MCPcopy Create free account
hub / github.com/apache/datafusion / test_sql

Function test_sql

datafusion/core/tests/optimizer/mod.rs:139–165  ·  view source on GitHub ↗
(sql: &str)

Source from the content-addressed store, hash-verified

137}
138
139fn 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)]
168struct MyContextProvider {

Callers 5

select_arrow_castFunction · 0.70
concat_literalsFunction · 0.70
concat_ws_literalsFunction · 0.70

Calls 11

newFunction · 0.85
with_udfMethod · 0.80
sql_statement_to_planMethod · 0.80
execute_and_checkMethod · 0.80
concatFunction · 0.50
concat_wsFunction · 0.50
cloneMethod · 0.45
optionsMethod · 0.45
optimizeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…