kosiew commented on code in PR #26969:
URL: https://github.com/apache/datafusion/pull/26969#discussion_r4676742233
##########
datafusion/optimizer/src/extract_leaf_expressions.rs:
##########
@@ -1049,7 +1142,7 @@ fn split_and_push_projection(
recovery_exprs.push(expr.clone());
proj_exprs_captured += 1;
} else if let Expr::Alias(alias) = expr
- && alias.name.starts_with(EXTRACTED_EXPR_PREFIX)
+ && is_extracted_alias(alias)
Review Comment:
Reusing a user-selected alias that matches an input field causes
AmbiguousReference. Please route colliding aliases through routing_extract to
allocate a fresh name, preserve the original output alias, and add a regression
test for _manual.
##########
datafusion/optimizer/src/extract_leaf_expressions.rs:
##########
@@ -613,35 +663,70 @@ struct LeafExpressionExtractor<'a> {
input_schema: &'a DFSchema,
/// Alias generator
alias_generator: &'a Arc<AliasGenerator>,
+ /// Pre-existing `__datafusion_extracted` names in the plan to avoid
+ /// collisions when the generator wraps past `usize::MAX`.
+ existing_aliases: &'a std::collections::HashSet<String>,
}
impl<'a> LeafExpressionExtractor<'a> {
- fn new(input_schema: &'a DFSchema, alias_generator: &'a
Arc<AliasGenerator>) -> Self {
+ fn new(
+ input_schema: &'a DFSchema,
+ alias_generator: &'a Arc<AliasGenerator>,
+ existing_aliases: &'a std::collections::HashSet<String>,
+ ) -> Self {
Self {
extracted: IndexMap::new(),
columns_needed: IndexSet::new(),
input_schema,
alias_generator,
+ existing_aliases,
+ }
+ }
+
+ fn next_available_alias(&self) -> Option<String> {
+ let max_attempts =
+ self.existing_aliases.len() + self.input_schema.fields().len() + 1;
+ for _ in 0..max_attempts {
+ let alias = self.alias_generator.next(EXTRACTED_EXPR_PREFIX);
+ let in_plan = self.existing_aliases.contains(&alias);
+ let in_input = self
Review Comment:
Suggestion: include prefixed input fields in existing_aliases during
projection splitting. This removes the per-candidate schema scan and avoids O(E
* W) string comparisons for E extractions over W fields.
--
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]