|
15 | 15 | // specific language governing permissions and limitations |
16 | 16 | // under the License. |
17 | 17 |
|
| 18 | +use std::collections::HashMap; |
| 19 | + |
18 | 20 | use super::*; |
19 | | -use datafusion_common::ScalarValue; |
| 21 | +use datafusion_common::{metadata::Literal, ParamValues, ScalarValue}; |
20 | 22 | use insta::assert_snapshot; |
21 | 23 |
|
22 | 24 | #[tokio::test] |
@@ -317,6 +319,41 @@ async fn test_named_parameter_not_bound() -> Result<()> { |
317 | 319 | Ok(()) |
318 | 320 | } |
319 | 321 |
|
| 322 | +#[tokio::test] |
| 323 | +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?; |
| 327 | + |
| 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 | + )]); |
| 336 | + |
| 337 | + // sql to statement then to logical plan with parameters |
| 338 | + let df = ctx.sql("SELECT $1, $2").await?; |
| 339 | + |
| 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 | + ]))?; |
| 347 | + |
| 348 | + let schema = df_with_params_replaced.schema(); |
| 349 | + assert_eq!(schema.field(0).data_type(), &DataType::UInt32); |
| 350 | + assert_eq!(schema.field(0).metadata(), &metadata0); |
| 351 | + assert_eq!(schema.field(1).data_type(), &DataType::Utf8); |
| 352 | + assert_eq!(schema.field(1).metadata(), &metadata1); |
| 353 | + |
| 354 | + Ok(()) |
| 355 | +} |
| 356 | + |
320 | 357 | #[tokio::test] |
321 | 358 | async fn test_version_function() { |
322 | 359 | let expected_version = format!( |
|
0 commit comments