-
Notifications
You must be signed in to change notification settings - Fork 190
[Feature] Add table function relation syntax to SQL grammar #5318
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,19 +13,22 @@ | |
| import static org.opensearch.sql.sql.antlr.parser.OpenSearchSQLParser.SelectElementContext; | ||
| import static org.opensearch.sql.sql.antlr.parser.OpenSearchSQLParser.SubqueryAsRelationContext; | ||
| import static org.opensearch.sql.sql.antlr.parser.OpenSearchSQLParser.TableAsRelationContext; | ||
| import static org.opensearch.sql.sql.antlr.parser.OpenSearchSQLParser.TableFunctionRelationContext; | ||
| import static org.opensearch.sql.sql.antlr.parser.OpenSearchSQLParser.WhereClauseContext; | ||
| import static org.opensearch.sql.sql.parser.ParserUtils.getTextInQuery; | ||
| import static org.opensearch.sql.utils.SystemIndexUtils.TABLE_INFO; | ||
| import static org.opensearch.sql.utils.SystemIndexUtils.mappingTable; | ||
|
|
||
| import com.google.common.collect.ImmutableList; | ||
| import java.util.Collections; | ||
| import java.util.Locale; | ||
| import java.util.Optional; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.antlr.v4.runtime.tree.ParseTree; | ||
| import org.opensearch.sql.ast.expression.Alias; | ||
| import org.opensearch.sql.ast.expression.AllFields; | ||
| import org.opensearch.sql.ast.expression.Function; | ||
| import org.opensearch.sql.ast.expression.UnresolvedArgument; | ||
| import org.opensearch.sql.ast.expression.UnresolvedExpression; | ||
| import org.opensearch.sql.ast.tree.DescribeRelation; | ||
| import org.opensearch.sql.ast.tree.Filter; | ||
|
|
@@ -34,6 +37,7 @@ | |
| import org.opensearch.sql.ast.tree.Relation; | ||
| import org.opensearch.sql.ast.tree.RelationSubquery; | ||
| import org.opensearch.sql.ast.tree.SubqueryAlias; | ||
| import org.opensearch.sql.ast.tree.TableFunction; | ||
| import org.opensearch.sql.ast.tree.UnresolvedPlan; | ||
| import org.opensearch.sql.ast.tree.Values; | ||
| import org.opensearch.sql.common.antlr.SyntaxCheckException; | ||
|
|
@@ -189,6 +193,24 @@ public UnresolvedPlan visitSubqueryAsRelation(SubqueryAsRelationContext ctx) { | |
| return new RelationSubquery(visit(ctx.subquery), subqueryAlias); | ||
| } | ||
|
|
||
| @Override | ||
| public UnresolvedPlan visitTableFunctionRelation(TableFunctionRelationContext ctx) { | ||
| ImmutableList.Builder<UnresolvedExpression> args = ImmutableList.builder(); | ||
| ctx.tableFunctionArgs() | ||
| .tableFunctionArg() | ||
| .forEach( | ||
| arg -> { | ||
| String argName = | ||
| StringUtils.unquoteIdentifier(arg.ident().getText()).toLowerCase(Locale.ROOT); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No. visitIdent() only unquotes identifiers; it does not lowercase them. In this path, the arg name is stored in UnresolvedArgument, and ExpressionAnalyzer.visitUnresolvedArgument() preserves that name when creating NamedArgumentExpression. The explicit toLowerCase(Locale.ROOT) in visitTableFunctionRelation() is therefore what canonicalizes named arg keys for table-function relations.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks @mengweieric — that confirms the lowercase is the only thing canonicalizing arg keys on this path. My concern isn't whether it's needed, but where it lives. Since Two ways to keep them in sync — what's your preference?
Not a blocker tbh — I was trying to avoid the "works in PPL, fails in SQL" footgun before vectorSearch lands on top of this.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My preference would be to centralize table-function arg canonicalization in Analyzer.visitTableFunction rather than ExpressionAnalyzer, so both front-ends share one table-function-specific policy without changing all named-arg handling globally. For this PR I kept the fix local to the SQL parser to minimize scope. |
||
| UnresolvedExpression argValue = visitAstExpression(arg.functionArg()); | ||
| args.add(new UnresolvedArgument(argName, argValue)); | ||
| }); | ||
| TableFunction tableFunction = | ||
| new TableFunction(visitAstExpression(ctx.qualifiedName()), args.build()); | ||
| String alias = StringUtils.unquoteIdentifier(ctx.alias().getText()); | ||
| return new SubqueryAlias(alias, tableFunction); | ||
| } | ||
|
|
||
| @Override | ||
| public UnresolvedPlan visitWhereClause(WhereClauseContext ctx) { | ||
| return new Filter(visitAstExpression(ctx.expression())); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.