-
Notifications
You must be signed in to change notification settings - Fork 216
New added commands should throw exception when calcite disabled #3571
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
Merged
Merged
Changes from 2 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
915686b
New added commands should throw exception when calcite disabled
LantaoJin 777273b
remove useless code
LantaoJin b9cbb9b
address comments
LantaoJin 4f9f561
Merge remote-tracking branch 'upstream/main' into issues/3568
LantaoJin 8e25b66
fix UT
LantaoJin a38e064
Merge remote-tracking branch 'upstream/main' into issues/3568
LantaoJin 879240c
Add a new IT case
LantaoJin 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 hidden or 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 hidden or 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
17 changes: 17 additions & 0 deletions
17
integ-test/src/test/java/org/opensearch/sql/calcite/remote/CalciteNewAddedCommandsIT.java
This file contains hidden or 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,17 @@ | ||
| /* | ||
| * Copyright OpenSearch Contributors | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| package org.opensearch.sql.calcite.remote; | ||
|
|
||
| import org.opensearch.sql.ppl.NewAddedCommandsIT; | ||
|
|
||
| public class CalciteNewAddedCommandsIT extends NewAddedCommandsIT { | ||
| @Override | ||
| public void init() throws Exception { | ||
| super.init(); | ||
| enableCalcite(); | ||
| disallowCalciteFallback(); | ||
| } | ||
| } |
136 changes: 136 additions & 0 deletions
136
integ-test/src/test/java/org/opensearch/sql/ppl/NewAddedCommandsIT.java
This file contains hidden or 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,136 @@ | ||
| /* | ||
| * Copyright OpenSearch Contributors | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| package org.opensearch.sql.ppl; | ||
|
|
||
| import static org.hamcrest.Matchers.containsString; | ||
| import static org.hamcrest.Matchers.equalTo; | ||
| import static org.opensearch.sql.common.setting.Settings.Key.CALCITE_ENGINE_ENABLED; | ||
| import static org.opensearch.sql.legacy.TestsConstants.TEST_INDEX_BANK; | ||
| import static org.opensearch.sql.legacy.TestsConstants.TEST_INDEX_DOG; | ||
|
|
||
| import java.io.IOException; | ||
| import org.json.JSONObject; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.opensearch.client.ResponseException; | ||
| import org.opensearch.sql.util.TestUtils; | ||
|
|
||
| public class NewAddedCommandsIT extends PPLIntegTestCase { | ||
| @Override | ||
| public void init() throws Exception { | ||
| super.init(); | ||
| loadIndex(Index.BANK); | ||
| loadIndex(Index.DOG); | ||
| } | ||
|
|
||
| @Test | ||
| public void testJoin() { | ||
| try { | ||
| JSONObject result; | ||
| try { | ||
| result = | ||
| executeQuery( | ||
| String.format( | ||
| "search source=%s | join on firstname=holdersName %s", | ||
| TEST_INDEX_BANK, TEST_INDEX_DOG)); | ||
| } catch (ResponseException e) { | ||
| result = new JSONObject(TestUtils.getResponseBody(e.getResponse())); | ||
| verifyQuery(result); | ||
| } | ||
| } catch (IOException e) { | ||
| fail(e.getMessage()); | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| public void testLookup() { | ||
| try { | ||
| JSONObject result; | ||
| try { | ||
| result = | ||
| executeQuery( | ||
| String.format( | ||
| "search source=%s | lookup %s holdersName as firstname", | ||
| TEST_INDEX_BANK, TEST_INDEX_DOG)); | ||
| } catch (ResponseException e) { | ||
| result = new JSONObject(TestUtils.getResponseBody(e.getResponse())); | ||
| } | ||
| verifyQuery(result); | ||
| } catch (IOException e) { | ||
| fail(e.getMessage()); | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| public void testSubsearch() { | ||
| try { | ||
| JSONObject result; | ||
| try { | ||
| result = | ||
| executeQuery( | ||
| String.format( | ||
| "search source=[source=%s | where age>35] as t | where age>35", | ||
| TEST_INDEX_BANK)); | ||
| } catch (ResponseException e) { | ||
| result = new JSONObject(TestUtils.getResponseBody(e.getResponse())); | ||
| } | ||
| verifyQuery(result); | ||
|
|
||
| try { | ||
| result = | ||
| executeQuery( | ||
| String.format( | ||
| "search source=%s | where exists [ source=%s | where firstname=holdersName]", | ||
| TEST_INDEX_BANK, TEST_INDEX_DOG)); | ||
| } catch (ResponseException e) { | ||
| result = new JSONObject(TestUtils.getResponseBody(e.getResponse())); | ||
| } | ||
| verifyQuery(result); | ||
|
|
||
| try { | ||
| result = | ||
| executeQuery( | ||
| String.format( | ||
| "search source=%s | where firstname in [ source=%s | fields holdersName]", | ||
| TEST_INDEX_BANK, TEST_INDEX_DOG)); | ||
| } catch (ResponseException e) { | ||
| result = new JSONObject(TestUtils.getResponseBody(e.getResponse())); | ||
| } | ||
| verifyQuery(result); | ||
|
|
||
| try { | ||
| result = | ||
| executeQuery( | ||
| String.format( | ||
| "search source=%s | where firstname = [ source=%s | where holdersName='Hattie'" | ||
| + " | fields holdersName | head 1]", | ||
| TEST_INDEX_BANK, TEST_INDEX_DOG)); | ||
| } catch (ResponseException e) { | ||
| result = new JSONObject(TestUtils.getResponseBody(e.getResponse())); | ||
| } | ||
| verifyQuery(result); | ||
| } catch (IOException e) { | ||
| fail(e.getMessage()); | ||
| } | ||
| } | ||
|
|
||
| private void verifyQuery(JSONObject result) { | ||
| try { | ||
| if (isCalciteEnabled()) { | ||
| assertFalse(result.getJSONArray("datarows").isEmpty()); | ||
| } else { | ||
| assertThat(result.getInt("status"), equalTo(500)); | ||
| JSONObject error = result.getJSONObject("error"); | ||
| assertThat( | ||
| error.getString("details"), | ||
| containsString( | ||
| "is supported only when " + CALCITE_ENGINE_ENABLED.getKeyValue() + "=true")); | ||
| assertThat(error.getString("type"), equalTo("UnsupportedOperationException")); | ||
| } | ||
| } catch (IOException e) { | ||
| fail(e.getMessage()); | ||
| } | ||
| } | ||
| } |
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -147,27 +147,39 @@ public static void disallowCalciteFallback() throws IOException { | |
| LOG.info("{} disabled", Settings.Key.CALCITE_FALLBACK_ALLOWED.name()); | ||
| } | ||
|
|
||
| protected static boolean isFallbackEnabled() throws IOException { | ||
| return Boolean.parseBoolean( | ||
| getClusterSetting(Settings.Key.CALCITE_FALLBACK_ALLOWED.getKeyValue(), "persistent")); | ||
| protected static boolean isFallbackEnabled() { | ||
|
Collaborator
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. Just curious, what's the concern of changing IOException to RuntimeException.
Member
Author
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. revert |
||
| try { | ||
| return Boolean.parseBoolean( | ||
| getClusterSetting(Settings.Key.CALCITE_FALLBACK_ALLOWED.getKeyValue(), "persistent")); | ||
| } catch (IOException e) { | ||
| throw new RuntimeException(e); | ||
| } | ||
| } | ||
|
|
||
| public static void withFallbackEnabled(Runnable f, String msg) throws IOException { | ||
| public static void withFallbackEnabled(Runnable f, String msg) { | ||
| LOG.info("Need fallback to v2 due to {}", msg); | ||
| boolean isFallbackEnabled = isFallbackEnabled(); | ||
| if (isFallbackEnabled) f.run(); | ||
| else { | ||
| try { | ||
| updateClusterSettings( | ||
| new SQLIntegTestCase.ClusterSetting( | ||
| "persistent", Settings.Key.CALCITE_FALLBACK_ALLOWED.getKeyValue(), "true")); | ||
| try { | ||
| updateClusterSettings( | ||
| new SQLIntegTestCase.ClusterSetting( | ||
| "persistent", Settings.Key.CALCITE_FALLBACK_ALLOWED.getKeyValue(), "true")); | ||
| } catch (IOException e) { | ||
| throw new RuntimeException(e); | ||
| } | ||
| LOG.info( | ||
| "Set {} to enabled and run the test", Settings.Key.CALCITE_FALLBACK_ALLOWED.name()); | ||
| f.run(); | ||
| } finally { | ||
| updateClusterSettings( | ||
| new SQLIntegTestCase.ClusterSetting( | ||
| "persistent", Settings.Key.CALCITE_FALLBACK_ALLOWED.getKeyValue(), "false")); | ||
| try { | ||
| updateClusterSettings( | ||
| new SQLIntegTestCase.ClusterSetting( | ||
| "persistent", Settings.Key.CALCITE_FALLBACK_ALLOWED.getKeyValue(), "false")); | ||
| } catch (IOException e) { | ||
| throw new RuntimeException(e); | ||
| } | ||
| LOG.info("Reset {} back to disabled", Settings.Key.CALCITE_FALLBACK_ALLOWED.name()); | ||
| } | ||
| } | ||
|
|
||
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.
Uh oh!
There was an error while loading. Please reload this page.