Skip to content

Commit 03c2ef4

Browse files
kawadakkalamb
andauthored
Don't panic on zero placeholder in ParamValues::get_placeholders_with_values (#8615)
It correctly rejected `$0` but not the other ones that are parsed equally (e.g., `$000`). Co-authored-by: Andrew Lamb <[email protected]>
1 parent e467492 commit 03c2ef4

File tree

2 files changed

+23
-7
lines changed

2 files changed

+23
-7
lines changed

datafusion/common/src/param_value.rs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -72,17 +72,20 @@ impl ParamValues {
7272
) -> Result<ScalarValue> {
7373
match self {
7474
ParamValues::List(list) => {
75-
if id.is_empty() || id == "$0" {
75+
if id.is_empty() {
7676
return _plan_err!("Empty placeholder id");
7777
}
7878
// convert id (in format $1, $2, ..) to idx (0, 1, ..)
79-
let idx = id[1..].parse::<usize>().map_err(|e| {
80-
DataFusionError::Internal(format!(
81-
"Failed to parse placeholder id: {e}"
82-
))
83-
})? - 1;
79+
let idx = id[1..]
80+
.parse::<usize>()
81+
.map_err(|e| {
82+
DataFusionError::Internal(format!(
83+
"Failed to parse placeholder id: {e}"
84+
))
85+
})?
86+
.checked_sub(1);
8487
// value at the idx-th position in param_values should be the value for the placeholder
85-
let value = list.get(idx).ok_or_else(|| {
88+
let value = idx.and_then(|idx| list.get(idx)).ok_or_else(|| {
8689
DataFusionError::Internal(format!(
8790
"No value found for placeholder with id {id}"
8891
))

datafusion/expr/src/logical_plan/plan.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3099,6 +3099,19 @@ digraph {
30993099
.build()
31003100
.unwrap();
31013101

3102+
plan.replace_params_with_values(&param_values.clone().into())
3103+
.expect_err("unexpectedly succeeded to replace an invalid placeholder");
3104+
3105+
// test $00 placeholder
3106+
let schema = Schema::new(vec![Field::new("id", DataType::Int32, false)]);
3107+
3108+
let plan = table_scan(TableReference::none(), &schema, None)
3109+
.unwrap()
3110+
.filter(col("id").eq(placeholder("$00")))
3111+
.unwrap()
3112+
.build()
3113+
.unwrap();
3114+
31023115
plan.replace_params_with_values(&param_values.into())
31033116
.expect_err("unexpectedly succeeded to replace an invalid placeholder");
31043117
}

0 commit comments

Comments
 (0)