generated from amazon-archives/__template_Custom
-
Notifications
You must be signed in to change notification settings - Fork 181
Add nomv command #5130
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
srikanthpadakanti
wants to merge
7
commits into
opensearch-project:main
Choose a base branch
from
srikanthpadakanti:feature/nomv
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
Add nomv command #5130
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
0a16953
Add nomv command + parser/AST/calcite wiring + tests + docs
0d714ac
Address coderrabbit suggestions.
836fe43
Correct the no_push_down yaml expected result
39fdbd5
Fix Windows CI: Override verifyPPLToSparkSQL to preserve ARRAY_JOIN '…
83e6345
Fix Windows CI: Override verifyPPLToSparkSQL to preserve ARRAY_JOIN '…
8632bc0
Fix Windows CI: Override verifyPPLToSparkSQL to preserve ARRAY_JOIN '…
5d7e879
Address code review comments
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| /* | ||
| * 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 javax.annotation.Nullable; | ||
| import lombok.EqualsAndHashCode; | ||
| import lombok.Getter; | ||
| import lombok.ToString; | ||
| import org.opensearch.sql.ast.AbstractNodeVisitor; | ||
| import org.opensearch.sql.ast.expression.DataType; | ||
| import org.opensearch.sql.ast.expression.Field; | ||
| import org.opensearch.sql.ast.expression.Function; | ||
| import org.opensearch.sql.ast.expression.Let; | ||
| import org.opensearch.sql.ast.expression.Literal; | ||
|
|
||
| /** | ||
| * AST node for the NOMV command. Converts multi-value fields to single-value fields by joining | ||
| * array elements with newline delimiter. | ||
| */ | ||
| @Getter | ||
| @ToString(callSuper = true) | ||
| @EqualsAndHashCode(callSuper = false) | ||
| public class NoMv extends UnresolvedPlan { | ||
|
|
||
| private final Field field; | ||
| @Nullable private UnresolvedPlan child; | ||
|
|
||
| public NoMv(Field field) { | ||
| this.field = field; | ||
| } | ||
|
|
||
| public NoMv attach(UnresolvedPlan child) { | ||
| this.child = child; | ||
| return this; | ||
| } | ||
|
|
||
| @Override | ||
| public List<UnresolvedPlan> getChild() { | ||
| return child == null ? ImmutableList.of() : ImmutableList.of(child); | ||
| } | ||
|
|
||
| @Override | ||
| public <T, C> T accept(AbstractNodeVisitor<T, C> nodeVisitor, C context) { | ||
| return nodeVisitor.visitNoMv(this, context); | ||
| } | ||
|
|
||
| /** | ||
| * Rewrites the nomv command as an eval command using mvjoin function with null filtering. nomv | ||
| * <field> is rewritten to: eval <field> = coalesce(mvjoin(array_compact(<field>), "\n"), "") | ||
| * | ||
| * <p>The array_compact removes null elements from the array, and coalesce ensures empty arrays | ||
| * return empty string instead of null. | ||
| * | ||
| * @return an Eval node representing the equivalent mvjoin operation with null filtering | ||
| */ | ||
| public UnresolvedPlan rewriteAsEval() { | ||
| Function arrayCompactFunc = new Function("array_compact", ImmutableList.of(field)); | ||
|
|
||
| Function mvjoinFunc = | ||
| new Function( | ||
| "mvjoin", ImmutableList.of(arrayCompactFunc, new Literal("\n", DataType.STRING))); | ||
|
|
||
| Function coalesceFunc = | ||
| new Function("coalesce", ImmutableList.of(mvjoinFunc, new Literal("", DataType.STRING))); | ||
|
|
||
| Let letExpr = new Let(field, coalesceFunc); | ||
|
|
||
| Eval eval = new Eval(ImmutableList.of(letExpr)); | ||
| if (this.child != null) { | ||
| eval.attach(this.child); | ||
| } | ||
| return eval; | ||
| } | ||
| } |
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
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.