This repository has been archived by the owner on Aug 2, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 186
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Converting HashJoinBasicTest to ESIntegTestCase (#74)
*Issue:* #17 *How tested:* ./gradlew build
- Loading branch information
Showing
3 changed files
with
98 additions
and
126 deletions.
There are no files selected for viewing
98 changes: 98 additions & 0 deletions
98
src/test/java/com/amazon/opendistroforelasticsearch/sql/esintgtest/HashJoinBasicIT.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,98 @@ | ||
/* | ||
* Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"). | ||
* You may not use this file except in compliance with the License. | ||
* A copy of the License is located at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* or in the "license" file accompanying this file. This file is distributed | ||
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
* express or implied. See the License for the specific language governing | ||
* permissions and limitations under the License. | ||
*/ | ||
|
||
package com.amazon.opendistroforelasticsearch.sql.esintgtest; | ||
|
||
import org.json.JSONArray; | ||
import org.json.JSONObject; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
|
||
import java.io.IOException; | ||
import java.util.HashSet; | ||
import java.util.Locale; | ||
import java.util.Set; | ||
|
||
import static com.amazon.opendistroforelasticsearch.sql.esintgtest.TestsConstants.TEST_INDEX_ACCOUNT; | ||
import static org.hamcrest.Matchers.equalTo; | ||
|
||
/** | ||
* Test new hash join algorithm by comparison with old implementation. | ||
*/ | ||
public class HashJoinBasicIT extends SQLIntegTestCase { | ||
|
||
/** | ||
* Hint to use old join algorithm | ||
*/ | ||
private static final String USE_OLD_JOIN_ALGORITHM = "/*! USE_NL*/"; | ||
|
||
/** | ||
* Set limit to 100% to bypass circuit break check | ||
*/ | ||
private static final String BYPASS_CIRCUIT_BREAK = "/*! JOIN_CIRCUIT_BREAK_LIMIT(100)*/"; | ||
|
||
@Override | ||
protected void init() throws Exception { | ||
loadIndex(Index.ACCOUNT); | ||
} | ||
|
||
@Test | ||
public void innerJoin() throws IOException { | ||
|
||
testJoin("INNER JOIN"); | ||
} | ||
|
||
@Test | ||
public void leftJoin() throws IOException { | ||
|
||
testJoin("LEFT JOIN"); | ||
} | ||
|
||
public void testJoin(final String join) throws IOException { | ||
|
||
final String queryPrefix = "SELECT"; | ||
|
||
// TODO: reduce the balance threshold to 10000 when the memory circuit breaker issue | ||
// (https://github.com/opendistro-for-elasticsearch/sql/issues/73) is fixed. | ||
final String querySuffixTemplate = "a.firstname, a.lastname, b.city, b.state FROM %1$s a %2$s %1$s b " + | ||
"ON b.age = a.age WHERE a.balance > 45000 AND b.age > 25 LIMIT 1000000"; | ||
final String querySuffix = String.format(Locale.ROOT, querySuffixTemplate, TEST_INDEX_ACCOUNT, join); | ||
|
||
final String oldQuery = String.join(" ", queryPrefix, USE_OLD_JOIN_ALGORITHM, querySuffix); | ||
final String newQuery = String.join(" ", queryPrefix, BYPASS_CIRCUIT_BREAK, querySuffix); | ||
|
||
final JSONObject responseOld = executeQuery(oldQuery); | ||
final JSONObject responseNew = executeQuery(newQuery); | ||
|
||
Assert.assertThat(getTotalHits(responseOld), equalTo(getTotalHits(responseNew))); | ||
|
||
final JSONArray hitsOld = getHits(responseOld); | ||
final JSONArray hitsNew = getHits(responseNew); | ||
|
||
Assert.assertThat(hitsOld.length(), equalTo(hitsNew.length())); | ||
|
||
Set<String> idsOld = new HashSet<>(); | ||
|
||
hitsOld.forEach(hitObj -> { | ||
JSONObject hit = (JSONObject) hitObj; | ||
idsOld.add(hit.getString("_id")); | ||
}); | ||
|
||
hitsNew.forEach(hitObj -> { | ||
JSONObject hit = (JSONObject) hitObj; | ||
Assert.assertTrue(idsOld.contains(hit.getString("_id"))); | ||
}); | ||
} | ||
} |
125 changes: 0 additions & 125 deletions
125
src/test/java/com/amazon/opendistroforelasticsearch/sql/intgtest/HashJoinBasicTest.java
This file was deleted.
Oops, something went wrong.
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