-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Allow logical expressions to express a cast to an extension type #18136
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
base: main
Are you sure you want to change the base?
Changes from all 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 |
|---|---|---|
|
|
@@ -127,7 +127,9 @@ impl ExprSchemable for Expr { | |
| .map_or(Ok(DataType::Null), |e| e.get_type(schema)) | ||
| } | ||
| Expr::Cast(Cast { data_type, .. }) | ||
| | Expr::TryCast(TryCast { data_type, .. }) => Ok(data_type.clone()), | ||
| | Expr::TryCast(TryCast { data_type, .. }) => { | ||
| Ok(data_type.data_type().clone()) | ||
| } | ||
| Expr::Unnest(Unnest { expr }) => { | ||
| let arg_data_type = expr.get_type(schema)?; | ||
| // Unnest's output type is the inner type of the list | ||
|
|
@@ -592,7 +594,14 @@ impl ExprSchemable for Expr { | |
| // _ => Ok((self.get_type(schema)?, self.nullable(schema)?)), | ||
| Expr::Cast(Cast { expr, data_type }) => expr | ||
| .to_field(schema) | ||
| .map(|(_, f)| f.as_ref().clone().with_data_type(data_type.clone())) | ||
| .map(|(_, f)| { | ||
| f.as_ref() | ||
| .clone() | ||
| .with_data_type(data_type.data_type().clone()) | ||
| .with_metadata(f.metadata().clone()) | ||
| // TODO: should nullability be overridden here or derived from the | ||
| // input expression? | ||
|
Comment on lines
+598
to
+603
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 am not sure if this type of cast should be able to express nullability or not. |
||
| }) | ||
| .map(Arc::new), | ||
| Expr::Like(_) | ||
| | Expr::SimilarTo(_) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -291,12 +291,14 @@ pub fn create_physical_expr( | |
| Expr::Cast(Cast { expr, data_type }) => expressions::cast( | ||
| create_physical_expr(expr, input_dfschema, execution_props)?, | ||
| input_schema, | ||
| data_type.clone(), | ||
| // TODO: this drops extension metadata associated with the cast | ||
| data_type.data_type().clone(), | ||
|
Comment on lines
-294
to
+295
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 don't actually need physical expressions to be able to cast things...my vauge plan is to use a logical plan transformation or perhaps optimizer rule to replace casts to extension types with a ScalarUDF call. This should possibly error if there is mismatched metadata between the input and destination (i.e., a physical cast would only ever represent a storage cast, which is usually OK). |
||
| ), | ||
| Expr::TryCast(TryCast { expr, data_type }) => expressions::try_cast( | ||
| create_physical_expr(expr, input_dfschema, execution_props)?, | ||
| input_schema, | ||
| data_type.clone(), | ||
| // TODO: this drops extension metadata associated with the cast | ||
| data_type.data_type().clone(), | ||
| ), | ||
| Expr::Not(expr) => { | ||
| expressions::not(create_physical_expr(expr, input_dfschema, execution_props)?) | ||
|
|
||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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.
I added a utility function for this in #17986 (how to print a type represented by a DataType and possibly metadata in a user-facing error or explain plan). The idea is to keep existing plan explain strings the same unless somebody actually puts metadata here.