Skip to content

Commit

Permalink
Merge branch 'dev-spike-nested-aggregation' of github.com:Bit-Quill/o…
Browse files Browse the repository at this point in the history
…pensearch-project-sql into dev-spike-nested-aggregation
  • Loading branch information
forestmvey committed Feb 8, 2023
2 parents 86b3f39 + 508cbcc commit cb7508d
Show file tree
Hide file tree
Showing 10 changed files with 14 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -90,15 +90,13 @@ public void explain(UnresolvedPlan plan,
* Analyze {@link UnresolvedPlan}.
*/
public LogicalPlan analyze(UnresolvedPlan plan) {
var ret = analyzer.analyze(plan, new AnalysisContext());
return ret;
return analyzer.analyze(plan, new AnalysisContext());
}

/**
* Translate {@link LogicalPlan} to {@link PhysicalPlan}.
*/
public PhysicalPlan plan(LogicalPlan plan) {
var ret = planner.plan(plan);
return ret;
return planner.plan(plan);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,13 @@ public boolean pushDownHighlight(LogicalHighlight highlight) {
return false;
}

/**
* Can a given nested operator be pushed down to table scan builder. Assume no such support
* by default unless subclass override this.
*
* @param nested logical highlight operator
* @return true if pushed down, otherwise false
*/
public boolean pushDownNested(LogicalNested nested) {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,6 @@ public void xor() {
);
}

@Test
public void nested() {
assertAnalyzeEqual(
DSL.nested(DSL.ref("field.subfield", STRING)),
AstDSL.nested(qualifiedName("field.subfield")));
}

@Test
public void not() {
assertAnalyzeEqual(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,15 +90,16 @@ public void testSelectNestedFieldItself() {
@Test
public void testSelectObjectFieldOfArrayValuesItself() {
JSONObject response = new JSONObject(query("SELECT accounts FROM %s"));
var blah = rows(new JSONArray(List.of("c","a")), "ab");
verifyDataRows(response, rows(new JSONArray(List.of(new JSONObject("{\"id\":1}"), new JSONObject("{\"id\":2}")))));

verifyDataRows(response,
rows(new JSONArray(List.of(new JSONObject("{\"id\":1}"),
new JSONObject("{\"id\":2}")))));
}

@Test
public void testSelectObjectFieldOfArrayValuesInnerFields() {
JSONObject response = new JSONObject(query("SELECT accounts.id FROM %s"));

// Only the first element of the list of is returned.
verifyDataRows(response, rows(new JSONArray(List.of(1,2))));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@
import java.util.HashMap;
import java.util.Map;
import lombok.RequiredArgsConstructor;
import org.apache.commons.lang3.tuple.Pair;
import org.opensearch.index.query.QueryBuilder;
import org.opensearch.search.aggregations.AggregationBuilder;
import org.opensearch.sql.common.setting.Settings;
import org.opensearch.sql.data.type.ExprType;
import org.opensearch.sql.opensearch.client.OpenSearchClient;
Expand All @@ -28,7 +25,6 @@
import org.opensearch.sql.planner.logical.LogicalAD;
import org.opensearch.sql.planner.logical.LogicalML;
import org.opensearch.sql.planner.logical.LogicalMLCommons;
import org.opensearch.sql.planner.logical.LogicalNested;
import org.opensearch.sql.planner.logical.LogicalPlan;
import org.opensearch.sql.planner.physical.PhysicalPlan;
import org.opensearch.sql.storage.Table;
Expand Down Expand Up @@ -153,11 +149,5 @@ public PhysicalPlan visitML(LogicalML node, OpenSearchIndexScan context) {
return new MLOperator(visitChild(node, context),
node.getArguments(), client.getNodeClient());
}

// @Override
// public PhysicalPlan visitUnnested(LogicalNested node, OpenSearchIndexScan context) {
//// context.getRequestBuilder().pushDownNested(node.getField().toString());
// return visitChild(node, context);
// }
}
}
4 changes: 0 additions & 4 deletions sql/src/main/antlr/OpenSearchSQLParser.g4
Original file line number Diff line number Diff line change
Expand Up @@ -491,10 +491,6 @@ noFieldRelevanceFunctionName
: QUERY
;

nestedFunctionName
: NESTED
;

systemFunctionName
: TYPEOF
;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,7 @@ public UnresolvedPlan visitSelectClause(SelectClauseContext ctx) {
}
ctx.selectElements().selectElement().forEach(field -> builder.add(visitSelectItem(field)));

UnresolvedPlan result = new Project(builder.build());
return result;
return new Project(builder.build());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,6 @@ public void canParseQueryEndWithSemiColon() {
assertNotNull(parser.parse("SELECT 123;"));
}

@Test
public void canParseQasdueryEndWithSemiColon() {
assertNotNull(parser.parse("SELECT nested(message.info) from blah;"));
}

@Test
public void canParseSelectLiterals() {
assertNotNull(parser.parse("SELECT 123, 'hello'"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -696,14 +696,4 @@ public void can_build_string_literal_highlight() {
buildAST("SELECT highlight(\"fieldA\") FROM test")
);
}

@Test
public void can_build_nested_in_select() {
assertEquals(
project(relation("test"),
alias("field.subfield",
qualifiedName("field.subfield"))),
buildAST("SELECT nested(\"field.subfield\") FROM test")
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -367,21 +367,6 @@ public void canBuildStringLiteralPositionFunction() {
);
}

// @Test
// public void canBuildStringLiteralNestedFunction() {
// assertEquals(
// nested(AstDSL.stringLiteral("field.subfield")),
// buildExprAst("nested(\"field.subfield\")")
// );
// }
//
// @Test
// public void canBuildQualifiedNameNestedFunction() {
// assertEquals(
// nested(AstDSL.qualifiedName("field", "subfield")),
// buildExprAst("nested(field.subfield)")
// );
// }

@Test
public void canBuildWindowFunctionWithoutOrderBy() {
Expand Down

0 comments on commit cb7508d

Please sign in to comment.