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

Commit

Permalink
Fix IT
Browse files Browse the repository at this point in the history
  • Loading branch information
dai-chen committed Dec 15, 2020
1 parent 8895994 commit 9be9000
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ public void noGroupKeyAvgOnIntegerShouldPass() {

@Test
public void hasGroupKeyAvgOnIntegerShouldPass() {
Assume.assumeTrue(isNewQueryEngineEabled());
JSONObject response = executeJdbcRequest(String.format(
"SELECT gender, AVG(age) as avg " +
"FROM %s " +
Expand All @@ -91,7 +92,7 @@ public void hasGroupKeyAvgOnIntegerShouldPass() {

verifySchema(response,
schema("gender", null, "text"),
schema("avg", "avg", "double"));
schema("AVG(age)", "avg", "double"));
verifyDataRows(response,
rows("m", 34.25),
rows("f", 33.666666666666664d));
Expand Down Expand Up @@ -181,6 +182,8 @@ public void AddLiteralOnGroupKeyShouldPass() {

@Test
public void logWithAddLiteralOnGroupKeyShouldPass() {
Assume.assumeTrue(isNewQueryEngineEabled());

JSONObject response = executeJdbcRequest(String.format(
"SELECT gender, Log(age+10) as logAge, max(balance) as max " +
"FROM %s " +
Expand All @@ -191,8 +194,8 @@ public void logWithAddLiteralOnGroupKeyShouldPass() {

verifySchema(response,
schema("gender", null, "text"),
schema("logAge", "logAge", "double"),
schema("max", "max", "long"));
schema("Log(age+10)", "logAge", "double"),
schema("max(balance)", "max", "long"));
verifyDataRows(response,
rows("m", 3.4011973816621555d, 49568),
rows("m", 3.4339872044851463d, 49433));
Expand Down Expand Up @@ -264,7 +267,7 @@ public void aggregateCastStatementShouldNotReturnZero() {
"SELECT SUM(CAST(male AS INT)) AS male_sum FROM %s",
Index.BANK.getName()));

verifySchema(response, schema("male_sum", "male_sum", "integer"));
verifySchema(response, schema("SUM(CAST(male AS INT))", "male_sum", "integer"));
verifyDataRows(response, rows(4));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import org.json.JSONArray;
import org.json.JSONObject;
import org.junit.Assert;
import org.junit.Assume;
import org.junit.Ignore;
import org.junit.Test;

Expand Down Expand Up @@ -470,10 +471,12 @@ public void orderByAscTest() {

@Test
public void orderByAliasAscTest() {
Assume.assumeTrue(isNewQueryEngineEabled());

JSONObject response = executeJdbcRequest(String.format("SELECT COUNT(*) as count FROM %s " +
"GROUP BY gender ORDER BY count", TEST_INDEX_ACCOUNT));

verifySchema(response, schema("count", "count", "integer"));
verifySchema(response, schema("COUNT(*)", "count", "integer"));
verifyDataRowsInOrder(response,
rows(493),
rows(507));
Expand All @@ -492,10 +495,12 @@ public void orderByDescTest() throws IOException {

@Test
public void orderByAliasDescTest() throws IOException {
Assume.assumeTrue(isNewQueryEngineEabled());

JSONObject response = executeJdbcRequest(String.format("SELECT COUNT(*) as count FROM %s " +
"GROUP BY gender ORDER BY count DESC", TEST_INDEX_ACCOUNT));

verifySchema(response, schema("count", "count", "integer"));
verifySchema(response, schema("COUNT(*)", "count", "integer"));
verifyDataRowsInOrder(response,
rows(507),
rows(493));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,8 @@ public void aggregationFunctionInSelectCaseCheck() throws IOException {

@Test
public void aggregationFunctionInSelectWithAlias() throws IOException {
Assume.assumeFalse(isNewQueryEngineEabled());

JSONObject response = executeQuery(
String.format(Locale.ROOT, "SELECT COUNT(*) AS total FROM %s GROUP BY age",
TestsConstants.TEST_INDEX_ACCOUNT));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ public void castIntFieldToFloatWithoutAliasJdbcFormatTest() {
" ORDER BY balance DESC LIMIT 1");

verifySchema(response,
schema("cast_balance", null, "float"));
schema("CAST(balance AS FLOAT)", "cast_balance", "float"));

verifyDataRows(response,
rows(49989.0));
Expand All @@ -242,7 +242,7 @@ public void castIntFieldToFloatWithAliasJdbcFormatTest() {
"FROM " + TestsConstants.TEST_INDEX_ACCOUNT + " ORDER BY jdbc_float_alias LIMIT 1");

verifySchema(response,
schema("jdbc_float_alias", null, "float"));
schema("CAST(balance AS FLOAT)", "jdbc_float_alias", "float"));

verifyDataRows(response,
rows(1011.0));
Expand Down Expand Up @@ -394,10 +394,10 @@ public void castBoolFieldToNumericValueInSelectClause() {

verifySchema(response,
schema("male", "boolean"),
schema("cast_int", "integer"),
schema("cast_long", "long"),
schema("cast_float", "float"),
schema("cast_double", "double")
schema("CAST(male AS INT)", "cast_int", "integer"),
schema("CAST(male AS LONG)", "cast_long", "long"),
schema("CAST(male AS FLOAT)", "cast_float", "float"),
schema("CAST(male AS DOUBLE)", "cast_double", "double")
);
verifyDataRows(response,
rows(true, 1, 1, 1.0, 1.0),
Expand All @@ -419,7 +419,7 @@ public void castBoolFieldToNumericValueWithGroupByAlias() {
);

verifySchema(response,
schema("cast_int", "cast_int", "integer"),
schema("CAST(male AS INT)", "cast_int", "integer"),
schema("COUNT(*)", "integer")
);
verifyDataRows(response,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.amazon.opendistroforelasticsearch.sql.data.model.ExprValue;
import com.amazon.opendistroforelasticsearch.sql.data.model.ExprValueUtils;
import com.amazon.opendistroforelasticsearch.sql.executor.ExecutionEngine;
import com.amazon.opendistroforelasticsearch.sql.executor.ExecutionEngine.Schema.Column;
import java.util.Collection;
import java.util.Iterator;
import java.util.LinkedHashMap;
Expand Down Expand Up @@ -57,7 +58,8 @@ public int size() {
*/
public Map<String, String> columnNameTypes() {
Map<String, String> colNameTypes = new LinkedHashMap<>();
schema.getColumns().forEach(column -> colNameTypes.put(column.getName(),
schema.getColumns().forEach(column -> colNameTypes.put(
getColumnName(column),
column.getExprType().typeName().toLowerCase()));
return colNameTypes;
}
Expand All @@ -72,6 +74,10 @@ public Iterator<Object[]> iterator() {
.iterator();
}

private String getColumnName(Column column) {
return (column.getAlias() != null) ? column.getAlias() : column.getName();
}

private Object[] convertExprValuesToValues(Collection<ExprValue> exprValues) {
return exprValues
.stream()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
class QueryResultTest {

private ExecutionEngine.Schema schema = new ExecutionEngine.Schema(ImmutableList.of(
new ExecutionEngine.Schema.Column("name", "name", STRING),
new ExecutionEngine.Schema.Column("age", "age", INTEGER)));
new ExecutionEngine.Schema.Column("name", "n", STRING),
new ExecutionEngine.Schema.Column("age", null, INTEGER)));


@Test
Expand All @@ -58,7 +58,7 @@ void columnNameTypes() {
));

assertEquals(
ImmutableMap.of("name", "string", "age", "integer"),
ImmutableMap.of("n", "string", "age", "integer"),
response.columnNameTypes()
);
}
Expand All @@ -69,7 +69,7 @@ void columnNameTypesFromEmptyExprValues() {
schema,
Collections.emptyList());
assertEquals(
ImmutableMap.of("name", "string", "age", "integer"),
ImmutableMap.of("n", "string", "age", "integer"),
response.columnNameTypes()
);
}
Expand All @@ -84,7 +84,7 @@ void columnNameTypesFromExprValuesWithMissing() {
));

assertEquals(
ImmutableMap.of("name", "string", "age", "integer"),
ImmutableMap.of("n", "string", "age", "integer"),
response.columnNameTypes()
);
}
Expand Down

0 comments on commit 9be9000

Please sign in to comment.