-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Encapsulate metadata for literals on to a FieldMetadata
structure
#16317
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
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -390,11 +390,7 @@ mod test { | |
} else { | ||
utf8_val | ||
}; | ||
Ok(Transformed::yes(lit_with_metadata( | ||
utf8_val, | ||
metadata | ||
.map(|m| m.into_iter().collect::<HashMap<String, String>>()), | ||
))) | ||
Ok(Transformed::yes(lit_with_metadata(utf8_val, metadata))) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is a pretty good example of the kind of simplification this PR allows (don't have to translate back/forth between HashMap / BTreeMap in various places) |
||
} | ||
// otherwise, return None | ||
_ => Ok(Transformed::no(expr)), | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,7 +15,6 @@ | |
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
use std::collections::HashMap; | ||
use std::sync::Arc; | ||
|
||
use crate::ScalarFunctionExpr; | ||
|
@@ -29,7 +28,9 @@ use datafusion_common::{ | |
exec_err, not_impl_err, plan_err, DFSchema, Result, ScalarValue, ToDFSchema, | ||
}; | ||
use datafusion_expr::execution_props::ExecutionProps; | ||
use datafusion_expr::expr::{Alias, Cast, InList, Placeholder, ScalarFunction}; | ||
use datafusion_expr::expr::{ | ||
Alias, Cast, FieldMetadata, InList, Placeholder, ScalarFunction, | ||
}; | ||
use datafusion_expr::var_provider::is_system_variables; | ||
use datafusion_expr::var_provider::VarType; | ||
use datafusion_expr::{ | ||
|
@@ -114,22 +115,11 @@ pub fn create_physical_expr( | |
match e { | ||
Expr::Alias(Alias { expr, metadata, .. }) => { | ||
if let Expr::Literal(v, prior_metadata) = expr.as_ref() { | ||
let mut new_metadata = prior_metadata | ||
.as_ref() | ||
.map(|m| { | ||
m.iter() | ||
.map(|(k, v)| (k.clone(), v.clone())) | ||
.collect::<HashMap<String, String>>() | ||
}) | ||
.unwrap_or_default(); | ||
if let Some(metadata) = metadata { | ||
new_metadata.extend(metadata.clone()); | ||
} | ||
let new_metadata = match new_metadata.is_empty() { | ||
true => None, | ||
false => Some(new_metadata), | ||
}; | ||
|
||
let metadata = metadata.as_ref().map(|m| FieldMetadata::from(m.clone())); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I remove this clone in a follow on PR: |
||
let new_metadata = FieldMetadata::merge_options( | ||
prior_metadata.as_ref(), | ||
metadata.as_ref(), | ||
); | ||
Ok(Arc::new(Literal::new_with_metadata( | ||
v.clone(), | ||
new_metadata, | ||
|
@@ -144,9 +134,7 @@ pub fn create_physical_expr( | |
} | ||
Expr::Literal(value, metadata) => Ok(Arc::new(Literal::new_with_metadata( | ||
value.clone(), | ||
metadata | ||
.as_ref() | ||
.map(|m| m.iter().map(|(k, v)| (k.clone(), v.clone())).collect()), | ||
metadata.clone(), | ||
))), | ||
Expr::ScalarVariable(_, variable_names) => { | ||
if is_system_variables(variable_names) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The point of this PR is to put all metadata handling in a Struct to make it easier to work with (and more efficient)