diff --git a/core/src/main/java/org/opensearch/sql/expression/aggregation/AggregatorFunctions.java b/core/src/main/java/org/opensearch/sql/expression/aggregation/AggregatorFunctions.java index fa48e5c3956..59c8c66e7c3 100644 --- a/core/src/main/java/org/opensearch/sql/expression/aggregation/AggregatorFunctions.java +++ b/core/src/main/java/org/opensearch/sql/expression/aggregation/AggregatorFunctions.java @@ -96,7 +96,7 @@ private static DefaultFunctionResolver count() { new FunctionSignature(functionName, Collections.singletonList(type)), type -> (functionProperties, arguments) -> - new CountAggregator(arguments, INTEGER)))); + new CountAggregator(arguments, LONG)))); return functionResolver; } diff --git a/core/src/main/java/org/opensearch/sql/expression/aggregation/CountAggregator.java b/core/src/main/java/org/opensearch/sql/expression/aggregation/CountAggregator.java index c4c02eb1d3e..09babdb00b0 100644 --- a/core/src/main/java/org/opensearch/sql/expression/aggregation/CountAggregator.java +++ b/core/src/main/java/org/opensearch/sql/expression/aggregation/CountAggregator.java @@ -44,7 +44,7 @@ public String toString() { /** Count State. */ protected static class CountState implements AggregationState { - protected int count; + protected long count; CountState() { this.count = 0; @@ -56,7 +56,7 @@ public void count(ExprValue value) { @Override public ExprValue result() { - return ExprValueUtils.integerValue(count); + return ExprValueUtils.longValue(count); } } diff --git a/core/src/test/java/org/opensearch/sql/analysis/AnalyzerTest.java b/core/src/test/java/org/opensearch/sql/analysis/AnalyzerTest.java index 5930df74ee5..6324e7ee5bd 100644 --- a/core/src/test/java/org/opensearch/sql/analysis/AnalyzerTest.java +++ b/core/src/test/java/org/opensearch/sql/analysis/AnalyzerTest.java @@ -1283,7 +1283,7 @@ public void named_aggregator_with_condition() { emptyList()), DSL.named( "count(string_value) filter(where integer_value > 1)", - DSL.ref("count(string_value) filter(where integer_value > 1)", INTEGER))), + DSL.ref("count(string_value) filter(where integer_value > 1)", LONG))), AstDSL.project( AstDSL.agg( AstDSL.relation("schema"), diff --git a/core/src/test/java/org/opensearch/sql/expression/aggregation/CountAggregatorTest.java b/core/src/test/java/org/opensearch/sql/expression/aggregation/CountAggregatorTest.java index 50bd3fedfea..115abff5af4 100644 --- a/core/src/test/java/org/opensearch/sql/expression/aggregation/CountAggregatorTest.java +++ b/core/src/test/java/org/opensearch/sql/expression/aggregation/CountAggregatorTest.java @@ -30,43 +30,43 @@ class CountAggregatorTest extends AggregationTest { @Test public void count_integer_field_expression() { ExprValue result = aggregation(DSL.count(DSL.ref("integer_value", INTEGER)), tuples); - assertEquals(4, result.value()); + assertEquals(4L, result.value()); } @Test public void count_long_field_expression() { ExprValue result = aggregation(DSL.count(DSL.ref("long_value", LONG)), tuples); - assertEquals(4, result.value()); + assertEquals(4L, result.value()); } @Test public void count_float_field_expression() { ExprValue result = aggregation(DSL.count(DSL.ref("float_value", FLOAT)), tuples); - assertEquals(4, result.value()); + assertEquals(4L, result.value()); } @Test public void count_double_field_expression() { ExprValue result = aggregation(DSL.count(DSL.ref("double_value", DOUBLE)), tuples); - assertEquals(4, result.value()); + assertEquals(4L, result.value()); } @Test public void count_date_field_expression() { ExprValue result = aggregation(DSL.count(DSL.ref("date_value", DATE)), tuples); - assertEquals(4, result.value()); + assertEquals(4L, result.value()); } @Test public void count_timestamp_field_expression() { ExprValue result = aggregation(DSL.count(DSL.ref("timestamp_value", TIMESTAMP)), tuples); - assertEquals(4, result.value()); + assertEquals(4L, result.value()); } @Test public void count_datetime_field_expression() { ExprValue result = aggregation(DSL.count(DSL.ref("datetime_value", DATETIME)), tuples); - assertEquals(4, result.value()); + assertEquals(4L, result.value()); } @Test @@ -75,34 +75,33 @@ public void count_arithmetic_expression() { aggregation( DSL.count( DSL.multiply( - DSL.ref("integer_value", INTEGER), - DSL.literal(ExprValueUtils.integerValue(10)))), + DSL.ref("long_value", LONG), DSL.literal(ExprValueUtils.longValue(10L)))), tuples); - assertEquals(4, result.value()); + assertEquals(4L, result.value()); } @Test public void count_string_field_expression() { ExprValue result = aggregation(DSL.count(DSL.ref("string_value", STRING)), tuples); - assertEquals(4, result.value()); + assertEquals(4L, result.value()); } @Test public void count_boolean_field_expression() { ExprValue result = aggregation(DSL.count(DSL.ref("boolean_value", BOOLEAN)), tuples); - assertEquals(1, result.value()); + assertEquals(1L, result.value()); } @Test public void count_struct_field_expression() { ExprValue result = aggregation(DSL.count(DSL.ref("struct_value", STRUCT)), tuples); - assertEquals(1, result.value()); + assertEquals(1L, result.value()); } @Test public void count_array_field_expression() { ExprValue result = aggregation(DSL.count(DSL.ref("array_value", ARRAY)), tuples); - assertEquals(1, result.value()); + assertEquals(1L, result.value()); } @Test @@ -112,14 +111,14 @@ public void filtered_count() { DSL.count(DSL.ref("integer_value", INTEGER)) .condition(DSL.greater(DSL.ref("integer_value", INTEGER), DSL.literal(1))), tuples); - assertEquals(3, result.value()); + assertEquals(3L, result.value()); } @Test public void distinct_count() { ExprValue result = aggregation(DSL.distinctCount(DSL.ref("integer_value", INTEGER)), tuples_with_duplicates); - assertEquals(3, result.value()); + assertEquals(3L, result.value()); } @Test @@ -129,47 +128,47 @@ public void filtered_distinct_count() { DSL.distinctCount(DSL.ref("integer_value", INTEGER)) .condition(DSL.greater(DSL.ref("double_value", DOUBLE), DSL.literal(1d))), tuples_with_duplicates); - assertEquals(2, result.value()); + assertEquals(2L, result.value()); } @Test public void distinct_count_map() { ExprValue result = aggregation(DSL.distinctCount(DSL.ref("struct_value", STRUCT)), tuples_with_duplicates); - assertEquals(3, result.value()); + assertEquals(3L, result.value()); } @Test public void distinct_count_array() { ExprValue result = aggregation(DSL.distinctCount(DSL.ref("array_value", ARRAY)), tuples_with_duplicates); - assertEquals(3, result.value()); + assertEquals(3L, result.value()); } @Test public void count_with_missing() { ExprValue result = aggregation(DSL.count(DSL.ref("integer_value", INTEGER)), tuples_with_null_and_missing); - assertEquals(2, result.value()); + assertEquals(2L, result.value()); } @Test public void count_with_null() { ExprValue result = aggregation(DSL.count(DSL.ref("double_value", DOUBLE)), tuples_with_null_and_missing); - assertEquals(2, result.value()); + assertEquals(2L, result.value()); } @Test public void count_star_with_null_and_missing() { ExprValue result = aggregation(DSL.count(DSL.literal("*")), tuples_with_null_and_missing); - assertEquals(3, result.value()); + assertEquals(3L, result.value()); } @Test public void count_literal_with_null_and_missing() { ExprValue result = aggregation(DSL.count(DSL.literal(1)), tuples_with_null_and_missing); - assertEquals(3, result.value()); + assertEquals(3L, result.value()); } @Test diff --git a/integ-test/src/test/java/org/opensearch/sql/bwc/SQLBackwardsCompatibilityIT.java b/integ-test/src/test/java/org/opensearch/sql/bwc/SQLBackwardsCompatibilityIT.java index 21193a01413..f8255fc0f08 100644 --- a/integ-test/src/test/java/org/opensearch/sql/bwc/SQLBackwardsCompatibilityIT.java +++ b/integ-test/src/test/java/org/opensearch/sql/bwc/SQLBackwardsCompatibilityIT.java @@ -175,13 +175,21 @@ private void verifySQLQueries(String endpoint) throws IOException { executeSQLQuery( endpoint, "SELECT COUNT(*) FILTER(WHERE age > 35) FROM " + TestsConstants.TEST_INDEX_ACCOUNT); - verifySchema(filterResponse, schema("COUNT(*) FILTER(WHERE age > 35)", null, "integer")); + // Accept both integer and long types for backwards compatibility + String actualType = + (String) filterResponse.getJSONArray("schema").getJSONObject(0).query("/type"); + String expectedType = actualType.equals("integer") ? "integer" : "long"; + verifySchema(filterResponse, schema("COUNT(*) FILTER(WHERE age > 35)", null, expectedType)); verifyDataRows(filterResponse, rows(238)); JSONObject aggResponse = executeSQLQuery( endpoint, "SELECT COUNT(DISTINCT age) FROM " + TestsConstants.TEST_INDEX_ACCOUNT); - verifySchema(aggResponse, schema("COUNT(DISTINCT age)", null, "integer")); + // Accept both integer and long types for backwards compatibility + String actualType2 = + (String) aggResponse.getJSONArray("schema").getJSONObject(0).query("/type"); + String expectedType2 = actualType2.equals("integer") ? "integer" : "long"; + verifySchema(aggResponse, schema("COUNT(DISTINCT age)", null, expectedType2)); verifyDataRows(aggResponse, rows(21)); JSONObject groupByResponse = diff --git a/integ-test/src/test/java/org/opensearch/sql/correctness/runner/resultset/DBResult.java b/integ-test/src/test/java/org/opensearch/sql/correctness/runner/resultset/DBResult.java index e3940bc5392..bc76cc9eeb1 100644 --- a/integ-test/src/test/java/org/opensearch/sql/correctness/runner/resultset/DBResult.java +++ b/integ-test/src/test/java/org/opensearch/sql/correctness/runner/resultset/DBResult.java @@ -34,6 +34,12 @@ public class DBResult { /** Possible types for varchar. H2 2.x use CHARACTER VARYING instead of VARCHAR. */ private static final Set VARCHAR = ImmutableSet.of("CHARACTER VARYING", "VARCHAR"); + /** + * Possible types for integer numbers.
+ * Different databases may return INTEGER or BIGINT for count operations. + */ + private static final Set INTEGER_TYPES = ImmutableSet.of("INTEGER", "BIGINT"); + /** Database name for display */ private final String databaseName; @@ -74,6 +80,8 @@ public void addColumn(String name, String type) { type = FLOAT_TYPES.toString(); } else if (VARCHAR.contains(type)) { type = "VARCHAR"; + } else if (INTEGER_TYPES.contains(type)) { + type = INTEGER_TYPES.toString(); } schema.add(new Type(StringUtils.toUpper(name), type)); } diff --git a/integ-test/src/test/java/org/opensearch/sql/correctness/runner/resultset/Row.java b/integ-test/src/test/java/org/opensearch/sql/correctness/runner/resultset/Row.java index 973ea76e712..471e9ea4666 100644 --- a/integ-test/src/test/java/org/opensearch/sql/correctness/runner/resultset/Row.java +++ b/integ-test/src/test/java/org/opensearch/sql/correctness/runner/resultset/Row.java @@ -10,12 +10,11 @@ import java.util.ArrayList; import java.util.Collection; import java.util.List; -import lombok.EqualsAndHashCode; +import java.util.Objects; import lombok.Getter; import lombok.ToString; /** Row in result set. */ -@EqualsAndHashCode @ToString @Getter public class Row implements Comparable { @@ -23,7 +22,7 @@ public class Row implements Comparable { private final Collection values; public Row() { - this(new ArrayList<>()); // values in order by default + this(new ArrayList<>()); } public Row(Collection values) { @@ -37,7 +36,7 @@ public void add(Object value) { private Object roundFloatNum(Object value) { if (value instanceof Float) { BigDecimal decimal = BigDecimal.valueOf((Float) value).setScale(2, RoundingMode.CEILING); - value = decimal.doubleValue(); // Convert to double too + value = decimal.doubleValue(); } else if (value instanceof Double) { BigDecimal decimal = BigDecimal.valueOf((Double) value).setScale(2, RoundingMode.CEILING); value = decimal.doubleValue(); @@ -70,8 +69,54 @@ public int compareTo(Row other) { if (result != 0) { return result; } - } // Ignore incomparable field silently? + } } return 0; } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof Row)) return false; + Row other = (Row) o; + return valuesEqual(this.values, other.values); + } + + private boolean valuesEqual(Collection values1, Collection values2) { + if (values1.size() != values2.size()) return false; + + List list1 = new ArrayList<>(values1); + List list2 = new ArrayList<>(values2); + + for (int i = 0; i < list1.size(); i++) { + if (!isValueEqual(list1.get(i), list2.get(i))) { + return false; + } + } + return true; + } + + private boolean isValueEqual(Object val1, Object val2) { + if (Objects.equals(val1, val2)) return true; + + if (isIntegerOrLong(val1) && isIntegerOrLong(val2)) { + return ((Number) val1).longValue() == ((Number) val2).longValue(); + } + + return false; + } + + private boolean isIntegerOrLong(Object value) { + return value instanceof Integer || value instanceof Long; + } + + @Override + public int hashCode() { + + List normalizedValues = new ArrayList<>(); + for (Object value : values) { + normalizedValues.add(value instanceof Integer ? ((Integer) value).longValue() : value); + } + return normalizedValues.hashCode(); + } } diff --git a/integ-test/src/test/java/org/opensearch/sql/legacy/AggregationExpressionIT.java b/integ-test/src/test/java/org/opensearch/sql/legacy/AggregationExpressionIT.java index 9f6a08c76ae..a55e6b78b87 100644 --- a/integ-test/src/test/java/org/opensearch/sql/legacy/AggregationExpressionIT.java +++ b/integ-test/src/test/java/org/opensearch/sql/legacy/AggregationExpressionIT.java @@ -204,7 +204,7 @@ public void groupByDateShouldPass() { Index.BANK.getName())); verifySchema( - response, schema("birthdate", null, "timestamp"), schema("count(*)", "count", "integer")); + response, schema("birthdate", null, "timestamp"), schema("count(*)", "count", "long")); verifyDataRows(response, rows("2018-06-23 00:00:00", 1)); } @@ -220,9 +220,7 @@ public void groupByDateWithAliasShouldPass() { Index.BANK.getName())); verifySchema( - response, - schema("birthdate", "birth", "timestamp"), - schema("count(*)", "count", "integer")); + response, schema("birthdate", "birth", "timestamp"), schema("count(*)", "count", "long")); verifyDataRows(response, rows("2018-06-23 00:00:00", 1)); } diff --git a/integ-test/src/test/java/org/opensearch/sql/legacy/AggregationIT.java b/integ-test/src/test/java/org/opensearch/sql/legacy/AggregationIT.java index 803379a50ea..05dc769c9bb 100644 --- a/integ-test/src/test/java/org/opensearch/sql/legacy/AggregationIT.java +++ b/integ-test/src/test/java/org/opensearch/sql/legacy/AggregationIT.java @@ -492,7 +492,7 @@ public void orderByAscTest() { "SELECT COUNT(*) FROM %s " + "GROUP BY gender ORDER BY COUNT(*)", TEST_INDEX_ACCOUNT)); - verifySchema(response, schema("COUNT(*)", null, "integer")); + verifySchema(response, schema("COUNT(*)", null, "long")); verifyDataRows(response, rows(493), rows(507)); } @@ -504,7 +504,7 @@ public void orderByAliasAscTest() { "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", "long")); verifyDataRowsInOrder(response, rows(493), rows(507)); } @@ -516,7 +516,7 @@ public void orderByDescTest() throws IOException { "SELECT COUNT(*) FROM %s " + "GROUP BY gender ORDER BY COUNT(*) DESC", TEST_INDEX_ACCOUNT)); - verifySchema(response, schema("COUNT(*)", null, "integer")); + verifySchema(response, schema("COUNT(*)", null, "long")); verifyDataRowsInOrder(response, rows(507), rows(493)); } @@ -528,7 +528,7 @@ public void orderByAliasDescTest() throws IOException { "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", "long")); verifyDataRowsInOrder(response, rows(507), rows(493)); } @@ -542,7 +542,7 @@ public void orderByGroupFieldWithAlias() throws IOException { + "FROM %s GROUP BY gender ORDER BY gender", TEST_INDEX_ACCOUNT)); - verifySchema(response, schema("gender", "g", "text"), schema("COUNT(*)", "count", "integer")); + verifySchema(response, schema("gender", "g", "text"), schema("COUNT(*)", "count", "long")); verifyDataRowsInOrder(response, rows("F", 493), rows("M", 507)); // ORDER BY field alias @@ -552,7 +552,7 @@ public void orderByGroupFieldWithAlias() throws IOException { "SELECT gender as g, COUNT(*) as count " + "FROM %s GROUP BY gender ORDER BY g", TEST_INDEX_ACCOUNT)); - verifySchema(response, schema("gender", "g", "text"), schema("COUNT(*)", "count", "integer")); + verifySchema(response, schema("gender", "g", "text"), schema("COUNT(*)", "count", "long")); verifyDataRowsInOrder(response, rows("F", 493), rows("M", 507)); } @@ -564,7 +564,7 @@ public void limitTest() throws IOException { "SELECT COUNT(*) FROM %s " + "GROUP BY age ORDER BY COUNT(*) LIMIT 5", TEST_INDEX_ACCOUNT)); - verifySchema(response, schema("COUNT(*)", null, "integer")); + verifySchema(response, schema("COUNT(*)", null, "long")); verifyDataRowsInOrder(response, rows(35), rows(39), rows(39), rows(42), rows(42)); } diff --git a/integ-test/src/test/java/org/opensearch/sql/legacy/SQLFunctionsIT.java b/integ-test/src/test/java/org/opensearch/sql/legacy/SQLFunctionsIT.java index 877f803189f..f7e0eef33a5 100644 --- a/integ-test/src/test/java/org/opensearch/sql/legacy/SQLFunctionsIT.java +++ b/integ-test/src/test/java/org/opensearch/sql/legacy/SQLFunctionsIT.java @@ -405,7 +405,7 @@ public void castBoolFieldToNumericValueWithGroupByAlias() { verifySchema( response, schema("CAST(male AS INT)", "cast_int", "integer"), - schema("COUNT(*)", "integer")); + schema("COUNT(*)", "long")); verifyDataRows(response, rows(0, 3), rows(1, 4)); } diff --git a/integ-test/src/test/java/org/opensearch/sql/ppl/DateTimeImplementationIT.java b/integ-test/src/test/java/org/opensearch/sql/ppl/DateTimeImplementationIT.java index 2317ad0c6fc..a81140fe9cf 100644 --- a/integ-test/src/test/java/org/opensearch/sql/ppl/DateTimeImplementationIT.java +++ b/integ-test/src/test/java/org/opensearch/sql/ppl/DateTimeImplementationIT.java @@ -189,10 +189,7 @@ public void testSpanDatetimeWithCustomFormat() throws IOException { String.format( "source=%s | eval a = 1 | stats count() as cnt by span(yyyy-MM-dd, 1d) as span", TEST_INDEX_DATE_FORMATS)); - verifySchema( - result, - isCalciteEnabled() ? schema("cnt", null, "bigint") : schema("cnt", null, "int"), - schema("span", null, "date")); + verifySchema(result, schema("cnt", null, "bigint"), schema("span", null, "date")); verifyDataRows(result, rows(2, "1984-04-12")); } @@ -203,10 +200,7 @@ public void testSpanDatetimeWithEpochMillisFormat() throws IOException { String.format( "source=%s | eval a = 1 | stats count() as cnt by span(epoch_millis, 1d) as span", TEST_INDEX_DATE_FORMATS)); - verifySchema( - result, - isCalciteEnabled() ? schema("cnt", null, "bigint") : schema("cnt", null, "int"), - schema("span", null, "timestamp")); + verifySchema(result, schema("cnt", null, "bigint"), schema("span", null, "timestamp")); verifyDataRows(result, rows(2, "1984-04-12 00:00:00")); } @@ -218,10 +212,7 @@ public void testSpanDatetimeWithDisjunctiveDifferentFormats() throws IOException "source=%s | eval a = 1 | stats count() as cnt by span(yyyy-MM-dd_OR_epoch_millis," + " 1d) as span", TEST_INDEX_DATE_FORMATS)); - verifySchema( - result, - isCalciteEnabled() ? schema("cnt", null, "bigint") : schema("cnt", null, "int"), - schema("span", null, "timestamp")); + verifySchema(result, schema("cnt", null, "bigint"), schema("span", null, "timestamp")); verifyDataRows(result, rows(2, "1984-04-12 00:00:00")); } } diff --git a/integ-test/src/test/java/org/opensearch/sql/ppl/ObjectFieldOperateIT.java b/integ-test/src/test/java/org/opensearch/sql/ppl/ObjectFieldOperateIT.java index 725fd318f99..898ab173e62 100644 --- a/integ-test/src/test/java/org/opensearch/sql/ppl/ObjectFieldOperateIT.java +++ b/integ-test/src/test/java/org/opensearch/sql/ppl/ObjectFieldOperateIT.java @@ -53,10 +53,7 @@ public void group_object_field_in_stats() throws IOException { JSONObject result = executeQuery( String.format("source=%s | stats count() by city.name", TEST_INDEX_DEEP_NESTED)); - verifySchema( - result, - schema("count()", isCalciteEnabled() ? "bigint" : "int"), - schema("city.name", "string")); + verifySchema(result, schema("count()", "bigint"), schema("city.name", "string")); verifyDataRows(result, rows(1, "Seattle")); } diff --git a/integ-test/src/test/java/org/opensearch/sql/ppl/PrometheusDataSourceCommandsIT.java b/integ-test/src/test/java/org/opensearch/sql/ppl/PrometheusDataSourceCommandsIT.java index fa5bacf716f..28149d776ca 100644 --- a/integ-test/src/test/java/org/opensearch/sql/ppl/PrometheusDataSourceCommandsIT.java +++ b/integ-test/src/test/java/org/opensearch/sql/ppl/PrometheusDataSourceCommandsIT.java @@ -209,7 +209,7 @@ public void testMetricCountAggregationCommand() { + " span(@timestamp, 15s), handler, job"); verifySchema( response, - schema("count()", "int"), + schema("count()", "bigint"), schema("span(@timestamp,15s)", "timestamp"), schema("handler", "string"), schema("job", "string")); diff --git a/integ-test/src/test/java/org/opensearch/sql/ppl/StatsCommandIT.java b/integ-test/src/test/java/org/opensearch/sql/ppl/StatsCommandIT.java index 5529c4ce346..de679b0c0ea 100644 --- a/integ-test/src/test/java/org/opensearch/sql/ppl/StatsCommandIT.java +++ b/integ-test/src/test/java/org/opensearch/sql/ppl/StatsCommandIT.java @@ -73,11 +73,9 @@ public void testStatsSumWithEnhancement() throws IOException { public void testStatsCount() throws IOException { JSONObject response = executeQuery(String.format("source=%s | stats count(account_number)", TEST_INDEX_ACCOUNT)); - if (isCalciteEnabled()) { - verifySchema(response, schema("count(account_number)", null, "bigint")); - } else { - verifySchema(response, schema("count(account_number)", null, "int")); - } + + verifySchema(response, schema("count(account_number)", null, "bigint")); + verifyDataRows(response, rows(1000)); } @@ -85,35 +83,22 @@ public void testStatsCount() throws IOException { public void testStatsCountAll() throws IOException { JSONObject response = executeQuery(String.format("source=%s | stats count()", TEST_INDEX_ACCOUNT)); - if (isCalciteEnabled()) { - verifySchema(response, schema("count()", null, "bigint")); - } else { - verifySchema(response, schema("count()", null, "int")); - } + + verifySchema(response, schema("count()", null, "bigint")); verifyDataRows(response, rows(1000)); response = executeQuery(String.format("source=%s | stats c()", TEST_INDEX_ACCOUNT)); - if (isCalciteEnabled()) { - verifySchema(response, schema("c()", null, "bigint")); - } else { - verifySchema(response, schema("c()", null, "int")); - } + + verifySchema(response, schema("c()", null, "bigint")); verifyDataRows(response, rows(1000)); response = executeQuery(String.format("source=%s | stats count", TEST_INDEX_ACCOUNT)); - if (isCalciteEnabled()) { - verifySchema(response, schema("count", null, "bigint")); - } else { - verifySchema(response, schema("count", null, "int")); - } + verifySchema(response, schema("count", null, "bigint")); verifyDataRows(response, rows(1000)); response = executeQuery(String.format("source=%s | stats c", TEST_INDEX_ACCOUNT)); - if (isCalciteEnabled()) { - verifySchema(response, schema("c", null, "bigint")); - } else { - verifySchema(response, schema("c", null, "int")); - } + + verifySchema(response, schema("c", null, "bigint")); verifyDataRows(response, rows(1000)); } @@ -121,11 +106,7 @@ public void testStatsCountAll() throws IOException { public void testStatsCBy() throws IOException { JSONObject response = executeQuery(String.format("source=%s | stats c by gender", TEST_INDEX_ACCOUNT)); - if (isCalciteEnabled()) { - verifySchema(response, schema("c", null, "bigint"), schema("gender", null, "string")); - } else { - verifySchema(response, schema("c", null, "int"), schema("gender", null, "string")); - } + verifySchema(response, schema("c", null, "bigint"), schema("gender", null, "string")); verifyDataRows(response, rows(493, "F"), rows(507, "M")); } @@ -133,19 +114,11 @@ public void testStatsCBy() throws IOException { public void testStatsDistinctCount() throws IOException { JSONObject response = executeQuery(String.format("source=%s | stats distinct_count(gender)", TEST_INDEX_ACCOUNT)); - if (isCalciteEnabled()) { - verifySchema(response, schema("distinct_count(gender)", null, "bigint")); - } else { - verifySchema(response, schema("distinct_count(gender)", null, "int")); - } + verifySchema(response, schema("distinct_count(gender)", null, "bigint")); verifyDataRows(response, rows(2)); response = executeQuery(String.format("source=%s | stats dc(age)", TEST_INDEX_ACCOUNT)); - if (isCalciteEnabled()) { - verifySchema(response, schema("dc(age)", null, "bigint")); - } else { - verifySchema(response, schema("dc(age)", null, "int")); - } + verifySchema(response, schema("dc(age)", null, "bigint")); verifyDataRows(response, rows(21)); } @@ -552,10 +525,7 @@ public void testStatsWithMissing() throws IOException { public void testStatsBySpan() throws IOException { JSONObject response = executeQuery(String.format("source=%s | stats count() by span(age,10)", TEST_INDEX_BANK)); - verifySchema( - response, - isCalciteEnabled() ? schema("count()", null, "bigint") : schema("count()", null, "int"), - schema("span(age,10)", null, "int")); + verifySchema(response, schema("count()", null, "bigint"), schema("span(age,10)", null, "int")); verifyDataRows(response, rows(1, 20), rows(6, 30)); } @@ -566,7 +536,7 @@ public void testStatsTimeSpan() throws IOException { String.format("source=%s | stats count() by span(birthdate,1y)", TEST_INDEX_BANK)); verifySchema( response, - isCalciteEnabled() ? schema("count()", null, "bigint") : schema("count()", null, "int"), + schema("count()", null, "bigint"), schema("span(birthdate,1y)", null, "timestamp")); verifyDataRows(response, rows(2, "2017-01-01 00:00:00"), rows(5, "2018-01-01 00:00:00")); } @@ -577,11 +547,8 @@ public void testStatsAliasedSpan() throws IOException { executeQuery( String.format( "source=%s | stats count() by span(age,10) as age_bucket", TEST_INDEX_BANK)); - if (isCalciteEnabled()) { - verifySchema(response, schema("count()", null, "bigint"), schema("age_bucket", null, "int")); - } else { - verifySchema(response, schema("count()", null, "int"), schema("age_bucket", null, "int")); - } + + verifySchema(response, schema("count()", null, "bigint"), schema("age_bucket", null, "int")); verifyDataRows(response, rows(1, 20), rows(6, 30)); } @@ -593,7 +560,7 @@ public void testStatsBySpanAndMultipleFields() throws IOException { "source=%s | stats count() by span(age,10), gender, state", TEST_INDEX_BANK)); verifySchemaInOrder( response, - isCalciteEnabled() ? schema("count()", null, "bigint") : schema("count()", null, "int"), + schema("count()", null, "bigint"), schema("span(age,10)", null, "int"), schema("gender", null, "string"), schema("state", null, "string")); @@ -618,7 +585,7 @@ public void testStatsByMultipleFieldsAndSpan() throws IOException { "source=%s | stats count() by gender, state, span(age,10)", TEST_INDEX_BANK)); verifySchemaInOrder( response, - isCalciteEnabled() ? schema("count()", null, "bigint") : schema("count()", null, "int"), + schema("count()", null, "bigint"), schema("span(age,10)", null, "int"), schema("gender", null, "string"), schema("state", null, "string")); @@ -796,13 +763,13 @@ public void testStatsByCounts() throws IOException { TEST_INDEX_ACCOUNT)); verifySchema( response, - schema("count()", null, isCalciteEnabled() ? "bigint" : "int"), - schema("c1", null, isCalciteEnabled() ? "bigint" : "int"), - schema("count(account_number)", null, isCalciteEnabled() ? "bigint" : "int"), - schema("c2", null, isCalciteEnabled() ? "bigint" : "int"), - schema("count(balance/10)", null, isCalciteEnabled() ? "bigint" : "int"), - schema("c3", null, isCalciteEnabled() ? "bigint" : "int"), - schema("count(b_1)", null, isCalciteEnabled() ? "bigint" : "int"), + schema("count()", null, "bigint"), + schema("c1", null, "bigint"), + schema("count(account_number)", null, "bigint"), + schema("c2", null, "bigint"), + schema("count(balance/10)", null, "bigint"), + schema("c3", null, "bigint"), + schema("count(b_1)", null, "bigint"), schema("gender", null, "string")); verifyDataRows( response, diff --git a/integ-test/src/test/java/org/opensearch/sql/sql/AggregationIT.java b/integ-test/src/test/java/org/opensearch/sql/sql/AggregationIT.java index 1118dd4cd64..e54b7dc768f 100644 --- a/integ-test/src/test/java/org/opensearch/sql/sql/AggregationIT.java +++ b/integ-test/src/test/java/org/opensearch/sql/sql/AggregationIT.java @@ -37,7 +37,7 @@ protected void init() throws Exception { public void testFilteredAggregatePushDown() throws IOException { JSONObject response = executeQuery("SELECT COUNT(*) FILTER(WHERE age > 35) FROM " + TEST_INDEX_BANK); - verifySchema(response, schema("COUNT(*) FILTER(WHERE age > 35)", null, "integer")); + verifySchema(response, schema("COUNT(*) FILTER(WHERE age > 35)", null, "long")); verifyDataRows(response, rows(3)); } @@ -48,7 +48,7 @@ public void testFilteredAggregateNotPushDown() throws IOException { "SELECT COUNT(*) FILTER(WHERE age > 35) FROM (SELECT * FROM " + TEST_INDEX_BANK + ") AS a"); - verifySchema(response, schema("COUNT(*) FILTER(WHERE age > 35)", null, "integer")); + verifySchema(response, schema("COUNT(*) FILTER(WHERE age > 35)", null, "long")); verifyDataRows(response, rows(3)); } diff --git a/integ-test/src/test/java/org/opensearch/sql/sql/DateTimeFormatsIT.java b/integ-test/src/test/java/org/opensearch/sql/sql/DateTimeFormatsIT.java index 13c2eecd563..a24775a9755 100644 --- a/integ-test/src/test/java/org/opensearch/sql/sql/DateTimeFormatsIT.java +++ b/integ-test/src/test/java/org/opensearch/sql/sql/DateTimeFormatsIT.java @@ -215,7 +215,7 @@ public void testDateNanosGroupBy() { "SELECT count(*)" + " FROM %s GROUP BY hour_minute_second_OR_t_time", TEST_INDEX_DATE_FORMATS); JSONObject result = executeQuery(query); - verifySchema(result, schema("count(*)", null, "integer")); + verifySchema(result, schema("count(*)", null, "long")); verifyDataRows(result, rows(1), rows(1)); }