forked from opensearch-project/sql
-
Notifications
You must be signed in to change notification settings - Fork 0
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
Closed
Changes from all commits
Commits
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
|
@@ -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() | ||
&& cur.symbolTable.lookup(symbol).get().equals(ExprCoreType.ARRAY)) { | ||
throw new UnsupportedV2NestedException( | ||
String.format("can't resolve %s type in the new engine", symbol)); | ||
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. We should mention unsupported...
|
||
} | ||
|
||
Optional<ExprType> typeOptional = cur.symbolTable.lookup(symbol); | ||
if (typeOptional.isPresent()) { | ||
return typeOptional.get(); | ||
|
19 changes: 19 additions & 0 deletions
19
core/src/main/java/org/opensearch/sql/exception/UnsupportedV2NestedException.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,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); | ||
} | ||
} | ||
|
||
|
||
|
56 changes: 56 additions & 0 deletions
56
integ-test/src/test/java/org/opensearch/sql/sql/NestedFallbackIT.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,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")); | ||
} | ||
} |
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
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.
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.
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.
For some reason the running
SELECT message.info
doesn't hit that code actually. Will investigate. Thanks!