Skip to content

Commit f2365b4

Browse files
authored
Support appendcol command with Calcite (opensearch-project#3729)
1 parent 2f2117b commit f2365b4

39 files changed

Lines changed: 759 additions & 26 deletions

core/src/main/java/org/opensearch/sql/analysis/Analyzer.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
import org.opensearch.sql.ast.expression.UnresolvedExpression;
4848
import org.opensearch.sql.ast.tree.AD;
4949
import org.opensearch.sql.ast.tree.Aggregation;
50+
import org.opensearch.sql.ast.tree.AppendCol;
5051
import org.opensearch.sql.ast.tree.CloseCursor;
5152
import org.opensearch.sql.ast.tree.Dedupe;
5253
import org.opensearch.sql.ast.tree.Eval;
@@ -702,6 +703,12 @@ public LogicalPlan visitLookup(Lookup node, AnalysisContext context) {
702703
"Lookup is supported only when " + CALCITE_ENGINE_ENABLED.getKeyValue() + "=true");
703704
}
704705

706+
@Override
707+
public LogicalPlan visitAppendCol(AppendCol node, AnalysisContext context) {
708+
throw new UnsupportedOperationException(
709+
"AppendCol is supported only when " + CALCITE_ENGINE_ENABLED.getKeyValue() + "=true");
710+
}
711+
705712
private LogicalSort buildSort(
706713
LogicalPlan child, AnalysisContext context, List<Field> sortFields) {
707714
ExpressionReferenceOptimizer optimizer =

core/src/main/java/org/opensearch/sql/ast/AbstractNodeVisitor.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
import org.opensearch.sql.ast.statement.Statement;
4646
import org.opensearch.sql.ast.tree.AD;
4747
import org.opensearch.sql.ast.tree.Aggregation;
48+
import org.opensearch.sql.ast.tree.AppendCol;
4849
import org.opensearch.sql.ast.tree.CloseCursor;
4950
import org.opensearch.sql.ast.tree.Dedupe;
5051
import org.opensearch.sql.ast.tree.Eval;
@@ -371,4 +372,8 @@ public T visitScalarSubquery(ScalarSubquery node, C context) {
371372
public T visitExistsSubquery(ExistsSubquery node, C context) {
372373
return visitChildren(node, context);
373374
}
375+
376+
public T visitAppendCol(AppendCol node, C context) {
377+
return visitChildren(node, context);
378+
}
374379
}

core/src/main/java/org/opensearch/sql/ast/tree/AD.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,6 @@ public <T, C> T accept(AbstractNodeVisitor<T, C> nodeVisitor, C context) {
4141

4242
@Override
4343
public List<UnresolvedPlan> getChild() {
44-
return ImmutableList.of(this.child);
44+
return this.child == null ? ImmutableList.of() : ImmutableList.of(this.child);
4545
}
4646
}

core/src/main/java/org/opensearch/sql/ast/tree/Aggregation.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public Aggregation attach(UnresolvedPlan child) {
6363

6464
@Override
6565
public List<UnresolvedPlan> getChild() {
66-
return ImmutableList.of(this.child);
66+
return this.child == null ? ImmutableList.of() : ImmutableList.of(this.child);
6767
}
6868

6969
@Override
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
* Copyright OpenSearch Contributors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
package org.opensearch.sql.ast.tree;
7+
8+
import com.google.common.collect.ImmutableList;
9+
import java.util.List;
10+
import lombok.EqualsAndHashCode;
11+
import lombok.Getter;
12+
import lombok.RequiredArgsConstructor;
13+
import lombok.Setter;
14+
import lombok.ToString;
15+
import org.opensearch.sql.ast.AbstractNodeVisitor;
16+
import org.opensearch.sql.ast.Node;
17+
18+
/**
19+
* Logical plan node of AppendCol, the interface for building appending column actions in queries.
20+
*/
21+
@Getter
22+
@Setter
23+
@ToString
24+
@EqualsAndHashCode(callSuper = false)
25+
@RequiredArgsConstructor
26+
public class AppendCol extends UnresolvedPlan {
27+
28+
private final boolean override;
29+
30+
private final UnresolvedPlan subSearch;
31+
32+
private UnresolvedPlan child;
33+
34+
@Override
35+
public UnresolvedPlan attach(UnresolvedPlan child) {
36+
this.child = child;
37+
return this;
38+
}
39+
40+
@Override
41+
public List<? extends Node> getChild() {
42+
return this.child == null ? ImmutableList.of() : ImmutableList.of(this.child);
43+
}
44+
45+
@Override
46+
public <T, C> T accept(AbstractNodeVisitor<T, C> visitor, C context) {
47+
return visitor.visitAppendCol(this, context);
48+
}
49+
}

core/src/main/java/org/opensearch/sql/ast/tree/CloseCursor.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
package org.opensearch.sql.ast.tree;
77

8+
import com.google.common.collect.ImmutableList;
89
import java.util.List;
910
import org.opensearch.sql.ast.AbstractNodeVisitor;
1011
import org.opensearch.sql.ast.Node;
@@ -28,6 +29,6 @@ public UnresolvedPlan attach(UnresolvedPlan child) {
2829

2930
@Override
3031
public List<? extends Node> getChild() {
31-
return List.of(cursor);
32+
return this.cursor == null ? ImmutableList.of() : ImmutableList.of(this.cursor);
3233
}
3334
}

core/src/main/java/org/opensearch/sql/ast/tree/Dedupe.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public Dedupe attach(UnresolvedPlan child) {
3737

3838
@Override
3939
public List<UnresolvedPlan> getChild() {
40-
return ImmutableList.of(this.child);
40+
return this.child == null ? ImmutableList.of() : ImmutableList.of(this.child);
4141
}
4242

4343
@Override

core/src/main/java/org/opensearch/sql/ast/tree/Eval.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public Eval attach(UnresolvedPlan child) {
3333

3434
@Override
3535
public List<UnresolvedPlan> getChild() {
36-
return ImmutableList.of(this.child);
36+
return this.child == null ? ImmutableList.of() : ImmutableList.of(this.child);
3737
}
3838

3939
@Override

core/src/main/java/org/opensearch/sql/ast/tree/FillNull.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
package org.opensearch.sql.ast.tree;
77

8+
import com.google.common.collect.ImmutableList;
89
import java.util.List;
910
import java.util.Optional;
1011
import lombok.EqualsAndHashCode;
@@ -59,7 +60,7 @@ public FillNull attach(UnresolvedPlan child) {
5960

6061
@Override
6162
public List<? extends Node> getChild() {
62-
return child == null ? List.of() : List.of(child);
63+
return this.child == null ? ImmutableList.of() : ImmutableList.of(this.child);
6364
}
6465

6566
@Override

core/src/main/java/org/opensearch/sql/ast/tree/Filter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public Filter attach(UnresolvedPlan child) {
3333

3434
@Override
3535
public List<UnresolvedPlan> getChild() {
36-
return ImmutableList.of(child);
36+
return this.child == null ? ImmutableList.of() : ImmutableList.of(this.child);
3737
}
3838

3939
@Override

0 commit comments

Comments
 (0)