Skip to content

Commit a36e720

Browse files
committed
add a test that fails
1 parent 05c91eb commit a36e720

File tree

1 file changed

+38
-1
lines changed

1 file changed

+38
-1
lines changed

datafusion/core/tests/sql/select.rs

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@
1515
// specific language governing permissions and limitations
1616
// under the License.
1717

18+
use std::collections::HashMap;
19+
1820
use super::*;
19-
use datafusion_common::ScalarValue;
21+
use datafusion_common::{metadata::Literal, ParamValues, ScalarValue};
2022
use insta::assert_snapshot;
2123

2224
#[tokio::test]
@@ -317,6 +319,41 @@ async fn test_named_parameter_not_bound() -> Result<()> {
317319
Ok(())
318320
}
319321

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+
320357
#[tokio::test]
321358
async fn test_version_function() {
322359
let expected_version = format!(

0 commit comments

Comments
 (0)