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

Function test_prepare_statement

datafusion/core/tests/sql/select.rs:103–146  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

101// This test is equivalent with the test parallel_query_with_filter below but using prepare statement
102#[tokio::test]
103async fn test_prepare_statement() -> Result<()> {
104 let tmp_dir = TempDir::new()?;
105 let partition_count = 4;
106 let ctx = create_ctx_with_partition(&tmp_dir, partition_count).await?;
107
108 // sql to statement then to prepare logical plan with parameters
109 let dataframe = ctx
110 .sql("SELECT c1, c2 FROM test WHERE c1 > $2 AND c1 < $1")
111 .await?;
112
113 // prepare logical plan to logical plan without parameters
114 let param_values = vec![ScalarValue::Int32(Some(3)), ScalarValue::Float64(Some(0.0))];
115 let dataframe = dataframe.with_param_values(param_values)?;
116 let results = dataframe.collect().await?;
117
118 assert_snapshot!(batches_to_sort_string(&results), @r"
119 +----+----+
120 | c1 | c2 |
121 +----+----+
122 | 1 | 1 |
123 | 1 | 10 |
124 | 1 | 2 |
125 | 1 | 3 |
126 | 1 | 4 |
127 | 1 | 5 |
128 | 1 | 6 |
129 | 1 | 7 |
130 | 1 | 8 |
131 | 1 | 9 |
132 | 2 | 1 |
133 | 2 | 10 |
134 | 2 | 2 |
135 | 2 | 3 |
136 | 2 | 4 |
137 | 2 | 5 |
138 | 2 | 6 |
139 | 2 | 7 |
140 | 2 | 8 |
141 | 2 | 9 |
142 +----+----+
143 ");
144
145 Ok(())
146}
147
148#[tokio::test]
149async fn prepared_statement_type_coercion() -> Result<()> {

Callers

nothing calls this directly

Calls 5

newFunction · 0.85
sqlMethod · 0.80
collectMethod · 0.80
with_param_valuesMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…