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

Function test_sql

datafusion/optimizer/tests/optimizer_integration.rs:647–695  ·  view source on GitHub ↗
(sql: &str)

Source from the content-addressed store, hash-verified

645}
646
647fn test_sql(sql: &str) -> Result<LogicalPlan> {
648 // parse the SQL
649 let dialect = GenericDialect {}; // or AnsiDialect, or your own dialect ...
650 let ast: Vec<Statement> = Parser::parse_sql(&dialect, sql).unwrap();
651 let statement = &ast[0];
652 let context_provider = MyContextProvider::default()
653 .with_udaf(sum_udaf())
654 .with_udaf(count_udaf())
655 .with_udaf(avg_udaf())
656 .with_expr_planners(vec![
657 Arc::new(AggregateFunctionPlanner),
658 Arc::new(WindowFunctionPlanner),
659 ])
660 .with_schema(
661 "test",
662 Schema::new_with_metadata(
663 vec![
664 Field::new("col_int32", DataType::Int32, true),
665 Field::new("col_uint32", DataType::UInt32, true),
666 Field::new("col_utf8", DataType::Utf8, true),
667 Field::new("col_date32", DataType::Date32, true),
668 Field::new("col_date64", DataType::Date64, true),
669 // timestamp with no timezone
670 Field::new(
671 "col_ts_nano_none",
672 DataType::Timestamp(TimeUnit::Nanosecond, None),
673 true,
674 ),
675 // timestamp with UTC timezone
676 Field::new(
677 "col_ts_nano_utc",
678 DataType::Timestamp(TimeUnit::Nanosecond, Some("+00:00".into())),
679 true,
680 ),
681 ],
682 HashMap::new(),
683 ),
684 );
685
686 let sql_to_rel = SqlToRel::new(&context_provider);
687 let plan = sql_to_rel.sql_statement_to_plan(statement.clone())?;
688
689 let config = OptimizerContext::new().with_skip_failing_rules(false);
690 let analyzer = Analyzer::new();
691 let optimizer = Optimizer::new();
692 // analyze and optimize the logical plan
693 let plan = analyzer.execute_and_check(plan, &config.options(), |_, _| {})?;
694 optimizer.optimize(plan, &config, observe)
695}
696
697fn observe(_plan: &LogicalPlan, _rule: &dyn OptimizerRule) {}
698

Callers 15

case_whenFunction · 0.70
case_when_aggregateFunction · 0.70
unsigned_target_typeFunction · 0.70
distribute_byFunction · 0.70
where_exists_distinctFunction · 0.70
intersectFunction · 0.70

Calls 10

newFunction · 0.85
sql_statement_to_planMethod · 0.80
execute_and_checkMethod · 0.80
with_schemaMethod · 0.45
with_expr_plannersMethod · 0.45
with_udafMethod · 0.45
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…