kosiew commented on code in PR #26969:
URL: https://github.com/apache/datafusion/pull/26969#discussion_r4781020342
##########
datafusion/optimizer/src/extract_leaf_expressions.rs:
##########
@@ -71,12 +72,45 @@ use crate::{OptimizerConfig, OptimizerRule};
/// Prefix for aliases generated by the extraction optimizer passes.
///
-/// This prefix is **reserved for internal optimizer use**. User-defined
aliases
-/// starting with this prefix may be misidentified as optimizer-generated
-/// extraction aliases, leading to unexpected behavior. Do not use this prefix
-/// in user queries.
+/// Aliases starting with this prefix are classified as extraction aliases when
+/// their inner expression is eligible for leaf pushdown
+/// ([`ExpressionPlacement::should_push_to_leaves`]). Canonical positive
decimal
+/// suffixes (`1..usize::MAX`, without leading zeros) are parsed solely to seed
+/// [`AliasGenerator`]; user aliases with this prefix that wrap pushable
+/// expressions may still be treated as extraction aliases.
const EXTRACTED_EXPR_PREFIX: &str = "__datafusion_extracted";
+/// Recognizes canonical positive decimal IDs (`1..usize::MAX` without leading
+/// zeros) for seeding [`AliasGenerator`] in
[`advance_generator_past_existing`].
+///
+/// Extraction alias classification uses [`is_extracted_alias`] instead so
+/// generated `usize::MAX` (and wrapped `0`) aliases are accepted while
+/// non-pushable user aliases with canonical names are rejected.
+fn extracted_expr_id(name: &str) -> Option<usize> {
+ let suffix = name
+ .strip_prefix(EXTRACTED_EXPR_PREFIX)?
+ .strip_prefix('_')?;
+ // Integer parsing alone also accepts leading zeros and a leading '+'.
+ if suffix.starts_with('0') || !suffix.bytes().all(|b| b.is_ascii_digit()) {
Review Comment:
eg this passes on main but fails in this PR
```
SET datafusion.optimizer.enable_leaf_expression_pushdown = true;
CREATE TABLE seed AS
SELECT column1 AS __datafusion_extracted_1, column2 AS s
FROM VALUES (0, {a: 10}), (1, {a: 20});
SELECT 99 AS __datafusion_extracted_01
FROM seed WHERE __datafusion_extracted_1 > 0 AND s['a'] = 20;
```
--
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]