Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename ParamValues::{LIST -> List,MAP -> Map} #8611

Merged
merged 2 commits into from
Dec 22, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions datafusion/common/src/param_value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,17 @@ use std::collections::HashMap;
/// The parameter value corresponding to the placeholder
#[derive(Debug, Clone)]
pub enum ParamValues {
/// for positional query parameters, like select * from test where a > $1 and b = $2
LIST(Vec<ScalarValue>),
/// for named query parameters, like select * from test where a > $foo and b = $goo
MAP(HashMap<String, ScalarValue>),
/// For positional query parameters, like `SELECT * FROM test WHERE a > $1 AND b = $2`
List(Vec<ScalarValue>),
/// For named query parameters, like `SELECT * FROM test WHERE a > $foo AND b = $goo`
Map(HashMap<String, ScalarValue>),
}

impl ParamValues {
/// Verify parameter list length and type
pub fn verify(&self, expect: &Vec<DataType>) -> Result<()> {
match self {
ParamValues::LIST(list) => {
ParamValues::List(list) => {
// Verify if the number of params matches the number of values
if expect.len() != list.len() {
return _plan_err!(
Expand All @@ -57,7 +57,7 @@ impl ParamValues {
}
Ok(())
}
ParamValues::MAP(_) => {
ParamValues::Map(_) => {
// If it is a named query, variables can be reused,
// but the lengths are not necessarily equal
Ok(())
Expand All @@ -71,7 +71,7 @@ impl ParamValues {
data_type: &Option<DataType>,
) -> Result<ScalarValue> {
match self {
ParamValues::LIST(list) => {
ParamValues::List(list) => {
if id.is_empty() || id == "$0" {
return _plan_err!("Empty placeholder id");
}
Expand All @@ -97,7 +97,7 @@ impl ParamValues {
}
Ok(value.clone())
}
ParamValues::MAP(map) => {
ParamValues::Map(map) => {
// convert name (in format $a, $b, ..) to mapped values (a, b, ..)
let name = &id[1..];
// value at the name position in param_values should be the value for the placeholder
Expand All @@ -122,7 +122,7 @@ impl ParamValues {

impl From<Vec<ScalarValue>> for ParamValues {
fn from(value: Vec<ScalarValue>) -> Self {
Self::LIST(value)
Self::List(value)
}
}

Expand All @@ -133,7 +133,7 @@ where
fn from(value: Vec<(K, ScalarValue)>) -> Self {
let value: HashMap<String, ScalarValue> =
value.into_iter().map(|(k, v)| (k.into(), v)).collect();
Self::MAP(value)
Self::Map(value)
}
}

Expand All @@ -144,6 +144,6 @@ where
fn from(value: HashMap<K, ScalarValue>) -> Self {
let value: HashMap<String, ScalarValue> =
value.into_iter().map(|(k, v)| (k.into(), v)).collect();
Self::MAP(value)
Self::Map(value)
}
}