-
Notifications
You must be signed in to change notification settings - Fork 141
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Signed-off-by: Norman Jordan <[email protected]> Signed-off-by: normanj-bitquill <[email protected]> Co-authored-by: Andrew Carbonetto <[email protected]>
- Loading branch information
1 parent
6712526
commit b6846ce
Showing
17 changed files
with
635 additions
and
0 deletions.
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
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 | ||
============= | ||
|
||
.. 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.