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

Function main

datafusion/sql/examples/sql.rs:37–66  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

35};
36
37fn main() {
38 let sql = "SELECT \
39 c.id, c.first_name, c.last_name, \
40 COUNT(*) as num_orders, \
41 sum(o.price) AS total_price, \
42 sum(o.price * s.sales_tax) AS state_tax \
43 FROM customer c \
44 JOIN state s ON c.state = s.id \
45 JOIN orders o ON c.id = o.customer_id \
46 WHERE o.price > 0 \
47 AND c.last_name LIKE 'G%' \
48 GROUP BY 1, 2, 3 \
49 ORDER BY state_tax DESC";
50
51 // parse the SQL
52 let dialect = GenericDialect {}; // or AnsiDialect, or your own dialect ...
53 let ast = Parser::parse_sql(&dialect, sql).unwrap();
54 let statement = &ast[0];
55
56 // create a logical query plan
57 let context_provider = MyContextProvider::new()
58 .with_udaf(sum_udaf())
59 .with_udaf(count_udaf())
60 .with_expr_planner(Arc::new(CoreFunctionPlanner::default()));
61 let sql_to_rel = SqlToRel::new(&context_provider);
62 let plan = sql_to_rel.sql_statement_to_plan(statement.clone()).unwrap();
63
64 // show the plan
65 println!("{plan}");
66}
67
68struct MyContextProvider {
69 options: ConfigOptions,

Callers

nothing calls this directly

Calls 5

newFunction · 0.85
sql_statement_to_planMethod · 0.80
with_expr_plannerMethod · 0.45
with_udafMethod · 0.45
cloneMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…