Jackie-Jiang commented on code in PR #9327:
URL: https://github.com/apache/pinot/pull/9327#discussion_r966435928


##########
pinot-core/src/main/java/org/apache/pinot/core/operator/transform/function/CoalesceTransformFunction.java:
##########
@@ -0,0 +1,108 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License 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 org.apache.pinot.core.operator.transform.function;
+
+import java.util.List;
+import java.util.Map;
+import org.apache.pinot.common.function.TransformFunctionType;
+import org.apache.pinot.core.operator.blocks.ProjectionBlock;
+import org.apache.pinot.core.operator.transform.TransformResultMetadata;
+import org.apache.pinot.segment.spi.datasource.DataSource;
+import org.apache.pinot.segment.spi.index.reader.NullValueVectorReader;
+
+
+/**
+ * The <code>CoalesceTransformFunction</code> implements the Coalesce operator.
+ *
+ * The results are in String format for first non-null value in the argument 
list.
+ * If all arguments are null, return a 'null' string.
+ * Note: arguments have to be column names.
+ *
+ * Expected result:
+ * Coalesce(nullColumn, columnA): columnA
+ * Coalesce(columnA, nullColumn): nullColumn
+ * Coalesce(nullColumnA, nullColumnB): "null"
+ *
+ * Note this operator only takes column names for now.
+ * SQL Syntax:
+ *    Coalesce(columnA, columnB)
+ */
+public class CoalesceTransformFunction extends BaseTransformFunction {
+  private String[] _results;
+  private NullValueVectorReader[] _nullValueReaders;
+  private TransformFunction[] _transformFunctions;
+
+  @Override
+  public String getName() {
+    return TransformFunctionType.COALESCE.getName();
+  }
+
+  @Override
+  public void init(List<TransformFunction> arguments, Map<String, DataSource> 
dataSourceMap) {
+    int argSize = arguments.size();
+    _nullValueReaders = new NullValueVectorReader[argSize];
+    _transformFunctions = new TransformFunction[argSize];
+    for (int i = 0; i < argSize; i++) {
+      TransformFunction func = arguments.get(i);
+      if (!(func instanceof IdentifierTransformFunction)) {
+        throw new IllegalArgumentException("Only column names are supported in 
COALESCE.");
+      }
+      String columnName = ((IdentifierTransformFunction) func).getColumnName();
+      NullValueVectorReader nullValueVectorReader = 
dataSourceMap.get(columnName).getNullValueVector();
+      _nullValueReaders[i] = nullValueVectorReader;
+      _transformFunctions[i] = func;
+    }
+  }
+
+  @Override
+  public TransformResultMetadata getResultMetadata() {
+    return STRING_MV_NO_DICTIONARY_METADATA;
+  }
+
+  @Override
+  public String[] transformToStringValuesSV(ProjectionBlock projectionBlock) {

Review Comment:
   Good point. Currently we don't support `null` values for transform function 
yet. You may read `TransformBlockValSet.getNullBitmap()`, which count the 
result as `null` when any argument is `null`. This won't work for `coalesce`.
   
   For now, we may use `NullValueUtils.getDefaultNullValue()` for each data 
type to present the null. Then we should figure out a way to support the real 
`null` in transform function.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to