alamb commented on code in PR #19128:
URL: https://github.com/apache/datafusion/pull/19128#discussion_r2603423250
##########
datafusion-examples/examples/custom_data_source/default_column_values.rs:
##########
@@ -304,74 +303,32 @@ struct DefaultValuePhysicalExprAdapter {
impl PhysicalExprAdapter for DefaultValuePhysicalExprAdapter {
fn rewrite(&self, expr: Arc<dyn PhysicalExpr>) -> Result<Arc<dyn
PhysicalExpr>> {
- // First try our custom default value injection for missing columns
- let rewritten = expr
- .transform(|expr| {
- self.inject_default_values(
- expr,
- &self.logical_file_schema,
- &self.physical_file_schema,
- )
- })
- .data()?;
-
- // Then apply the default adapter as a fallback to handle standard
schema differences
- // like type casting, etc.
- self.default_adapter.rewrite(rewritten)
- }
-}
-
-impl DefaultValuePhysicalExprAdapter {
- fn inject_default_values(
- &self,
- expr: Arc<dyn PhysicalExpr>,
- logical_file_schema: &Schema,
- physical_file_schema: &Schema,
- ) -> Result<Transformed<Arc<dyn PhysicalExpr>>> {
- if let Some(column) = expr.as_any().downcast_ref::<Column>() {
- let column_name = column.name();
-
- // Check if this column exists in the physical schema
- if physical_file_schema.index_of(column_name).is_err() {
- // Column is missing from physical schema, check if logical
schema has a default
- if let Ok(logical_field) =
- logical_file_schema.field_with_name(column_name)
- {
- if let Some(default_value_str) =
-
logical_field.metadata().get(DEFAULT_VALUE_METADATA_KEY)
- {
- // Create a string literal and wrap it in a cast
expression
- let default_literal = self.create_default_value_expr(
- default_value_str,
- logical_field.data_type(),
- )?;
- return Ok(Transformed::yes(default_literal));
- }
- }
+ // Pre-compute replacements for missing columns with default values
Review Comment:
this is great
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]