jonahgao commented on code in PR #15153: URL: https://github.com/apache/datafusion/pull/15153#discussion_r1995837380
########## datafusion/sql/src/expr/mod.rs: ########## @@ -983,14 +983,102 @@ impl<S: ContextProvider> SqlToRel<'_, S> { Ok(Expr::Cast(Cast::new(Box::new(expr), dt))) } + /// Extracts the root expression and access chain from a compound expression. + /// + /// This function attempts to identify if a compound expression (like `a.b.c`) should be treated + /// as a column reference with a qualifier (like `table.column`) or as a field access expression. + /// + /// # Arguments + /// + /// * `root` - The root SQL expression (e.g., the first part of `a.b.c`) + /// * `access_chain` - Vector of access expressions (e.g., `.b` and `.c` parts) + /// * `schema` - The schema to resolve column references against + /// * `planner_context` - Context for planning expressions + /// + /// # Returns + /// + /// A tuple containing: + /// * The resolved root expression + /// * The remaining access chain that should be processed as field accesses + fn extract_root_and_access_chain( + &self, + root: SQLExpr, + access_chain: Vec<AccessExpr>, + schema: &DFSchema, + planner_context: &mut PlannerContext, + ) -> Result<(Expr, Vec<AccessExpr>)> { Review Comment: I think it would be simpler to reuse `sql_compound_identifier_to_expr()`, like [this](https://github.com/jonahgao/datafusion/commit/8f5129997c40f3054b66a1fd4e877ccdf84ec996). ########## datafusion/core/tests/sql/select.rs: ########## @@ -350,3 +350,45 @@ async fn test_version_function() { assert_eq!(version.value(0), expected_version); } + +#[tokio::test] +async fn test_subscript() -> Result<()> { Review Comment: This is more suitable as a sqllogictest test. Maybe we can move it to [struct.slt](https://github.com/apache/datafusion/blob/main/datafusion/sqllogictest/test_files/struct.slt) or [identifiers.slt](https://github.com/apache/datafusion/blob/main/datafusion/sqllogictest/test_files/identifiers.slt) -- 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: github-unsubscr...@datafusion.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: github-unsubscr...@datafusion.apache.org For additional commands, e-mail: github-h...@datafusion.apache.org