Skip to content
This repository has been archived by the owner on Aug 2, 2022. It is now read-only.

Commit

Permalink
Converting HashJoinBasicTest to ESIntegTestCase (#74)
Browse files Browse the repository at this point in the history
*Issue:* #17 

*How tested:* ./gradlew build
  • Loading branch information
arsen-es authored Jun 7, 2019
1 parent 90d77a6 commit 255ad1b
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 126 deletions.
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")));
});
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@
@Suite.SuiteClasses({
QueryTest.class,
AggregationTest.class,
HashJoinBasicTest.class,
HashJoinMoreTest.class,
CSVResultsExtractorTests.class,
MultiQueryTests.class,
Expand Down

0 comments on commit 255ad1b

Please sign in to comment.