(sql: &str)
| 137 | } |
| 138 | |
| 139 | fn test_sql(sql: &str) -> Result<LogicalPlan> { |
| 140 | // parse the SQL |
| 141 | let dialect = GenericDialect {}; // or AnsiDialect, or your own dialect ... |
| 142 | let ast: Vec<Statement> = Parser::parse_sql(&dialect, sql).unwrap(); |
| 143 | let statement = &ast[0]; |
| 144 | |
| 145 | // create a logical query plan |
| 146 | let config = ConfigOptions::default(); |
| 147 | let context_provider = MyContextProvider::default() |
| 148 | .with_udf(datetime::now(&config)) |
| 149 | .with_udf(datafusion_functions::core::arrow_cast()) |
| 150 | .with_udf(datafusion_functions::string::concat()) |
| 151 | .with_udf(datafusion_functions::string::concat_ws()); |
| 152 | let sql_to_rel = SqlToRel::new(&context_provider); |
| 153 | let plan = sql_to_rel.sql_statement_to_plan(statement.clone()).unwrap(); |
| 154 | |
| 155 | // hard code the return value of now() |
| 156 | let now_time = DateTime::from_timestamp(1666615693, 0).unwrap(); |
| 157 | let config = OptimizerContext::new() |
| 158 | .with_skip_failing_rules(false) |
| 159 | .with_query_execution_start_time(now_time); |
| 160 | let analyzer = Analyzer::new(); |
| 161 | let optimizer = Optimizer::new(); |
| 162 | // analyze and optimize the logical plan |
| 163 | let plan = analyzer.execute_and_check(plan, &config.options(), |_, _| {})?; |
| 164 | optimizer.optimize(plan, &config, |_, _| {}) |
| 165 | } |
| 166 | |
| 167 | #[derive(Default)] |
| 168 | struct MyContextProvider { |
no test coverage detected
searching dependent graphs…