andygrove commented on code in PR #2258:
URL: https://github.com/apache/datafusion-comet/pull/2258#discussion_r2369624187
##########
native/core/src/execution/planner.rs:
##########
@@ -2344,16 +2351,60 @@ impl PhysicalPlanner {
))
}
PartitioningStruct::RangePartition(range_partition) => {
+ // Generate the lexical ordering for comparisons
let exprs: Result<Vec<PhysicalSortExpr>, ExecutionError> =
range_partition
.sort_orders
.iter()
.map(|expr| self.create_sort_expr(expr,
Arc::clone(&input_schema)))
.collect();
let lex_ordering = LexOrdering::new(exprs?).unwrap();
+
+ // Generate the row converter for comparing incoming batches
to boundary rows
+ let sort_fields: Vec<SortField> = lex_ordering
+ .iter()
+ .map(|sort_expr| {
+ let data_type =
sort_expr.expr.data_type(input_schema.as_ref()).unwrap();
+ SortField::new_with_options(data_type,
sort_expr.options)
+ })
+ .collect();
+
+ // Deserialize the literals to columnar collections of
ScalarValues
+ let mut scalar_values: Vec<Vec<ScalarValue>> = vec![vec![];
lex_ordering.len()];
+ range_partition
+ .boundary_rows
+ .iter()
+ .for_each(|boundary_row| {
+ // For each serialized expr in a boundary row, convert
to a Literal
+ // expression, then extract the ScalarValue from the
Literal and push it
+ // into the collection of ScalarValues
+ (0..lex_ordering.len()).for_each(|col_idx| {
+ let expr = self
+ .create_expr(
+ &boundary_row.partition_bounds[col_idx],
+ Arc::clone(&input_schema),
+ )
+ .unwrap();
+ let literal_expr =
expr.as_any().downcast_ref::<Literal>().unwrap();
+
scalar_values[col_idx].push(literal_expr.value().clone());
+ });
+ });
Review Comment:
`unwrap` can be avoided by using regular `for` loops instead of `for_each`
with closures:
```suggestion
for boundary_row in &range_partition.boundary_rows {
// For each serialized expr in a boundary row, convert
to a Literal
// expression, then extract the ScalarValue from the
Literal and push it
// into the collection of ScalarValues
for col_idx in 0..lex_ordering.len() {
let expr = self.create_expr(
&boundary_row.partition_bounds[col_idx],
Arc::clone(&input_schema),
)?;
let literal_expr =
expr.as_any().downcast_ref::<Literal>().expect("Literal");
scalar_values[col_idx].push(literal_expr.value().clone());
}
}
```
--
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]