Skip to content

Commit 27e8e42

Browse files
committed
fix test
1 parent a36e720 commit 27e8e42

File tree

1 file changed

+33
-23
lines changed

1 file changed

+33
-23
lines changed

datafusion/core/tests/sql/select.rs

Lines changed: 33 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use std::collections::HashMap;
1919

2020
use super::*;
21+
use datafusion::assert_batches_eq;
2122
use datafusion_common::{metadata::Literal, ParamValues, ScalarValue};
2223
use insta::assert_snapshot;
2324

@@ -321,35 +322,44 @@ async fn test_named_parameter_not_bound() -> Result<()> {
321322

322323
#[tokio::test]
323324
async fn test_query_parameters_with_metadata() -> Result<()> {
324-
let tmp_dir = TempDir::new()?;
325-
let partition_count = 4;
326-
let ctx = create_ctx_with_partition(&tmp_dir, partition_count).await?;
325+
let ctx = SessionContext::new();
327326

328-
let metadata0 = HashMap::from([(
329-
"some_key".to_string(),
330-
"some_value".to_string(),
331-
)]);
332-
let metadata1 = HashMap::from([(
333-
"some_other_key".to_string(),
334-
"some_other_value".to_string(),
335-
)]);
327+
let df = ctx.sql("SELECT $1, $2").await.unwrap();
336328

337-
// sql to statement then to logical plan with parameters
338-
let df = ctx.sql("SELECT $1, $2").await?;
329+
let metadata1 = HashMap::from([("some_key".to_string(), "some_value".to_string())]);
330+
let metadata2 =
331+
HashMap::from([("some_other_key".to_string(), "some_other_value".to_string())]);
332+
333+
let df_with_params_replaced = df
334+
.with_param_values(ParamValues::List(vec![
335+
Literal::new(ScalarValue::UInt32(Some(1)), Some(metadata1.clone().into())),
336+
Literal::new(
337+
ScalarValue::Utf8(Some("two".to_string())),
338+
Some(metadata2.clone().into()),
339+
),
340+
]))
341+
.unwrap();
339342

340-
let df_with_params_replaced = df.with_param_values(ParamValues::List(vec![
341-
Literal::new(ScalarValue::UInt32(Some(3)), Some(metadata0.clone().into())),
342-
Literal::new(
343-
ScalarValue::Utf8(Some("bar_value".to_string())),
344-
Some(metadata1.clone().into()),
345-
),
346-
]))?;
343+
// df_with_params_replaced.schema() is not correct here
344+
// https://github.com/apache/datafusion/issues/18102
345+
let batches = df_with_params_replaced.clone().collect().await.unwrap();
346+
let schema = batches[0].schema();
347347

348-
let schema = df_with_params_replaced.schema();
349348
assert_eq!(schema.field(0).data_type(), &DataType::UInt32);
350-
assert_eq!(schema.field(0).metadata(), &metadata0);
349+
assert_eq!(schema.field(0).metadata(), &metadata1);
351350
assert_eq!(schema.field(1).data_type(), &DataType::Utf8);
352-
assert_eq!(schema.field(1).metadata(), &metadata1);
351+
assert_eq!(schema.field(1).metadata(), &metadata2);
352+
353+
assert_batches_eq!(
354+
vec![
355+
"+----+-----+",
356+
"| $1 | $2 |",
357+
"+----+-----+",
358+
"| 1 | two |",
359+
"+----+-----+",
360+
],
361+
&batches
362+
);
353363

354364
Ok(())
355365
}

0 commit comments

Comments
 (0)