-
Notifications
You must be signed in to change notification settings - Fork 141
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
Add FILLNULL command in PPL (#3032) #3075
Merged
acarbonetto
merged 11 commits into
opensearch-project:main
from
Bit-Quill:opensearch-3032
Dec 5, 2024
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
bac4725
Add FILLNULL command in PPL (#3032)
normanj-bitquill 4be00ba
Added some integration tests for fillnull
normanj-bitquill 913177f
Updated the multi field integration test
normanj-bitquill 104445a
Added some more tests
normanj-bitquill 6df47b6
Updated fillnull doc to match doc for Spark
normanj-bitquill 00fe9be
Added fillnull to the keywordsCanBeId list
normanj-bitquill 18ccf38
Update ppl/src/main/java/org/opensearch/sql/ppl/utils/PPLQueryDataAno…
normanj-bitquill 430bf78
Update ppl/src/test/java/org/opensearch/sql/ppl/utils/PPLQueryDataAno…
normanj-bitquill 3ac44f0
Update ppl/src/test/java/org/opensearch/sql/ppl/parser/AstBuilderTest…
normanj-bitquill 0f04940
Update ppl/src/test/java/org/opensearch/sql/ppl/antlr/PPLSyntaxParser…
normanj-bitquill 8559e1c
Simplified the grammar for FILLNULL
normanj-bitquill 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 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 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 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
89 changes: 89 additions & 0 deletions
89
core/src/main/java/org/opensearch/sql/ast/tree/FillNull.java
This file contains 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,89 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.sql.ast.tree; | ||
|
||
import java.util.List; | ||
import java.util.Objects; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NonNull; | ||
import lombok.RequiredArgsConstructor; | ||
import org.opensearch.sql.ast.AbstractNodeVisitor; | ||
import org.opensearch.sql.ast.Node; | ||
import org.opensearch.sql.ast.expression.Field; | ||
import org.opensearch.sql.ast.expression.UnresolvedExpression; | ||
|
||
/** AST node represent FillNull operation. */ | ||
@RequiredArgsConstructor | ||
@AllArgsConstructor | ||
public class FillNull extends UnresolvedPlan { | ||
|
||
@Getter | ||
@RequiredArgsConstructor | ||
public static class NullableFieldFill { | ||
@NonNull private final Field nullableFieldReference; | ||
@NonNull private final UnresolvedExpression replaceNullWithMe; | ||
} | ||
|
||
public interface ContainNullableFieldFill { | ||
List<NullableFieldFill> getNullFieldFill(); | ||
|
||
static ContainNullableFieldFill ofVariousValue(List<NullableFieldFill> replacements) { | ||
return new VariousValueNullFill(replacements); | ||
} | ||
|
||
static ContainNullableFieldFill ofSameValue( | ||
UnresolvedExpression replaceNullWithMe, List<Field> nullableFieldReferences) { | ||
return new SameValueNullFill(replaceNullWithMe, nullableFieldReferences); | ||
} | ||
} | ||
|
||
private static class SameValueNullFill implements ContainNullableFieldFill { | ||
@Getter(onMethod_ = @Override) | ||
private final List<NullableFieldFill> nullFieldFill; | ||
|
||
public SameValueNullFill( | ||
UnresolvedExpression replaceNullWithMe, List<Field> nullableFieldReferences) { | ||
Objects.requireNonNull(replaceNullWithMe, "Null replacement is required"); | ||
this.nullFieldFill = | ||
Objects.requireNonNull(nullableFieldReferences, "Nullable field reference is required") | ||
.stream() | ||
.map(nullableReference -> new NullableFieldFill(nullableReference, replaceNullWithMe)) | ||
.toList(); | ||
} | ||
} | ||
|
||
@RequiredArgsConstructor | ||
private static class VariousValueNullFill implements ContainNullableFieldFill { | ||
@NonNull | ||
@Getter(onMethod_ = @Override) | ||
private final List<NullableFieldFill> nullFieldFill; | ||
} | ||
|
||
private UnresolvedPlan child; | ||
|
||
@NonNull private final ContainNullableFieldFill containNullableFieldFill; | ||
|
||
public List<NullableFieldFill> getNullableFieldFills() { | ||
return containNullableFieldFill.getNullFieldFill(); | ||
} | ||
|
||
@Override | ||
public UnresolvedPlan attach(UnresolvedPlan child) { | ||
this.child = child; | ||
return this; | ||
} | ||
|
||
@Override | ||
public List<? extends Node> getChild() { | ||
return child == null ? List.of() : List.of(child); | ||
} | ||
|
||
@Override | ||
public <T, C> T accept(AbstractNodeVisitor<T, C> nodeVisitor, C context) { | ||
return nodeVisitor.visitFillNull(this, context); | ||
} | ||
} |
This file contains 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 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
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. You need to list new file in table of content (see James's PR for example) 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. Updated. |
This file contains 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,62 @@ | ||
============= | ||
fillnull | ||
normanj-bitquill marked this conversation as resolved.
Show resolved
Hide resolved
|
||
============= | ||
|
||
.. rubric:: Table of contents | ||
|
||
.. contents:: | ||
:local: | ||
:depth: 2 | ||
|
||
|
||
Description | ||
============ | ||
Using ``fillnull`` command to fill null with provided value in one or more fields in the search result. | ||
|
||
|
||
Syntax | ||
============ | ||
`fillnull [with <null-replacement> in <nullable-field>["," <nullable-field>]] | [using <source-field> = <null-replacement> [","<source-field> = <null-replacement>]]` | ||
|
||
* null-replacement: mandatory. The value used to replace `null`s. | ||
* nullable-field: mandatory. Field reference. The `null` values in the field referred to by the property will be replaced with the values from the null-replacement. | ||
|
||
Example 1: fillnull one field | ||
====================================================================== | ||
|
||
The example show fillnull one field. | ||
|
||
PPL query:: | ||
|
||
os> source=accounts | fields email, employer | fillnull with '<not found>' in email ; | ||
fetched rows / total rows = 4/4 | ||
+-----------------------+----------+ | ||
| email | employer | | ||
|-----------------------+----------| | ||
| [email protected] | Pyrami | | ||
| [email protected] | Netagy | | ||
| <not found> | Quility | | ||
| [email protected] | null | | ||
+-----------------------+----------+ | ||
|
||
Example 2: fillnull applied to multiple fields | ||
======================================================================== | ||
|
||
The example show fillnull applied to multiple fields. | ||
|
||
PPL query:: | ||
|
||
os> source=accounts | fields email, employer | fillnull using email = '<not found>', employer = '<no employer>' ; | ||
fetched rows / total rows = 4/4 | ||
+-----------------------+---------------+ | ||
| email | employer | | ||
|-----------------------+---------------| | ||
| [email protected] | Pyrami | | ||
| [email protected] | Netagy | | ||
| <not found> | Quility | | ||
| [email protected] | <no employer> | | ||
+-----------------------+---------------+ | ||
|
||
Limitation | ||
========== | ||
The ``fillnull`` command is not rewritten to OpenSearch DSL, it is only executed on the coordination node. |
This file contains 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.
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.
Do you mind adding a doc?
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.
Added a Javadoc comment.