-
Notifications
You must be signed in to change notification settings - Fork 214
[Feature] Add PPL outputlookup command (synchronous terminal write sink) #5621
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
Open
noCharger
wants to merge
15
commits into
opensearch-project:main
Choose a base branch
from
noCharger:feature/ppl-outputlookup-clean
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
9476e41
Add PPL outputlookup command (synchronous terminal write sink)
noCharger 92cfd5f
Harden outputlookup failure cases (key_field validation, dest guard, …
noCharger e1d19cd
Merge remote-tracking branch 'origin/main' into feature/ppl-outputloo…
noCharger 4c9fb21
Surface outputlookup write params in explain + add user doc
noCharger d39455c
Merge remote-tracking branch 'origin/main' into feature/ppl-outputloo…
noCharger b1c4ccb
outputlookup: migration-aware overwrite for data-importer (#11303) lo…
noCharger 7faebf1
outputlookup C2: plain-index substrate + lookup-marker guard + indice…
noCharger a986700
Apply spotless formatting
noCharger 7963644
Add PPL outputlookup command on the shared .lookups substrate
noCharger 5bf7c7c
Merge origin/main into feature/ppl-outputlookup-clean
noCharger 29b7e8b
Merge origin/main into feature/ppl-outputlookup-clean
noCharger e682917
Make outputlookup max_rows exceed error actionable
noCharger dade0d5
Add PPL outputlookup command
noCharger b84bad6
Optimize outputlookup slice write with build-time index settings
noCharger 5dc4c9a
Address review comments: close input enumerator, restore settings on …
noCharger File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
core/src/main/java/org/opensearch/sql/ast/tree/OutputLookup.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| /* | ||
| * Copyright OpenSearch Contributors | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| package org.opensearch.sql.ast.tree; | ||
|
|
||
| import com.google.common.collect.ImmutableList; | ||
| import java.util.List; | ||
| import lombok.AllArgsConstructor; | ||
| import lombok.EqualsAndHashCode; | ||
| import lombok.Getter; | ||
| import lombok.RequiredArgsConstructor; | ||
| import lombok.Setter; | ||
| import lombok.ToString; | ||
| import org.opensearch.sql.ast.AbstractNodeVisitor; | ||
|
|
||
| /** AST node for the {@code outputlookup} command: a terminal write sink, overwrite by default. */ | ||
| @Getter | ||
| @Setter | ||
| @ToString | ||
| @EqualsAndHashCode(callSuper = false) | ||
| @RequiredArgsConstructor | ||
| @AllArgsConstructor | ||
| public class OutputLookup extends UnresolvedPlan { | ||
|
|
||
| private UnresolvedPlan child; | ||
|
|
||
| /** The lookup name: the filtered alias published over the backing index. */ | ||
| private final String indexName; | ||
|
|
||
| /** false (default) overwrites the destination; true appends to it. */ | ||
| private boolean append = false; | ||
|
|
||
| /** true (default) clears the destination on empty results; false keeps it. */ | ||
| private boolean overrideIfEmpty = true; | ||
|
|
||
| /** | ||
| * Fields whose values form the document {@code _id} for upsert; empty means auto-generated id. | ||
| */ | ||
| private List<String> keyFields = List.of(); | ||
|
|
||
| /** Cap on the number of rows written; null means unbounded. */ | ||
| private Integer max; | ||
|
|
||
| @Override | ||
| public OutputLookup attach(UnresolvedPlan child) { | ||
| this.child = child; | ||
| return this; | ||
| } | ||
|
|
||
| @Override | ||
| public List<UnresolvedPlan> getChild() { | ||
| return this.child == null ? ImmutableList.of() : ImmutableList.of(this.child); | ||
| } | ||
|
|
||
| @Override | ||
| public <T, C> T accept(AbstractNodeVisitor<T, C> nodeVisitor, C context) { | ||
| return nodeVisitor.visitOutputLookup(this, context); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
115 changes: 115 additions & 0 deletions
115
core/src/main/java/org/opensearch/sql/calcite/OutputLookupTableModify.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,115 @@ | ||
| /* | ||
| * Copyright OpenSearch Contributors | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| package org.opensearch.sql.calcite; | ||
|
|
||
| import java.util.List; | ||
| import lombok.Getter; | ||
| import org.apache.calcite.plan.Convention; | ||
| import org.apache.calcite.plan.RelOptCluster; | ||
| import org.apache.calcite.plan.RelOptTable; | ||
| import org.apache.calcite.plan.RelTraitSet; | ||
| import org.apache.calcite.prepare.Prepare.CatalogReader; | ||
| import org.apache.calcite.rel.RelNode; | ||
| import org.apache.calcite.rel.core.TableModify; | ||
| import org.apache.calcite.rel.type.RelDataType; | ||
| import org.apache.calcite.rel.type.RelDataTypeFactory; | ||
| import org.apache.calcite.sql.type.SqlTypeName; | ||
| import org.checkerframework.checker.nullness.qual.Nullable; | ||
| import org.opensearch.sql.calcite.plan.AbstractOpenSearchTable; | ||
|
|
||
| /** | ||
| * Terminal write node for outputlookup, a Calcite {@link TableModify} INSERT so the optimizer | ||
| * treats it as a mandatory side effect (never dropped or reordered). The referenced table is the | ||
| * destination backing index, used only so the lowering rule can reach the in-cluster client; the | ||
| * lookup is created and written at execution time. Subclasses {@link TableModify} rather than | ||
| * LogicalTableModify so the built-in EnumerableTableModifyRule (which needs a ModifiableTable) does | ||
| * not fire. | ||
| */ | ||
| @Getter | ||
| public class OutputLookupTableModify extends TableModify { | ||
|
|
||
| private final String indexName; | ||
| private final boolean append; | ||
| private final boolean overrideIfEmpty; | ||
| private final List<String> keyFields; | ||
| private final @Nullable Integer max; | ||
|
|
||
| public OutputLookupTableModify( | ||
| RelOptCluster cluster, | ||
| RelTraitSet traits, | ||
| RelOptTable table, | ||
| CatalogReader catalogReader, | ||
| RelNode input, | ||
| String indexName, | ||
| boolean append, | ||
| boolean overrideIfEmpty, | ||
| java.util.List<String> keyFields, | ||
| @Nullable Integer max) { | ||
| super(cluster, traits, table, catalogReader, input, Operation.INSERT, null, null, false); | ||
| this.indexName = indexName; | ||
| this.append = append; | ||
| this.overrideIfEmpty = overrideIfEmpty; | ||
| this.keyFields = keyFields; | ||
| this.max = max; | ||
| } | ||
|
|
||
| public static OutputLookupTableModify create( | ||
| RelNode input, | ||
| RelOptTable table, | ||
| CatalogReader catalogReader, | ||
| String indexName, | ||
| boolean append, | ||
| boolean overrideIfEmpty, | ||
| java.util.List<String> keyFields, | ||
| @Nullable Integer max) { | ||
| RelOptCluster cluster = input.getCluster(); | ||
| RelTraitSet traits = cluster.traitSetOf(Convention.NONE); | ||
| return new OutputLookupTableModify( | ||
| cluster, | ||
| traits, | ||
| table, | ||
| catalogReader, | ||
| input, | ||
| indexName, | ||
| append, | ||
| overrideIfEmpty, | ||
| keyFields, | ||
| max); | ||
| } | ||
|
|
||
| @Override | ||
| public RelDataType deriveRowType() { | ||
| RelDataTypeFactory typeFactory = getCluster().getTypeFactory(); | ||
| return typeFactory | ||
| .builder() | ||
| .add("rows_written", typeFactory.createSqlType(SqlTypeName.BIGINT)) | ||
| .build(); | ||
| } | ||
|
|
||
| /** Registers the write-lowering rule when no OpenSearch scan in the pipeline does. */ | ||
| @Override | ||
| public void register(org.apache.calcite.plan.RelOptPlanner planner) { | ||
| AbstractOpenSearchTable osTable = table.unwrap(AbstractOpenSearchTable.class); | ||
| if (osTable != null) { | ||
| osTable.getWriteConversionRules().forEach(planner::addRule); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public RelNode copy(RelTraitSet traitSet, List<RelNode> inputs) { | ||
| return new OutputLookupTableModify( | ||
| getCluster(), | ||
| traitSet, | ||
| getTable(), | ||
| getCatalogReader(), | ||
| inputs.get(0), | ||
| indexName, | ||
| append, | ||
| overrideIfEmpty, | ||
| keyFields, | ||
| max); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.