-
Notifications
You must be signed in to change notification settings - Fork 141
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve error handling for some more edge cases (#3080)
* Add failing tests Signed-off-by: Simeon Widdis <[email protected]> * Fix the first test Signed-off-by: Simeon Widdis <[email protected]> * Revise the tests Signed-off-by: Simeon Widdis <[email protected]> * Fix wildcard tests Signed-off-by: Simeon Widdis <[email protected]> * Add license header Signed-off-by: Simeon Widdis <[email protected]> * Fix rerunning SQL parsing Signed-off-by: Simeon Widdis <[email protected]> --------- Signed-off-by: Simeon Widdis <[email protected]>
- Loading branch information
Showing
3 changed files
with
108 additions
and
1 deletion.
There are no files selected for viewing
82 changes: 82 additions & 0 deletions
82
integ-test/src/test/java/org/opensearch/sql/legacy/MalformedQueryIT.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,82 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.sql.legacy; | ||
|
||
import java.io.IOException; | ||
import java.util.Locale; | ||
import org.apache.hc.core5.http.ParseException; | ||
import org.apache.hc.core5.http.io.entity.EntityUtils; | ||
import org.json.JSONObject; | ||
import org.junit.Assert; | ||
import org.opensearch.client.ResponseException; | ||
|
||
/** Tests for clean handling of various types of invalid queries */ | ||
public class MalformedQueryIT extends SQLIntegTestCase { | ||
@Override | ||
protected void init() throws Exception { | ||
loadIndex(Index.BANK); | ||
loadIndex(Index.BANK_TWO); | ||
} | ||
|
||
public void testJoinWithInvalidCondition() throws IOException, ParseException { | ||
ResponseException result = | ||
assertThrows( | ||
"Expected Join query with malformed 'ON' to raise error, but didn't", | ||
ResponseException.class, | ||
() -> | ||
executeQuery( | ||
String.format( | ||
Locale.ROOT, | ||
"SELECT a.firstname, b.age FROM %s AS a INNER JOIN %s AS b %%" | ||
+ " a.account_number=b.account_number", | ||
TestsConstants.TEST_INDEX_BANK, | ||
TestsConstants.TEST_INDEX_BANK_TWO))); | ||
var errMsg = new JSONObject(EntityUtils.toString(result.getResponse().getEntity())); | ||
|
||
Assert.assertEquals("SqlParseException", errMsg.getJSONObject("error").getString("type")); | ||
Assert.assertEquals(400, errMsg.getInt("status")); | ||
} | ||
|
||
public void testWrappedWildcardInSubquery() throws IOException, ParseException { | ||
ResponseException result = | ||
assertThrows( | ||
"Expected wildcard subquery to raise error, but didn't", | ||
ResponseException.class, | ||
() -> | ||
executeQuery( | ||
String.format( | ||
Locale.ROOT, | ||
"SELECT a.first_name FROM %s AS a WHERE a.age IN (SELECT age FROM" | ||
+ " `opensearch-sql_test_index_*` WHERE age > 30)", | ||
TestsConstants.TEST_INDEX_BANK, | ||
TestsConstants.TEST_INDEX_BANK_TWO))); | ||
var errMsg = new JSONObject(EntityUtils.toString(result.getResponse().getEntity())); | ||
System.err.println("Full response: " + errMsg); | ||
|
||
Assert.assertEquals("IndexNotFoundException", errMsg.getJSONObject("error").getString("type")); | ||
Assert.assertEquals(404, errMsg.getInt("status")); | ||
} | ||
|
||
public void testUnwrappedWildcardInSubquery() throws IOException, ParseException { | ||
ResponseException result = | ||
assertThrows( | ||
"Expected wildcard subquery to raise error, but didn't", | ||
ResponseException.class, | ||
() -> | ||
executeQuery( | ||
String.format( | ||
Locale.ROOT, | ||
"SELECT a.first_name FROM %s AS a WHERE a.age IN (SELECT age FROM * WHERE" | ||
+ " age > 30)", | ||
TestsConstants.TEST_INDEX_BANK, | ||
TestsConstants.TEST_INDEX_BANK_TWO))); | ||
var errMsg = new JSONObject(EntityUtils.toString(result.getResponse().getEntity())); | ||
System.err.println("Full response: " + errMsg); | ||
|
||
Assert.assertEquals("IndexNotFoundException", errMsg.getJSONObject("error").getString("type")); | ||
Assert.assertEquals(404, errMsg.getInt("status")); | ||
} | ||
} |
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
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