You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pinot.apache.org by ja...@apache.org on 2022/12/13 19:35:12 UTC
[pinot] branch master updated: coalesce literal (#9958)
This is an automated email from the ASF dual-hosted git repository.
jackie 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 c56a023f7a coalesce literal (#9958)
c56a023f7a is described below
commit c56a023f7ae38e652c34d962432ac09ee54b727d
Author: Yao Liu <ya...@startree.ai>
AuthorDate: Tue Dec 13 11:35:04 2022 -0800
coalesce literal (#9958)
---
.../function/CoalesceTransformFunction.java | 16 ++++++++++-----
.../function/CoalesceTransformFunctionTest.java | 24 ++++++++++++++++++++++
2 files changed, 35 insertions(+), 5 deletions(-)
diff --git a/pinot-core/src/main/java/org/apache/pinot/core/operator/transform/function/CoalesceTransformFunction.java b/pinot-core/src/main/java/org/apache/pinot/core/operator/transform/function/CoalesceTransformFunction.java
index 0176ae8efd..7a5b477764 100644
--- a/pinot-core/src/main/java/org/apache/pinot/core/operator/transform/function/CoalesceTransformFunction.java
+++ b/pinot-core/src/main/java/org/apache/pinot/core/operator/transform/function/CoalesceTransformFunction.java
@@ -68,9 +68,14 @@ public class CoalesceTransformFunction extends BaseTransformFunction {
RoaringBitmap[] roaringBitmaps = new RoaringBitmap[transformFunctions.length];
for (int i = 0; i < roaringBitmaps.length; i++) {
TransformFunction func = transformFunctions[i];
- String columnName = ((IdentifierTransformFunction) func).getColumnName();
- RoaringBitmap nullBitmap = projectionBlock.getBlockValueSet(columnName).getNullBitmap();
- roaringBitmaps[i] = nullBitmap;
+ if (func instanceof IdentifierTransformFunction) {
+ String columnName = ((IdentifierTransformFunction) func).getColumnName();
+ RoaringBitmap nullBitmap = projectionBlock.getBlockValueSet(columnName).getNullBitmap();
+ roaringBitmaps[i] = nullBitmap;
+ } else {
+ // Consider literal as not null.
+ roaringBitmaps[i] = new RoaringBitmap();
+ }
}
return roaringBitmaps;
}
@@ -297,8 +302,9 @@ public class CoalesceTransformFunction extends BaseTransformFunction {
_transformFunctions = new TransformFunction[argSize];
for (int i = 0; i < argSize; i++) {
TransformFunction func = arguments.get(i);
- Preconditions.checkArgument(func instanceof IdentifierTransformFunction,
- "Only column names are supported in COALESCE.");
+ Preconditions.checkArgument(
+ func instanceof IdentifierTransformFunction || func instanceof LiteralTransformFunction,
+ "Only column names and literals are supported in COALESCE.");
DataType dataType = func.getResultMetadata().getDataType();
if (_dataType == null) {
_dataType = dataType;
diff --git a/pinot-core/src/test/java/org/apache/pinot/core/operator/transform/function/CoalesceTransformFunctionTest.java b/pinot-core/src/test/java/org/apache/pinot/core/operator/transform/function/CoalesceTransformFunctionTest.java
index 00569eca15..d604044d18 100644
--- a/pinot-core/src/test/java/org/apache/pinot/core/operator/transform/function/CoalesceTransformFunctionTest.java
+++ b/pinot-core/src/test/java/org/apache/pinot/core/operator/transform/function/CoalesceTransformFunctionTest.java
@@ -429,6 +429,30 @@ public class CoalesceTransformFunctionTest extends BaseTransformFunctionTest {
});
}
+ // Test the Coalesce on two Int columns (where one or the other or both can be null) and litrals.
+ @Test
+ public void testCoalesceIntColumnsAndLiterals()
+ throws Exception {
+ ExpressionContext coalesceExpr =
+ RequestContextUtils.getExpression(String.format("COALESCE(%s,%s,%s)", INT_SV_COLUMN1, INT_SV_COLUMN2, 314));
+ TransformFunction coalesceTransformFunction = TransformFunctionFactory.get(coalesceExpr, _enableNullDataSourceMap);
+ Assert.assertEquals(coalesceTransformFunction.getName(), "coalesce");
+ int[] expectedResults = new int[NUM_ROWS];
+ for (int i = 0; i < NUM_ROWS; i++) {
+ if (isColumn1Null(i) && isColumn2Null(i)) {
+ expectedResults[i] = 314;
+ } else if (isColumn1Null(i)) {
+ expectedResults[i] = _intSVValues[i] + INT_VALUE_SHIFT;
+ } else if (isColumn2Null(i)) {
+ expectedResults[i] = _intSVValues[i];
+ } else {
+ expectedResults[i] = _intSVValues[i];
+ }
+ }
+ testIntTransformFunction(coalesceExpr, expectedResults, _enableNullProjectionBlock, _enableNullDataSourceMap);
+ testIntTransformFunction(coalesceExpr, expectedResults, _disableNullProjectionBlock, _disableNullDataSourceMap);
+ }
+
// Test that all arguments have to be same type.
@Test
public void testDifferentArgumentType()
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org