Skip to content
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

[WIP] Added new exception for nested fields to force it to fallback to legacy #205

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@
import org.opensearch.sql.analysis.symbol.Namespace;
import org.opensearch.sql.analysis.symbol.Symbol;
import org.opensearch.sql.analysis.symbol.SymbolTable;
import org.opensearch.sql.data.type.ExprCoreType;
import org.opensearch.sql.data.type.ExprType;
import org.opensearch.sql.exception.SemanticCheckException;
import org.opensearch.sql.exception.UnsupportedV2NestedException;
import org.opensearch.sql.expression.Expression;
import org.opensearch.sql.expression.ReferenceExpression;
import org.opensearch.sql.expression.env.Environment;
Expand Down Expand Up @@ -48,6 +50,12 @@ public TypeEnvironment(TypeEnvironment parent, SymbolTable symbolTable) {
@Override
public ExprType resolve(Symbol symbol) {
for (TypeEnvironment cur = this; cur != null; cur = cur.parent) {
if (!cur.symbolTable.lookup(symbol).isEmpty()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like there is already a fallback mechanism HERE. Could we alter this to work for nested with partiql syntax? At a quick glance I'm not sure why it's not working.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For some reason the running SELECT message.info doesn't hit that code actually. Will investigate. Thanks!

&& cur.symbolTable.lookup(symbol).get().equals(ExprCoreType.ARRAY)) {
throw new UnsupportedV2NestedException(
String.format("can't resolve %s type in the new engine", symbol));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should mention unsupported...

"%s type is unsupported in the new engine"

}

Optional<ExprType> typeOptional = cur.symbolTable.lookup(symbol);
if (typeOptional.isPresent()) {
return typeOptional.get();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/


package org.opensearch.sql.exception;

/**
* Exception thrown to fall back to legacy when nested fields are queried.
*/
public class UnsupportedV2NestedException extends QueryEngineException {
public UnsupportedV2NestedException(String message) {
super(message);
}
}



Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/


package org.opensearch.sql.sql;
import org.json.JSONObject;
import org.junit.Ignore;
import org.junit.Test;
import org.opensearch.sql.legacy.SQLIntegTestCase;
import java.io.IOException;

import static org.opensearch.sql.legacy.TestsConstants.TEST_INDEX_NESTED_TYPE;
import static org.opensearch.sql.util.MatcherUtils.schema;
import static org.opensearch.sql.util.MatcherUtils.verifyColumn;
import static org.opensearch.sql.util.MatcherUtils.verifyDataRows;
import static org.opensearch.sql.util.MatcherUtils.rows;

public class NestedFallbackIT extends SQLIntegTestCase{
@Override
public void init() throws IOException {
loadIndex(Index.NESTED);
}

@Test
public void nested_function_and_without_nested_function_test() {
String query = "SELECT nested(message.info), message.info FROM " + TEST_INDEX_NESTED_TYPE;
JSONObject result = executeJdbcRequest(query);

verifyColumn(result, schema("message.info", "keyword"),
schema("message.info", "keyword"));
verifyDataRows(result, rows("a", "a"),
rows("b", "b"),
rows("c", "c"),
rows("c", "c"),
rows("a", "a"),
rows("zz", "zz"));
}

@Ignore("Legacy has a bug that returns nulls for array values. " +
"This will be fixed in the new engine. https://github.com/opensearch-project/sql/issues/1218")
@Test
public void without_nested_function_test() {
String query = "SELECT message.info FROM " + TEST_INDEX_NESTED_TYPE;
JSONObject result = executeJdbcRequest(query);

verifyColumn(result, schema("message.info", "keyword"));
verifyDataRows(result, rows("a"),
rows("b"),
rows("c"),
rows("c"),
rows("a"),
rows("zz"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.opensearch.sql.common.antlr.SyntaxCheckException;
import org.opensearch.sql.common.response.ResponseListener;
import org.opensearch.sql.common.utils.QueryContext;
import org.opensearch.sql.exception.UnsupportedV2NestedException;
import org.opensearch.sql.executor.ExecutionEngine.ExplainResponse;
import org.opensearch.sql.legacy.metrics.MetricName;
import org.opensearch.sql.legacy.metrics.Metrics;
Expand Down Expand Up @@ -126,7 +127,7 @@ public void onResponse(T response) {

@Override
public void onFailure(Exception e) {
if (e instanceof SyntaxCheckException) {
if (e instanceof SyntaxCheckException || e instanceof UnsupportedV2NestedException) {
fallBackHandler.accept(channel, e);
} else {
next.onFailure(e);
Expand Down