You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@gluten.apache.org by "pedrumj2 (via GitHub)" <gi...@apache.org> on 2026/10/13 22:33:35 UTC

[PR] [CORE] Keep struct field names in udfLibraryPaths UDF signatures [gluten]

pedrumj2 opened a new pull request, #13274:
URL: https://github.com/apache/gluten/pull/13274

   ## What changes are proposed in this pull request?
   
   A UDF loaded through [`udfLibraryPaths`](https://github.com/apache/gluten/blob/main/docs/developers/VeloxUDF.md) now keeps the field names of every struct in its signature, so a named struct argument binds and the fields of a returned struct can be selected by name.
   
   apache/gluten#13016 let such a UDF be called by its own name for apache/gluten#13014, behind [`spark.gluten.sql.columnar.backend.velox.nativeUDF.bypassRegistration`](https://github.com/apache/gluten/blob/main/docs/velox-configuration.md). 
   
   Today the above implementation does not support NameStructs. This diff aims to address that
   
   ## How was this patch tested?
   
   ### Reproduction
   
   Everything runs in the `apache/gluten:centos-9-jdk8` image. Run each block from the same empty directory. The queries call two example UDFs that this pull request adds to [`MyUDF.cc`](https://github.com/apache/gluten/blob/main/cpp/velox/udf/examples/MyUDF.cc): one takes a `struct<a:bigint,b:bigint>` and the other returns one.
   
   #### [step1] Get the source and Spark
   
   ```bash
   git clone https://github.com/apache/gluten.git
   curl -LO https://archive.apache.org/dist/spark/spark-3.5.5/spark-3.5.5-bin-hadoop3.tgz
   tar -xzf spark-3.5.5-bin-hadoop3.tgz
   ```
   
   Then check out this pull request's branch in `gluten` as a local branch named `pr`.
   
   #### [step2] Write the queries
   
   ```bash
   cat > repro.sql <<'EOF'
   SELECT myudf_sum_row(named_struct('a', a, 'b', b)) AS sum_ab FROM VALUES (1L, 2L), (3L, 4L) AS t(a, b);
   SELECT myudf_make_row(id).b AS b FROM VALUES (1L), (2L) AS t(id);
   EXPLAIN SELECT myudf_make_row(id).b AS b FROM VALUES (1L) AS t(id);
   EOF
   ```
   
   #### [step3] Build Gluten with the UDF examples
   
   ```bash
   docker run --rm -v "$PWD":/work:z -w /work/gluten apache/gluten:centos-9-jdk8 bash -c '
     source /opt/rh/gcc-toolset-12/enable
     export VELOX_BUILD_SHARED=ON
     ./dev/builddeps-veloxbe.sh --build_examples=ON --build_arrow=OFF --run_setup_script=OFF
     ./build/mvn clean install -Pbackends-velox -Pspark-3.5 -DskipTests'
   ```
   
   #### [step4] Run the queries
   
   ```bash
   docker run --rm -v "$PWD":/work:z -w /work apache/gluten:centos-9-jdk8 \
     spark-3.5.5-bin-hadoop3/bin/spark-sql --master 'local[2]' \
       --jars gluten/package/target/gluten-velox-bundle-spark3.5_2.12-linux_amd64-1.8.0-SNAPSHOT.jar \
       --driver-class-path gluten/package/target/gluten-velox-bundle-spark3.5_2.12-linux_amd64-1.8.0-SNAPSHOT.jar \
       --conf spark.plugins=org.apache.gluten.GlutenPlugin \
       --conf spark.memory.offHeap.enabled=true \
       --conf spark.memory.offHeap.size=2g \
       --conf spark.shuffle.manager=org.apache.spark.shuffle.sort.ColumnarShuffleManager \
       --conf spark.gluten.sql.columnar.backend.velox.udfLibraryPaths=file:///work/gluten/cpp/build/velox/udf/examples/libmyudf.so \
       --conf spark.gluten.sql.columnar.backend.velox.driver.udfLibraryPaths=file:///work/gluten/cpp/build/velox/udf/examples/libmyudf.so \
       --conf spark.gluten.sql.columnar.backend.velox.nativeUDF.bypassRegistration=true \
       --hiveconf hive.cli.errors.ignore=true \
       -f repro.sql
   ```
   
   #### Before: the base commit with only the example UDFs from this pull request
   
   ```bash
   git -C gluten checkout --detach pr~1
   git -C gluten checkout pr -- cpp/velox/udf/examples/MyUDF.cc
   ```
   
   Then [step3] and [step4]:
   
   ```
   26/10/13 19:44:41 ERROR SparkSQLDriver: Failed in [SELECT myudf_sum_row(named_struct('a', a, 'b', b)) AS sum_ab FROM VALUES (1L, 2L), (3L, 4L) AS t(a, b)]
   org.apache.gluten.exception.GlutenNotSupportException: UDF myudf_sum_row -> struct<a:bigint,b:bigint> is not registered.
   	at org.apache.spark.sql.expression.UDFResolver$.getUdfExpression(UDFResolver.scala:407)
   	at org.apache.spark.sql.expression.UDFResolver$.$anonfun$getFunctionDescriptions$10(UDFResolver.scala:385)
   ...
   [FIELD_NOT_FOUND] No such struct field `b` in ``, ``.
   ...
   == Physical Plan ==
   org.apache.spark.sql.AnalysisException: [FIELD_NOT_FOUND] No such struct field `b` in ``, ``.
   ```
   
   #### After: this pull request
   
   ```bash
   git -C gluten checkout pr
   ```
   
   Then [step3] and [step4]:
   
   ```
   3
   7
   2
   3
   == Physical Plan ==
   VeloxColumnarToRow
   +- ^(1) ProjectExecTransformer [myudf_make_row(myudf_make_row, myudf_make_row, StructField(a,LongType,true), StructField(b,LongType,true), true, id#13L).b AS b#7L]
      +- ^(1) InputIteratorTransformer[id#13L]
         +- RowToVeloxColumnar
            +- LocalTableScan [id#13L]
   ```
   
   ### Tests
   
   New cases cover a named struct argument and return value end to end in [`VeloxUdfSuite`](https://github.com/apache/gluten/blob/main/backends-velox/src/test/scala/org/apache/gluten/expression/VeloxUdfSuite.scala), decoding with and without names in [`ConverterUtilsSuite`](https://github.com/apache/gluten/blob/main/gluten-substrait/src/test/scala/org/apache/gluten/expression/ConverterUtilsSuite.scala), and nested structs, including structs inside an array and a map, in [`VeloxToSubstraitTypeTest`](https://github.com/apache/gluten/blob/main/cpp/velox/tests/VeloxToSubstraitTypeTest.cc).
   
   ```
   ./build/mvn install -Pbackends-velox -Pspark-3.5 -Pfast-build -pl gluten-substrait,backends-velox -Dtest=none -Dsurefire.failIfNoSpecifiedTests=false -DwildcardSuites=org.apache.gluten.expression.ConverterUtilsSuite,org.apache.gluten.expression.VeloxUdfSuiteLocal -DtagsToExclude=org.apache.spark.tags.SkipTest
   ```
   
   ```
   - TimestampType emits PrecisionTimestampTZ(precision=6) and round-trips
   - TimestampNTZType emits PrecisionTimestamp(precision=6) and round-trips
   - column names for an attribute with a null name
   - struct field names are kept when the producer sets them
   - struct fields stay unnamed when the producer sets no names
   Tests: succeeded 5, failed 0, canceled 0, ignored 0, pending 0
   All tests passed.
   - test native hive udf
   - test native hive udaf
   - test native hive udaf in window
   - test udf fallback in partition filter
   - native udf with a plain name is callable without a hive udf class
   - native udf with a plain name fails at analysis when gluten is disabled
   - native udf with a named row argument is callable
   - native udf returning a named row exposes its field names
   Tests: succeeded 8, failed 0, canceled 0, ignored 0, pending 0
   All tests passed.
   ```
   
   ```
   cpp/build/velox/tests/velox_plan_conversion_test
   ```
   
   ```
   [       OK ] VeloxToSubstraitTypeTest.rowFieldNames (0 ms)
   [       OK ] VeloxToSubstraitTypeTest.rowFieldNamesInContainers (0 ms)
   [==========] 57 tests from 9 test suites ran. (644 ms total)
   [  PASSED  ] 50 tests.
   [  SKIPPED ] 7 tests, listed below:
   [  SKIPPED ] VeloxSubstraitRoundTripTest.sum
   [  SKIPPED ] VeloxSubstraitRoundTripTest.sumAndCount
   [  SKIPPED ] VeloxSubstraitRoundTripTest.sumGlobal
   [  SKIPPED ] VeloxSubstraitRoundTripTest.sumMask
   [  SKIPPED ] VeloxSubstraitRoundTripTest.projectAs
   [  SKIPPED ] VeloxSubstraitRoundTripTest.avg
   [  SKIPPED ] VeloxSubstraitRoundTripTest.subField
   
     YOU HAVE 1 DISABLED TEST
   ```
   
   ## Was this patch authored or co-authored using generative AI tooling?
   
   Generated-by: Co-authored with Claude Code (claude-opus-5-5)
   
   
   


-- 
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: commits-unsubscribe@gluten.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@gluten.apache.org
For additional commands, e-mail: commits-help@gluten.apache.org


Re: [PR] [GLUTEN-13273][VL] Keep struct field names in udfLibraryPaths UDF signatures [gluten]

Posted by "marin-ma (via GitHub)" <gi...@apache.org>.
marin-ma merged PR #13274:
URL: https://github.com/apache/gluten/pull/13274


-- 
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: commits-unsubscribe@gluten.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@gluten.apache.org
For additional commands, e-mail: commits-help@gluten.apache.org


Re: [PR] [GLUTEN-13273][VL] Keep struct field names in udfLibraryPaths UDF signatures [gluten]

Posted by "pedrumj2 (via GitHub)" <gi...@apache.org>.
pedrumj2 commented on code in PR #13274:
URL: https://github.com/apache/gluten/pull/13274#discussion_r4275699503


##########
cpp/velox/udf/examples/MyUDF.cc:
##########
@@ -108,6 +109,84 @@ class MyUdfPlusOneRegisterer final : public gluten::UdfRegisterer {
 
 } // namespace myudfplusone
 
+namespace myudfsumrow {
+
+template <typename T>
+struct MyUdfSumRowFunction {
+  VELOX_DEFINE_FUNCTION_TYPES(T);
+
+  FOLLY_ALWAYS_INLINE bool call(int64_t& result, const arg_type<Row<int64_t, int64_t>>& row) {
+    const auto a = row.template at<0>();
+    const auto b = row.template at<1>();
+    if (!a.has_value() || !b.has_value()) {
+      return false;
+    }
+    result = a.value() + b.value();
+    return true;
+  }

Review Comment:
   Updated



-- 
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: commits-unsubscribe@gluten.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@gluten.apache.org
For additional commands, e-mail: commits-help@gluten.apache.org


Re: [PR] [GLUTEN-13273][VL] Keep struct field names in udfLibraryPaths UDF signatures [gluten]

Posted by "pedrumj2 (via GitHub)" <gi...@apache.org>.
pedrumj2 commented on PR #13274:
URL: https://github.com/apache/gluten/pull/13274#issuecomment-6200850778

   > LGTM. Thanks.
   > 
   > Just to confirm this fix also applies to `spark.gluten.sql.columnar.backend.velox.nativeUDF.bypassRegistration=false` right?
   
   Thanks for the review @marin-ma. Yes it I believe it would also fix the `bypassRegistration=false` path as well. Repro below
   
   
   #### [step1] Get the source and Spark
   
   ```bash
   git clone https://github.com/apache/gluten.git
   git -C gluten fetch origin pull/13274/head:pr
   curl -LO https://archive.apache.org/dist/spark/spark-3.5.5/spark-3.5.5-bin-hadoop3.tgz
   tar -xzf spark-3.5.5-bin-hadoop3.tgz
   ```
   
   #### [step2] Add a Hive UDF, its native implementation registered under the Hive UDF's class name, and the query
   
   ```bash
   mkdir -p hiveudf/com/example/udf hiveudf/classes
   cat > hiveudf/com/example/udf/SumRow.java <<'EOF'
   package com.example.udf;
   
   import org.apache.hadoop.hive.ql.exec.UDFArgumentException;
   import org.apache.hadoop.hive.ql.metadata.HiveException;
   import org.apache.hadoop.hive.ql.udf.generic.GenericUDF;
   import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector;
   import org.apache.hadoop.hive.serde2.objectinspector.StructField;
   import org.apache.hadoop.hive.serde2.objectinspector.StructObjectInspector;
   import org.apache.hadoop.hive.serde2.objectinspector.primitive.LongObjectInspector;
   import org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory;
   
   public class SumRow extends GenericUDF {
     private StructObjectInspector rowOI;
     private StructField a;
     private StructField b;
   
     @Override
     public ObjectInspector initialize(ObjectInspector[] args) throws UDFArgumentException {
       rowOI = (StructObjectInspector) args[0];
       a = rowOI.getStructFieldRef("a");
       b = rowOI.getStructFieldRef("b");
       return PrimitiveObjectInspectorFactory.javaLongObjectInspector;
     }
   
     @Override
     public Object evaluate(DeferredObject[] args) throws HiveException {
       Object row = args[0].get();
       if (row == null) {
         return null;
       }
       Object av = rowOI.getStructFieldData(row, a);
       Object bv = rowOI.getStructFieldData(row, b);
       if (av == null || bv == null) {
         return null;
       }
       return ((LongObjectInspector) a.getFieldObjectInspector()).get(av)
           + ((LongObjectInspector) b.getFieldObjectInspector()).get(bv);
     }
   
     @Override
     public String getDisplayString(String[] children) {
       return "sum_row(" + children[0] + ")";
     }
   }
   EOF
   cat > gluten/cpp/velox/udf/examples/HiveStructUdf.cc <<'EOF'
   #include <velox/functions/Macros.h>
   #include <velox/functions/Registerer.h>
   #include "udf/Udf.h"
   
   using namespace facebook::velox;
   
   namespace {
   
   template <typename T>
   struct SumRowFunction {
     VELOX_DEFINE_FUNCTION_TYPES(T);
   
     FOLLY_ALWAYS_INLINE bool callNullable(int64_t& result, const arg_type<Row<int64_t, int64_t>>* row) {
       if (row == nullptr) {
         return false;
       }
       const auto a = row->template at<0>();
       const auto b = row->template at<1>();
       if (!a.has_value() || !b.has_value()) {
         return false;
       }
       result = a.value() + b.value();
       return true;
     }
   };
   
   const char* kName = "com.example.udf.SumRow";
   const char* kArgs[1] = {"struct<a:bigint,b:bigint>"};
   
   } // namespace
   
   DEFINE_GET_NUM_UDF {
     return 1;
   }
   
   DEFINE_GET_UDF_ENTRIES {
     udfEntries[0] = {kName, "bigint", 1, kArgs, false, false};
   }
   
   DEFINE_REGISTER_UDF {
     registerFunction<SumRowFunction, int64_t, Row<int64_t, int64_t>>({kName});
   }
   EOF
   cat >> gluten/cpp/velox/udf/examples/CMakeLists.txt <<'EOF'
   
   add_library(hivestructudf SHARED "HiveStructUdf.cc")
   target_link_libraries(hivestructudf velox)
   EOF
   cat > repro.sql <<'EOF'
   CREATE TEMPORARY FUNCTION sum_row AS 'com.example.udf.SumRow';
   SELECT sum_row(named_struct('a', id, 'b', id + 1)) AS sum_ab FROM range(1, 4, 2);
   EXPLAIN SELECT sum_row(named_struct('a', id, 'b', id + 1)) AS sum_ab FROM range(1, 4, 2);
   EOF
   docker run --rm -v "$PWD":/work:z -w /work apache/gluten:centos-9-jdk8 bash -c '
     javac -cp "spark-3.5.5-bin-hadoop3/jars/*" -d hiveudf/classes hiveudf/com/example/udf/SumRow.java
     jar cf hiveudf.jar -C hiveudf/classes .'
   ```
   
   #### [step3] Build Gluten with the UDF examples
   
   ```bash
   docker run --rm -v "$PWD":/work:z -w /work/gluten apache/gluten:centos-9-jdk8 bash -c '
     source /opt/rh/gcc-toolset-12/enable
     export VELOX_BUILD_SHARED=ON
     ./dev/builddeps-veloxbe.sh --build_examples=ON --build_arrow=OFF --run_setup_script=OFF
     ./build/mvn clean install -Pbackends-velox -Pspark-3.5 -DskipTests'
   ```
   
   #### [step4] Run the query with `bypassRegistration=false`
   
   ```bash
   docker run --rm -v "$PWD":/work:z -w /work apache/gluten:centos-9-jdk8 \
     spark-3.5.5-bin-hadoop3/bin/spark-sql --master 'local[2]' \
       --jars gluten/package/target/gluten-velox-bundle-spark3.5_2.12-linux_amd64-1.8.0-SNAPSHOT.jar,hiveudf.jar \
       --driver-class-path gluten/package/target/gluten-velox-bundle-spark3.5_2.12-linux_amd64-1.8.0-SNAPSHOT.jar:hiveudf.jar \
       --conf spark.plugins=org.apache.gluten.GlutenPlugin \
       --conf spark.memory.offHeap.enabled=true \
       --conf spark.memory.offHeap.size=2g \
       --conf spark.shuffle.manager=org.apache.spark.shuffle.sort.ColumnarShuffleManager \
       --conf spark.gluten.sql.columnar.backend.velox.udfLibraryPaths=file:///work/gluten/cpp/build/velox/udf/examples/libhivestructudf.so \
       --conf spark.gluten.sql.columnar.backend.velox.driver.udfLibraryPaths=file:///work/gluten/cpp/build/velox/udf/examples/libhivestructudf.so \
       --conf spark.gluten.sql.columnar.backend.velox.nativeUDF.bypassRegistration=false \
       --hiveconf hive.cli.errors.ignore=true \
       -f repro.sql
   ```
   
   #### Before: the base commit
   
   ```bash
   git -C gluten checkout --detach pr~1
   ```
   
   Then [step2], [step3] and [step4]:
   
   ```
   26/10/15 19:35:03 WARN GlutenFallbackReporter: Validation failed for plan: Project[QueryId=1], due to: 
    - Validation failed with exception from: ProjectExecTransformer, reason: UDF com.example.udf.SumRow -> struct<a:bigint,b:bigint> is not registered.
   3
   7
   ...
   == Physical Plan ==
   *(1) Project [HiveGenericUDF#com.example.udf.SumRow(named_struct(a, id#9L, b, (id#9L + 1))) AS sum_ab#3L]
   +- *(1) ColumnarToRow
      +- ColumnarRange 1, 4, 2, 2, 2, [id#9L]
   ```
   
   #### After: this pull request
   
   ```bash
   git -C gluten checkout pr
   ```
   
   Then [step3] and [step4]:
   
   ```
   3
   7
   ...
   == Physical Plan ==
   VeloxColumnarToRow
   +- ^(1) ProjectExecTransformer [HiveGenericUDF#com.example.udf.SumRow(named_struct(a, id#9L, b, (id#9L + 1))) AS sum_ab#3L]
      +- ^(1) InputIteratorTransformer[id#9L]
         +- ArrowColumnarToVeloxColumnar
            +- OffloadArrowData
               +- ColumnarRange 1, 4, 2, 2, 2, [id#9L]
   ```
   


-- 
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: commits-unsubscribe@gluten.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@gluten.apache.org
For additional commands, e-mail: commits-help@gluten.apache.org


Re: [PR] [Gluten-13273][VL] Keep struct field names in udfLibraryPaths UDF signatures [gluten]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #13274:
URL: https://github.com/apache/gluten/pull/13274#issuecomment-6158703001

   Run Gluten Clickhouse CI on x86


-- 
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: commits-unsubscribe@gluten.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@gluten.apache.org
For additional commands, e-mail: commits-help@gluten.apache.org


Re: [PR] [GLUTEN-13273][VL] Keep struct field names in udfLibraryPaths UDF signatures [gluten]

Posted by "pedrumj2 (via GitHub)" <gi...@apache.org>.
pedrumj2 commented on code in PR #13274:
URL: https://github.com/apache/gluten/pull/13274#discussion_r4275719859


##########
cpp/velox/udf/examples/MyUDF.cc:
##########
@@ -108,6 +109,84 @@ class MyUdfPlusOneRegisterer final : public gluten::UdfRegisterer {
 
 } // namespace myudfplusone
 
+namespace myudfsumrow {
+
+template <typename T>
+struct MyUdfSumRowFunction {
+  VELOX_DEFINE_FUNCTION_TYPES(T);
+
+  FOLLY_ALWAYS_INLINE bool call(int64_t& result, const arg_type<Row<int64_t, int64_t>>& row) {
+    const auto a = row.template at<0>();
+    const auto b = row.template at<1>();
+    if (!a.has_value() || !b.has_value()) {
+      return false;
+    }
+    result = a.value() + b.value();
+    return true;
+  }
+};
+
+// name: myudf_sum_row
+// signatures:
+//    struct<a:bigint,b:bigint> -> bigint
+// type: SimpleFunction
+class MyUdfSumRowRegisterer final : public gluten::UdfRegisterer {
+ public:
+  int getNumUdf() override {
+    return 1;
+  }
+
+  void populateUdfEntries(int& index, gluten::UdfEntry* udfEntries) override {
+    udfEntries[index++] = {name_.c_str(), kBigInt, 1, arg_, false, false};
+  }
+
+  void registerSignatures() override {
+    facebook::velox::registerFunction<MyUdfSumRowFunction, int64_t, Row<int64_t, int64_t>>({name_});
+  }
+
+ private:
+  const std::string name_ = "myudf_sum_row";
+  const char* arg_[1] = {kStructAB};
+};
+
+} // namespace myudfsumrow
+
+namespace myudfmakerow {
+
+template <typename T>
+struct MyUdfMakeRowFunction {
+  VELOX_DEFINE_FUNCTION_TYPES(T);
+
+  FOLLY_ALWAYS_INLINE void call(out_type<Row<int64_t, int64_t>>& result, const int64_t& a) {
+    result = std::make_tuple(a, a + 1);

Review Comment:
   Updated, applied those changes



-- 
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: commits-unsubscribe@gluten.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@gluten.apache.org
For additional commands, e-mail: commits-help@gluten.apache.org


Re: [PR] [GLUTEN-13273][VL] Keep struct field names in udfLibraryPaths UDF signatures [gluten]

Posted by "pedrumj2 (via GitHub)" <gi...@apache.org>.
pedrumj2 commented on code in PR #13274:
URL: https://github.com/apache/gluten/pull/13274#discussion_r4275699503


##########
cpp/velox/udf/examples/MyUDF.cc:
##########
@@ -108,6 +109,84 @@ class MyUdfPlusOneRegisterer final : public gluten::UdfRegisterer {
 
 } // namespace myudfplusone
 
+namespace myudfsumrow {
+
+template <typename T>
+struct MyUdfSumRowFunction {
+  VELOX_DEFINE_FUNCTION_TYPES(T);
+
+  FOLLY_ALWAYS_INLINE bool call(int64_t& result, const arg_type<Row<int64_t, int64_t>>& row) {
+    const auto a = row.template at<0>();
+    const auto b = row.template at<1>();
+    if (!a.has_value() || !b.has_value()) {
+      return false;
+    }
+    result = a.value() + b.value();
+    return true;
+  }

Review Comment:
   Updated, we have null check now:
   ```
   if (row == nullptr) {
         return false;
   }
   ```



-- 
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: commits-unsubscribe@gluten.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@gluten.apache.org
For additional commands, e-mail: commits-help@gluten.apache.org


Re: [PR] [GLUTEN-13273][VL] Keep struct field names in udfLibraryPaths UDF signatures [gluten]

Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #13274:
URL: https://github.com/apache/gluten/pull/13274#discussion_r4273355414


##########
cpp/velox/udf/examples/MyUDF.cc:
##########
@@ -108,6 +109,84 @@ class MyUdfPlusOneRegisterer final : public gluten::UdfRegisterer {
 
 } // namespace myudfplusone
 
+namespace myudfsumrow {
+
+template <typename T>
+struct MyUdfSumRowFunction {
+  VELOX_DEFINE_FUNCTION_TYPES(T);
+
+  FOLLY_ALWAYS_INLINE bool call(int64_t& result, const arg_type<Row<int64_t, int64_t>>& row) {
+    const auto a = row.template at<0>();
+    const auto b = row.template at<1>();
+    if (!a.has_value() || !b.has_value()) {
+      return false;
+    }
+    result = a.value() + b.value();
+    return true;
+  }

Review Comment:
   The UDF dereferences the struct argument unconditionally. If the *struct itself* is null (e.g., `CAST(NULL AS STRUCT<a:bigint,b:bigint>)`), accessing `row.at<0>()`/`row.at<1>()` can be invalid. Fix by explicitly handling a null struct argument (e.g., check `row.has_value()` / nullability per Velox UDF conventions) before reading fields, and return `false` to produce a null result when the input row is null.



##########
cpp/velox/udf/examples/MyUDF.cc:
##########
@@ -108,6 +109,84 @@ class MyUdfPlusOneRegisterer final : public gluten::UdfRegisterer {
 
 } // namespace myudfplusone
 
+namespace myudfsumrow {
+
+template <typename T>
+struct MyUdfSumRowFunction {
+  VELOX_DEFINE_FUNCTION_TYPES(T);
+
+  FOLLY_ALWAYS_INLINE bool call(int64_t& result, const arg_type<Row<int64_t, int64_t>>& row) {
+    const auto a = row.template at<0>();
+    const auto b = row.template at<1>();
+    if (!a.has_value() || !b.has_value()) {
+      return false;
+    }
+    result = a.value() + b.value();
+    return true;
+  }
+};
+
+// name: myudf_sum_row
+// signatures:
+//    struct<a:bigint,b:bigint> -> bigint
+// type: SimpleFunction
+class MyUdfSumRowRegisterer final : public gluten::UdfRegisterer {
+ public:
+  int getNumUdf() override {
+    return 1;
+  }
+
+  void populateUdfEntries(int& index, gluten::UdfEntry* udfEntries) override {
+    udfEntries[index++] = {name_.c_str(), kBigInt, 1, arg_, false, false};
+  }
+
+  void registerSignatures() override {
+    facebook::velox::registerFunction<MyUdfSumRowFunction, int64_t, Row<int64_t, int64_t>>({name_});
+  }
+
+ private:
+  const std::string name_ = "myudf_sum_row";
+  const char* arg_[1] = {kStructAB};
+};
+
+} // namespace myudfsumrow
+
+namespace myudfmakerow {
+
+template <typename T>
+struct MyUdfMakeRowFunction {
+  VELOX_DEFINE_FUNCTION_TYPES(T);
+
+  FOLLY_ALWAYS_INLINE void call(out_type<Row<int64_t, int64_t>>& result, const int64_t& a) {
+    result = std::make_tuple(a, a + 1);

Review Comment:
   This example UDF takes `a` as non-nullable (`const int64_t&`). In Spark SQL, `BIGINT` inputs are generally nullable, so passing null could lead to incorrect behavior or crashes depending on how the binding is performed. Consider using Velox's nullable argument type (`arg_type<int64_t>`) and emitting a null result when `a` is null, or otherwise documenting/enforcing non-nullability in the signature/registration.



-- 
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: commits-unsubscribe@gluten.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@gluten.apache.org
For additional commands, e-mail: commits-help@gluten.apache.org


Re: [PR] [GLUTEN-13273][VL] Keep struct field names in udfLibraryPaths UDF signatures [gluten]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #13274:
URL: https://github.com/apache/gluten/pull/13274#issuecomment-6178818272

   Run Gluten Clickhouse CI on x86


-- 
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: commits-unsubscribe@gluten.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@gluten.apache.org
For additional commands, e-mail: commits-help@gluten.apache.org


Re: [PR] [GLUTEN-13273][VL] Keep struct field names in udfLibraryPaths UDF signatures [gluten]

Posted by "pedrumj2 (via GitHub)" <gi...@apache.org>.
pedrumj2 commented on PR #13274:
URL: https://github.com/apache/gluten/pull/13274#issuecomment-6177404320

   @marin-ma  thanks for triggering co-pilot review. I addressed both comments, please let me know if there is anything else we'd like to change. 


-- 
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: commits-unsubscribe@gluten.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@gluten.apache.org
For additional commands, e-mail: commits-help@gluten.apache.org