marin-ma commented on code in PR #5495:
URL: https://github.com/apache/incubator-gluten/pull/5495#discussion_r1579037893


##########
cpp/velox/udf/examples/MyUDF.cc:
##########
@@ -56,33 +64,36 @@ class PlusConstantFunction : public exec::VectorFunction {
 
     flatResult->clearNulls(rows);
 
-    if (arg->isConstantEncoding()) {
-      auto value = arg->as<ConstantVector<nativeType>>()->valueAt(0);
-      rows.applyToSelected([&](auto row) { rawResult[row] = value + addition_; 
});
-    } else {
-      auto* rawInput = arg->as<FlatVector<nativeType>>()->rawValues();
+    rows.applyToSelected([&](auto row) { rawResult[row] = addition_; });
+
+    if (args.size() == 0) {
+      return;
+    }
 
-      rows.applyToSelected([&](auto row) { rawResult[row] = rawInput[row] + 
addition_; });
+    for (int i = 0; i < args.size(); i++) {
+      auto& arg = args[i];
+      VELOX_CHECK(arg->isFlatEncoding() || arg->isConstantEncoding());
+      if (arg->isConstantEncoding()) {
+        auto value = arg->as<ConstantVector<nativeType>>()->valueAt(0);
+        rows.applyToSelected([&](auto row) { rawResult[row] += value; });
+      } else {
+        auto* rawInput = arg->as<FlatVector<nativeType>>()->rawValues();
+        rows.applyToSelected([&](auto row) { rawResult[row] += rawInput[row]; 
});
+      }
     }
   }
 
  private:
   const int32_t addition_;
 };
 
-template <typename T>
-struct MyDateSimpleFunction {
-  VELOX_DEFINE_FUNCTION_TYPES(T);
-
-  FOLLY_ALWAYS_INLINE void call(int32_t& result, const arg_type<Date>& date, 
const arg_type<int32_t> addition) {
-    result = date + addition;
-  }
-};
-
-std::shared_ptr<facebook::velox::exec::VectorFunction> makeMyUdf1(
+static std::shared_ptr<facebook::velox::exec::VectorFunction> makePlusConstant(
     const std::string& /*name*/,
     const std::vector<exec::VectorFunctionArg>& inputArgs,
     const core::QueryConfig& /*config*/) {
+  if (inputArgs.size() == 0) {
+    return std::make_shared<PlusConstantFunction<TypeKind::INTEGER>>(5);

Review Comment:
   Will rename it to "PlusFiveFunction"



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