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

Function analysis

datafusion-examples/examples/sql_ops/analysis.rs:39–182  ·  view source on GitHub ↗

Demonstrates how to analyze a SQL query by counting JOINs and identifying join-trees using DataFusion’s `LogicalPlan` and `TreeNode` API.

()

Source from the content-addressed store, hash-verified

37/// Demonstrates how to analyze a SQL query by counting JOINs and identifying
38/// join-trees using DataFusion’s `LogicalPlan` and `TreeNode` API.
39pub async fn analysis() -> Result<()> {
40 // To show how we can count the joins in a sql query we'll be using query 88
41 // from the TPC-DS benchmark.
42 //
43 // q8 has many joins, cross-joins and multiple join-trees, perfect for our
44 // example:
45
46 let tpcds_query_88 = "
47select *
48from
49 (select count(*) h8_30_to_9
50 from store_sales, household_demographics , time_dim, store
51 where ss_sold_time_sk = time_dim.t_time_sk
52 and ss_hdemo_sk = household_demographics.hd_demo_sk
53 and ss_store_sk = s_store_sk
54 and time_dim.t_hour = 8
55 and time_dim.t_minute >= 30
56 and ((household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2) or
57 (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2) or
58 (household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2))
59 and store.s_store_name = 'ese') s1,
60 (select count(*) h9_to_9_30
61 from store_sales, household_demographics , time_dim, store
62 where ss_sold_time_sk = time_dim.t_time_sk
63 and ss_hdemo_sk = household_demographics.hd_demo_sk
64 and ss_store_sk = s_store_sk
65 and time_dim.t_hour = 9
66 and time_dim.t_minute < 30
67 and ((household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2) or
68 (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2) or
69 (household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2))
70 and store.s_store_name = 'ese') s2,
71 (select count(*) h9_30_to_10
72 from store_sales, household_demographics , time_dim, store
73 where ss_sold_time_sk = time_dim.t_time_sk
74 and ss_hdemo_sk = household_demographics.hd_demo_sk
75 and ss_store_sk = s_store_sk
76 and time_dim.t_hour = 9
77 and time_dim.t_minute >= 30
78 and ((household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2) or
79 (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2) or
80 (household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2))
81 and store.s_store_name = 'ese') s3,
82 (select count(*) h10_to_10_30
83 from store_sales, household_demographics , time_dim, store
84 where ss_sold_time_sk = time_dim.t_time_sk
85 and ss_hdemo_sk = household_demographics.hd_demo_sk
86 and ss_store_sk = s_store_sk
87 and time_dim.t_hour = 10
88 and time_dim.t_minute < 30
89 and ((household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2) or
90 (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2) or
91 (household_demographics.hd_dep_count = 1 and household_demographics.hd_vehicle_count<=1+2))
92 and store.s_store_name = 'ese') s4,
93 (select count(*) h10_30_to_11
94 from store_sales, household_demographics , time_dim, store
95 where ss_sold_time_sk = time_dim.t_time_sk
96 and ss_hdemo_sk = household_demographics.hd_demo_sk

Callers 1

runMethod · 0.85

Calls 8

tpcds_schemasFunction · 0.85
newFunction · 0.85
total_join_countFunction · 0.85
count_treesFunction · 0.85
into_optimized_planMethod · 0.80
sqlMethod · 0.80
register_tableMethod · 0.45
cloneMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…