rui-mo commented on code in PR #5544:
URL: https://github.com/apache/incubator-gluten/pull/5544#discussion_r1582500791


##########
cpp/velox/operators/functions/RowFunctionWithNull.h:
##########
@@ -42,15 +44,26 @@ class RowFunctionWithNull final : public 
facebook::velox::exec::VectorFunction {
     rows.applyToSelected([&](facebook::velox::vector_size_t i) {
       facebook::velox::bits::clearNull(nullsPtr, i);
       if (!facebook::velox::bits::isBitNull(nullsPtr, i)) {
+        int argsNullCnt = 0;
         for (size_t c = 0; c < argsCopy.size(); c++) {
           auto arg = argsCopy[c].get();
           if (arg->mayHaveNulls() && arg->isNullAt(i)) {
-            // If any argument of the struct is null, set the struct as null.
-            facebook::velox::bits::setNull(nullsPtr, i, true);
-            cntNull++;
-            break;
+            // For row_constructor_with_null, if any argument of the struct is 
null,
+            // set the struct as null.
+            if (!allNull) {

Review Comment:
   constexpr



##########
cpp/velox/operators/functions/RowConstructorWithAllNull.h:
##########
@@ -0,0 +1,44 @@
+/*
+ * 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.
+ */
+
+#pragma once
+
+#include "velox/expression/FunctionCallToSpecialForm.h"
+#include "velox/expression/SpecialForm.h"
+
+namespace gluten {
+class RowConstructorWithAllNullCallToSpecialForm : public 
facebook::velox::exec::FunctionCallToSpecialForm {

Review Comment:
   Is it possible to extend `RowConstructorWithNullCallToSpecialForm` and reuse 
most of the code?



##########
backends-velox/src/main/scala/org/apache/gluten/utils/VeloxIntermediateData.scala:
##########
@@ -159,7 +159,10 @@ object VeloxIntermediateData {
    * row_constructor_with_null.
    */
   def getRowConstructFuncName(aggFunc: AggregateFunction): String = aggFunc 
match {
-    case _: Average | _: Sum if aggFunc.dataType.isInstanceOf[DecimalType] => 
"row_constructor"
+    case _: Average | _: Sum if aggFunc.dataType.isInstanceOf[DecimalType] =>
+      "row_constructor"
+    case _: MaxMinBy =>
+      "row_constructor_with_all_null"

Review Comment:
   I see your point. Could we add a comment to explain why 
`row_constructor_with_all_null` is needed by MaxMinBy?



##########
cpp/velox/operators/functions/RowFunctionWithNull.h:
##########
@@ -42,15 +44,26 @@ class RowFunctionWithNull final : public 
facebook::velox::exec::VectorFunction {
     rows.applyToSelected([&](facebook::velox::vector_size_t i) {
       facebook::velox::bits::clearNull(nullsPtr, i);
       if (!facebook::velox::bits::isBitNull(nullsPtr, i)) {
+        int argsNullCnt = 0;
         for (size_t c = 0; c < argsCopy.size(); c++) {
           auto arg = argsCopy[c].get();
           if (arg->mayHaveNulls() && arg->isNullAt(i)) {
-            // If any argument of the struct is null, set the struct as null.
-            facebook::velox::bits::setNull(nullsPtr, i, true);
-            cntNull++;
-            break;
+            // For row_constructor_with_null, if any argument of the struct is 
null,
+            // set the struct as null.
+            if (!allNull) {
+              facebook::velox::bits::setNull(nullsPtr, i, true);
+              cntNull++;
+              break;
+            } else {
+              argsNullCnt++;
+            }
           }
         }
+        // For row_constructor_with_all_null, set the struct to be null when 
all arguments are all
+        if (allNull && argsNullCnt == argsCopy.size()) {

Review Comment:
   nit: constexpr



-- 
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