|
15 | 15 | // specific language governing permissions and limitations |
16 | 16 | // under the License. |
17 | 17 |
|
18 | | -// use crate::datafusion::functions::register_udfs; |
19 | | -// use datafusion::prelude::{SessionConfig, SessionContext}; |
| 18 | +use crate::datafusion::functions::register_udfs; |
| 19 | +use datafusion::prelude::{SessionConfig, SessionContext}; |
20 | 20 |
|
21 | | -// static TABLE_SETUP: &str = include_str!(r"./queries/table_setup.sql"); |
| 21 | +static TABLE_SETUP: &str = include_str!(r"./queries/table_setup.sql"); |
22 | 22 |
|
23 | | -// #[allow(clippy::unwrap_used)] |
24 | | -// pub async fn create_df_session() -> SessionContext { |
25 | | -// let mut config = SessionConfig::new(); |
26 | | -// config.options_mut().catalog.information_schema = true; |
27 | | -// let mut ctx = SessionContext::new_with_config(config); |
| 23 | +#[allow(clippy::unwrap_used)] |
| 24 | +pub async fn create_df_session() -> SessionContext { |
| 25 | + let mut config = SessionConfig::new(); |
| 26 | + config.options_mut().catalog.information_schema = true; |
| 27 | + let mut ctx = SessionContext::new_with_config(config); |
28 | 28 |
|
29 | | -// register_udfs(&mut ctx).unwrap(); |
| 29 | + register_udfs(&mut ctx).unwrap(); |
30 | 30 |
|
31 | | -// for query in TABLE_SETUP.split(';') { |
32 | | -// if !query.is_empty() { |
33 | | -// dbg!("Running query: ", query); |
34 | | -// ctx.sql(query).await.unwrap().collect().await.unwrap(); |
35 | | -// } |
36 | | -// } |
37 | | -// ctx |
38 | | -// } |
| 31 | + for query in TABLE_SETUP.split(';') { |
| 32 | + if !query.is_empty() { |
| 33 | + dbg!("Running query: ", query); |
| 34 | + ctx.sql(query).await.unwrap().collect().await.unwrap(); |
| 35 | + } |
| 36 | + } |
| 37 | + ctx |
| 38 | +} |
39 | 39 |
|
40 | | -// pub mod macros { |
41 | | -// macro_rules! test_query { |
42 | | -// ($test_fn_name:ident, $query:expr) => { |
43 | | -// paste::paste! { |
44 | | -// #[tokio::test] |
45 | | -// async fn [< query_ $test_fn_name >]() { |
46 | | -// let ctx = crate::tests::utils::create_df_session().await; |
47 | | -// let statement = ctx.state().sql_to_statement($query, "snowflake"); |
| 40 | +pub mod macros { |
| 41 | + macro_rules! test_query { |
| 42 | + ($test_fn_name:ident, $query:expr) => { |
| 43 | + paste::paste! { |
| 44 | + #[tokio::test] |
| 45 | + async fn [< query_ $test_fn_name >]() { |
| 46 | + let ctx = crate::tests::utils::create_df_session().await; |
| 47 | + let statement = ctx.state().sql_to_statement($query, "snowflake"); |
48 | 48 |
|
49 | | -// let plan = ctx.state().create_logical_plan($query) |
50 | | -// .await; |
| 49 | + let plan = ctx.state().create_logical_plan($query) |
| 50 | + .await; |
51 | 51 |
|
52 | | -// let df = match &plan { |
53 | | -// Ok(plan) => { |
54 | | -// match ctx.execute_logical_plan(plan.clone()).await { |
55 | | -// Ok(df) => { |
56 | | -// let record_batches = df.collect().await.unwrap(); |
57 | | -// Ok(datafusion::arrow::util::pretty::pretty_format_batches(&record_batches).unwrap().to_string()) |
58 | | -// }, |
59 | | -// Err(e) => Err(e) |
60 | | -// } |
61 | | -// }, |
62 | | -// _ => Err(datafusion::error::DataFusionError::Execution("Failed to create logical plan".to_string())) |
63 | | -// }; |
64 | | -// insta::with_settings!({ |
65 | | -// description => stringify!($query), |
66 | | -// omit_expression => true, |
67 | | -// prepend_module_to_snapshot => false |
68 | | -// }, { |
69 | | -// let plan = plan.map(|plan| plan.to_string().split("\n").map(|s| s.to_string()).collect::<Vec<String>>()); |
70 | | -// let df = df.map(|df| df.split("\n").map(|s| s.to_string()).collect::<Vec<String>>()); |
71 | | -// insta::assert_debug_snapshot!((statement, plan, df)); |
72 | | -// }) |
73 | | -// } |
74 | | -// } |
75 | | -// } |
76 | | -// } |
| 52 | + let df = match &plan { |
| 53 | + Ok(plan) => { |
| 54 | + match ctx.execute_logical_plan(plan.clone()).await { |
| 55 | + Ok(df) => { |
| 56 | + let record_batches = df.collect().await.unwrap(); |
| 57 | + Ok(datafusion::arrow::util::pretty::pretty_format_batches(&record_batches).unwrap().to_string()) |
| 58 | + }, |
| 59 | + Err(e) => Err(e) |
| 60 | + } |
| 61 | + }, |
| 62 | + _ => Err(datafusion::error::DataFusionError::Execution("Failed to create logical plan".to_string())) |
| 63 | + }; |
| 64 | + insta::with_settings!({ |
| 65 | + description => stringify!($query), |
| 66 | + omit_expression => true, |
| 67 | + prepend_module_to_snapshot => false |
| 68 | + }, { |
| 69 | + let plan = plan.map(|plan| plan.to_string().split("\n").map(|s| s.to_string()).collect::<Vec<String>>()); |
| 70 | + let df = df.map(|df| df.split("\n").map(|s| s.to_string()).collect::<Vec<String>>()); |
| 71 | + insta::assert_debug_snapshot!((statement, plan, df)); |
| 72 | + }) |
| 73 | + } |
| 74 | + } |
| 75 | + } |
| 76 | + } |
77 | 77 |
|
78 | | -// pub(crate) use test_query; |
79 | | -// } |
| 78 | + pub(crate) use test_query; |
| 79 | +} |
0 commit comments