-
Notifications
You must be signed in to change notification settings - Fork 181
Add Settings to UnifiedQueryPlanner #4911
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 |
|---|---|---|
|
|
@@ -32,6 +32,7 @@ | |
| import org.opensearch.sql.calcite.SysLimit; | ||
| import org.opensearch.sql.common.antlr.Parser; | ||
| import org.opensearch.sql.common.antlr.SyntaxCheckException; | ||
| import org.opensearch.sql.common.setting.Settings; | ||
| import org.opensearch.sql.executor.QueryType; | ||
| import org.opensearch.sql.ppl.antlr.PPLSyntaxParser; | ||
| import org.opensearch.sql.ppl.parser.AstBuilder; | ||
|
|
@@ -52,21 +53,26 @@ public class UnifiedQueryPlanner { | |
| /** Calcite framework configuration used during logical plan construction. */ | ||
| private final FrameworkConfig config; | ||
|
|
||
| private final Settings settings; | ||
|
|
||
| /** AST-to-RelNode visitor that builds logical plans from the parsed AST. */ | ||
| private final CalciteRelNodeVisitor relNodeVisitor = | ||
| new CalciteRelNodeVisitor(new EmptyDataSourceService()); | ||
|
|
||
| /** | ||
| * Constructs a UnifiedQueryPlanner for a given query type and schema root. | ||
| * Constructs a UnifiedQueryPlanner for a given query type, schema root, and settings. | ||
| * | ||
| * @param queryType the query language type (e.g., PPL) | ||
| * @param rootSchema the root Calcite schema containing all catalogs and tables | ||
| * @param defaultPath dot-separated path of schema to set as default schema | ||
| * @param settings configuration settings for query processing | ||
| */ | ||
| public UnifiedQueryPlanner(QueryType queryType, SchemaPlus rootSchema, String defaultPath) { | ||
| public UnifiedQueryPlanner( | ||
| QueryType queryType, SchemaPlus rootSchema, String defaultPath, Settings settings) { | ||
| this.queryType = queryType; | ||
| this.parser = buildQueryParser(queryType); | ||
| this.config = buildCalciteConfig(rootSchema, defaultPath); | ||
| this.settings = settings; | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -124,7 +130,8 @@ private UnresolvedPlan parse(String query) { | |
| ParseTree cst = parser.parse(query); | ||
| AstStatementBuilder astStmtBuilder = | ||
| new AstStatementBuilder( | ||
| new AstBuilder(query), AstStatementBuilder.StatementBuilderContext.builder().build()); | ||
| new AstBuilder(query, settings), | ||
|
Member
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. This is the key part to resolve the issue. Can you remove the single parameter construction? It's nothing but a hassle.
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. I tried, but realized some Calcite tests rely on this:
Maybe this can be done as a follow-up together with changes to the tests? |
||
| AstStatementBuilder.StatementBuilderContext.builder().build()); | ||
| Statement statement = cst.accept(astStmtBuilder); | ||
|
|
||
| if (statement instanceof Query) { | ||
|
|
@@ -164,6 +171,7 @@ public static class Builder { | |
| private String defaultNamespace; | ||
| private QueryType queryType; | ||
| private boolean cacheMetadata; | ||
| private Settings settings; | ||
|
|
||
| /** | ||
| * Sets the query language frontend to be used by the planner. | ||
|
|
@@ -176,6 +184,17 @@ public Builder language(QueryType queryType) { | |
| return this; | ||
| } | ||
|
|
||
| /** | ||
| * Sets the settings for query processing configuration. | ||
| * | ||
| * @param settings the Settings instance for configuration | ||
| * @return this builder instance | ||
| */ | ||
| public Builder settings(Settings settings) { | ||
| this.settings = settings; | ||
| return this; | ||
| } | ||
|
|
||
| /** | ||
| * Registers a catalog with the specified name and its associated schema. The schema can be a | ||
| * flat or nested structure (e.g., catalog → schema → table), depending on how data is | ||
|
|
@@ -221,7 +240,7 @@ public UnifiedQueryPlanner build() { | |
| Objects.requireNonNull(queryType, "Must specify language before build"); | ||
| SchemaPlus rootSchema = CalciteSchema.createRootSchema(true, cacheMetadata).plus(); | ||
| catalogs.forEach(rootSchema::add); | ||
| return new UnifiedQueryPlanner(queryType, rootSchema, defaultNamespace); | ||
| return new UnifiedQueryPlanner(queryType, rootSchema, defaultNamespace, settings); | ||
| } | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Validate Settings parameter or document null handling.
The constructor accepts
Settingsbut does not validate whether it's null. According to issue #4910, the NPE occurs whenvalidateJoinTypecallssettings.getSettingValue(...)on a null settings object. While this PR threads Settings through the planner, it does not prevent null from being passed, which would cause the same NPE for join queries.Consider one of the following approaches:
public UnifiedQueryPlanner( QueryType queryType, SchemaPlus rootSchema, String defaultPath, Settings settings) { + this.settings = Objects.requireNonNull(settings, "Settings cannot be null"); this.queryType = queryType; this.parser = buildQueryParser(queryType); this.config = buildCalciteConfig(rootSchema, defaultPath); - this.settings = settings; }parse()methodBased on coding guidelines: validate inputs and use proper error handling.
🤖 Prompt for AI Agents