This is an automated email from the ASF dual-hosted git repository.
yashmayya pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/pinot.git
The following commit(s) were added to refs/heads/master by this push:
new 616d6917a8 Fix broken BIG_DECIMAL aggregations (MIN / MAX / SUM / AVG)
in the multi-stage query engine (#14689)
616d6917a8 is described below
commit 616d6917a8295b9cb61c6b98d18744b61ce48c24
Author: Yash Mayya <[email protected]>
AuthorDate: Sat Dec 21 19:33:11 2024 +0700
Fix broken BIG_DECIMAL aggregations (MIN / MAX / SUM / AVG) in the
multi-stage query engine (#14689)
---
.../tests/MultiStageEngineIntegrationTest.java | 9 +++++++++
.../query/runtime/operator/utils/TypeUtils.java | 3 +++
.../src/test/resources/queries/Aggregates.json | 22 ++++++++++++++--------
3 files changed, 26 insertions(+), 8 deletions(-)
diff --git
a/pinot-integration-tests/src/test/java/org/apache/pinot/integration/tests/MultiStageEngineIntegrationTest.java
b/pinot-integration-tests/src/test/java/org/apache/pinot/integration/tests/MultiStageEngineIntegrationTest.java
index 2fa71d0718..74a477364e 100644
---
a/pinot-integration-tests/src/test/java/org/apache/pinot/integration/tests/MultiStageEngineIntegrationTest.java
+++
b/pinot-integration-tests/src/test/java/org/apache/pinot/integration/tests/MultiStageEngineIntegrationTest.java
@@ -1159,6 +1159,15 @@ public class MultiStageEngineIntegrationTest extends
BaseClusterIntegrationTestS
assertNoError(jsonNode);
}
+ @Test
+ public void testBigDecimalAggregations()
+ throws Exception {
+ String query =
+ "SELECT MIN(CAST(ArrTime AS DECIMAL)), MAX(CAST(ArrTime AS DECIMAL)),
SUM(CAST(ArrTime AS DECIMAL)), AVG(CAST"
+ + "(ArrTime AS DECIMAL)) FROM mytable";
+ testQuery(query);
+ }
+
@Override
protected String getTableName() {
return _tableName;
diff --git
a/pinot-query-runtime/src/main/java/org/apache/pinot/query/runtime/operator/utils/TypeUtils.java
b/pinot-query-runtime/src/main/java/org/apache/pinot/query/runtime/operator/utils/TypeUtils.java
index 80841b8554..336c733d56 100644
---
a/pinot-query-runtime/src/main/java/org/apache/pinot/query/runtime/operator/utils/TypeUtils.java
+++
b/pinot-query-runtime/src/main/java/org/apache/pinot/query/runtime/operator/utils/TypeUtils.java
@@ -23,6 +23,7 @@ import it.unimi.dsi.fastutil.floats.FloatArrayList;
import it.unimi.dsi.fastutil.ints.IntArrayList;
import it.unimi.dsi.fastutil.longs.LongArrayList;
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
+import java.math.BigDecimal;
import org.apache.pinot.common.utils.ArrayListUtils;
import org.apache.pinot.common.utils.DataSchema.ColumnDataType;
@@ -46,6 +47,8 @@ public class TypeUtils {
return ((Number) value).floatValue();
case DOUBLE:
return ((Number) value).doubleValue();
+ case BIG_DECIMAL:
+ return value instanceof BigDecimal ? value :
BigDecimal.valueOf(((Number) value).doubleValue());
// For AggregationFunctions that return serialized custom object, e.g.
DistinctCountRawHLLAggregationFunction
case STRING:
return value.toString();
diff --git a/pinot-query-runtime/src/test/resources/queries/Aggregates.json
b/pinot-query-runtime/src/test/resources/queries/Aggregates.json
index 1e4d6166b0..089614b17a 100644
--- a/pinot-query-runtime/src/test/resources/queries/Aggregates.json
+++ b/pinot-query-runtime/src/test/resources/queries/Aggregates.json
@@ -6,16 +6,17 @@
{"name": "int_col", "type": "INT"},
{"name": "double_col", "type": "DOUBLE"},
{"name": "string_col", "type": "STRING"},
- {"name": "bool_col", "type": "BOOLEAN"}
+ {"name": "bool_col", "type": "BOOLEAN"},
+ {"name": "big_decimal_col", "type": "BIG_DECIMAL"}
],
"inputs": [
- [2, 300, "a", true],
- [2, 400, "a", true],
- [3, 100, "b", false],
- [100, 1, "b", false],
- [101, 1.01, "c", false],
- [150, 1.5, "c", false],
- [175, 1.75, "c", true]
+ [2, 300, "a", true, 1.23456789],
+ [2, 400, "a", true, 2.3456789],
+ [3, 100, "b", false, 3.456789],
+ [100, 1, "b", false, 4.56789],
+ [101, 1.01, "c", false, 5.6789],
+ [150, 1.5, "c", false, 6.789],
+ [175, 1.75, "c", true, 7.89]
]
}
},
@@ -44,6 +45,11 @@
"psql": "4.2.7",
"description": "aggregations on string column",
"sql": "SELECT count(string_col), count(distinct(string_col)),
count(*) FROM {tbl}"
+ },
+ {
+ "psql": "4.2.7",
+ "description": "aggregations on big_decimal column",
+ "sql": "SELECT min(big_decimal_col), max(big_decimal_col),
avg(big_decimal_col), sum(big_decimal_col), count(big_decimal_col), count(*)
FROM {tbl}"
}
]
},
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]