forked from opensearch-project/sql
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Simeon Widdis <sawiddis@amazon.com>
- Loading branch information
Showing
1 changed file
with
82 additions
and
0 deletions.
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.http.ParseException; | ||
import org.apache.http.util.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")); | ||
} | ||
} |