mattsu2020 commented on code in PR #26969:
URL: https://github.com/apache/datafusion/pull/26969#discussion_r4650602929
##########
datafusion/optimizer/src/extract_leaf_expressions.rs:
##########
@@ -84,12 +84,28 @@ 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.
+/// Names of the form `__datafusion_extracted_N`, where `N` is in
`1..usize::MAX`
+/// with no leading zeros, are **reserved for internal optimizer use**.
+/// User-defined aliases matching that form may still be misidentified as
+/// optimizer-generated extraction aliases.
const EXTRACTED_EXPR_PREFIX: &str = "__datafusion_extracted";
+/// Recognize canonical positive decimal IDs that the counter can advance past.
+/// Use the same check when identifying extractions and when advancing the
+/// generator past them.
+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()) {
+ return None;
+ }
+ let id = suffix.parse::<usize>().ok()?;
+ // update_min_id adds one, so the maximum value has no usable successor.
+ (id < usize::MAX).then_some(id)
Review Comment:
I added regression tests.
--
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]