You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In certain situations, it might be clearer to use named parameters, e.g $foo.
Describe the solution you'd like
Would it be possible to support named query parameters?
On a cursory look, it seems like the underlying LogicalPlan already supports mapping parameter ids to values, so this might "just" be to change the with_param_values API to allow specifying the named parameter ids.
I looked at the relevant code, and the placeholders are used in the following three sections:
PREPARE Statement
Insert Statement
Select Statement (query)
I don't think 1 and 2 need to support named queries, just support 3
This is is preliminary thinking. If you have some idea please advice. @alamb@simonvandel
let results = ctx
.sql("SELECT a FROM example WHERE b = $foo")
.await?
// replace $foo with value 2
.with_param_values(vec![
"$foo", ScalarValue::from(2i64)
])?
.collect()
.await?;
let results = ctx
.sql("SELECT a FROM example WHERE b = $foo")
.await?
// replace $foo with value 2
.with_param_values(vec![
"$foo", ScalarValue::from(2i64)
])?
.collect()
.await?;
Maybe I can't describe it clearly, but my thoughts are the same as yours,thanks
Activity
alamb commentedon Nov 17, 2023
I agree @simonvandel this is both a good idea, and would be a straightforward change
Asura7969 commentedon Nov 30, 2023
I looked at the relevant code, and the placeholders are used in the following three sections:
I don't think 1 and 2 need to support named queries, just support 3
This is is preliminary thinking. If you have some idea please advice.
@alamb @simonvandel
alamb commentedon Nov 30, 2023
I don't fully understand what you are suggesting here.
I thought the proposal was to change https://docs.rs/datafusion/latest/datafusion/dataframe/struct.DataFrame.html#method.with_param_values to take a different API, perhaps like
So you could call it like
Asura7969 commentedon Dec 1, 2023
Maybe I can't describe it clearly, but my thoughts are the same as yours,thanks