You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@gluten.apache.org by "wud-if (via GitHub)" <gi...@apache.org> on 2026/10/20 01:58:26 UTC

[PR] [GLUTEN-13369][FLINK] Support function IFNULL [gluten]

wud-if opened a new pull request, #13375:
URL: https://github.com/apache/gluten/pull/13375

   ### What changes are proposed in this pull request?
   
   Adds the planner-side wiring so Flink's `IFNULL(a, b)` offloads to the velox flinksql `ifnull` function (bigo-sg/velox#82> adds the function itself):
   
   - `RexCallConverterFactory`: map the `IFNULL` RexCall to `ifnull` via the default name converter. Flink's planner coerces both operands to their common type before the call, so a plain name mapping suffices.
   - `RexNodeConverter`: typed null-literal support — `CAST(NULL AS X)` folds to a null `RexLiteral`, which previously NPE'd in `toVariant`. A null literal now converts to a single null-accepting variant carrier; the velox-side serde (companion velox PR) reads the absent `"value"` member as the typed null. This is required for `IFNULL(x, CAST(NULL AS ...))` shapes and null constants in offloaded calcs in general.
   
   ### How was this patch tested?
   
   - `gluten-flink/ut`: `RexNodeConverterTest` null-literal cases (six SQL types plus decimal) and `IfNullFunctionsTest` execution tests (null three-state across STRING/BIGINT/DOUBLE/DECIMAL, null-literal first arg, both null) pass.
   - End-to-end dual-run on Flink 1.19.2 (native vs gluten-offloaded, identical VALUES inputs, changelog multiset exact comparison): the IFNULL case matches native exactly; the full 11-case expression suite passes.


-- 
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-13369][FLINK] Support function IFNULL [gluten]

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

   @KevinyhZou Thanks for the correction — you're right, this is plan-time fail-loud, not a fallback: getConverter throws when no converter matches and StreamExecCalc does not catch it, so the job fails at plan translation. Pushed cc69043 rewording all three spots as suggested:
   
   - ScalarOnlyRexCallConverter / TypeUtils: operands (BINARY, ARRAY, MAP, ROW) are rejected so conversion fails loudly at planning time instead of failing at runtime with an unresolved velox signature.
   - RexNodeConverter: the typed-null serde comment now reflects the current state — velox4j emits an explicit "value": null via @JsonInclude(ALWAYS), and the velox serde accepts both an explicit null and an absent member.
   
   The PR description is updated accordingly as well. 


-- 
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-13369][FLINK] Support function IFNULL [gluten]

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

   @ggjh-159 @KevinyhZou Would you mind reviewing this PR?


-- 
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-13369][FLINK] Support function IFNULL [gluten]

Posted by "ggjh-159 (via GitHub)" <gi...@apache.org>.
ggjh-159 commented on code in PR #13375:
URL: https://github.com/apache/gluten/pull/13375#discussion_r4377305267


##########
gluten-flink/planner/src/main/java/org/apache/gluten/rexnode/RexNodeConverter.java:
##########
@@ -97,7 +97,38 @@ public static Type toType(RelDataType relDataType) {
     return LogicalTypeConverter.toVLType(FlinkTypeFactory.toLogicalType(relDataType));
   }
 
+  private static Variant toNullVariant(SqlTypeName sqlTypeName) {
+    // A typed null needs no per-type carrier: the velox-side
+    // ConstantTypedExpr renders a null variant as a null constant of the
+    // EXPRESSION type (the variant kind is irrelevant on the null path), and
+    // the velox variant serde treats an absent "value" member as the typed
+    // null (matching velox4j's Include.NON_NULL serialization). VarCharValue
+    // is the natural null-accepting carrier.
+    switch (sqlTypeName) {

Review Comment:
   The toNullVariant switch is missing DATE: IFNULL(date_col, NULL) / IFNULL(NULL, date_col) fails at job construction with "Unsupported null rex node type: DATE". Please add the DATE case (and INTERVAL_SECOND / SYMBOL, which the main switch handles but the null path does not).



-- 
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-13369][FLINK] Support function IFNULL [gluten]

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

   @KevinyhZou Thanks for the review! Done — pushed in 3428d45.


-- 
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-13369][FLINK] Support function IFNULL [gluten]

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


##########
gluten-flink/planner/src/main/java/org/apache/gluten/rexnode/TypeUtils.java:
##########
@@ -53,6 +53,20 @@ public static boolean isStringType(Type type) {
     return type instanceof VarCharType;
   }
 
+  // Matches the scalar signatures registered under the velox flinksql
+  // namespace: booleans, numerics, strings, dates, timestamps and decimals.
+  // BINARY, ARRAY, MAP and ROW have no flinksql registration and must be
+  // rejected at the converter level so the planner falls back instead of

Review Comment:
   Same nit as on `ScalarOnlyRexCallConverter`: rejecting here does not make the planner fall back; it causes plan-time failure via `getConverter`. Suggest something like:
   
   ```
     // rejected at the converter level so conversion fails at planning time
     // instead of failing at runtime.
   ```



##########
gluten-flink/planner/src/main/java/org/apache/gluten/rexnode/RexNodeConverter.java:
##########
@@ -97,7 +97,41 @@ public static Type toType(RelDataType relDataType) {
     return LogicalTypeConverter.toVLType(FlinkTypeFactory.toLogicalType(relDataType));
   }
 
+  private static Variant toNullVariant(SqlTypeName sqlTypeName) {
+    // A typed null needs no per-type carrier: the velox-side
+    // ConstantTypedExpr renders a null variant as a null constant of the
+    // EXPRESSION type (the variant kind is irrelevant on the null path), and
+    // the velox variant serde treats an absent "value" member as the typed
+    // null (matching velox4j's Include.NON_NULL serialization). VarCharValue
+    // is the natural null-accepting carrier.
+    switch (sqlTypeName) {
+      case BOOLEAN:
+      case TINYINT:
+      case SMALLINT:
+      case INTEGER:
+      case BIGINT:
+      case DOUBLE:
+      case FLOAT:
+      case VARCHAR:
+      case CHAR:
+      case BINARY:
+      case DECIMAL:
+      case DATE:
+      case INTERVAL_SECOND:
+      case SYMBOL:
+      case TIMESTAMP:
+        return new VarCharValue(null);
+      default:
+        throw new RuntimeException("Unsupported null rex node type: " + sqlTypeName);
+    }
+  }
+
   public static Variant toVariant(RexLiteral literal) {
+    if (literal.getValue() == null || literal.isNull()) {
+      // A typed null literal: velox4j's NON_NULL serialization omits the
+      // "value" member and the velox-side serde reads that as the typed null.

Review Comment:
   Minor: velox4j now uses `@JsonInclude(JsonInclude.Include.ALWAYS)` for `Variant`, so null carriers serialize as `"value": null` rather than omitting the member. Velox accepts both; the comment is slightly outdated. Optional to say that absent or explicit-null `value` both work.



##########
gluten-flink/planner/src/main/java/org/apache/gluten/rexnode/functions/ScalarOnlyRexCallConverter.java:
##########
@@ -0,0 +1,63 @@
+/*
+ * 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.gluten.rexnode.functions;
+
+import org.apache.gluten.rexnode.RexConversionContext;
+import org.apache.gluten.rexnode.RexNodeConverter;
+import org.apache.gluten.rexnode.TypeUtils;
+import org.apache.gluten.rexnode.ValidationResult;
+
+import io.github.zhztheplayer.velox4j.expression.CallTypedExpr;
+import io.github.zhztheplayer.velox4j.expression.TypedExpr;
+import io.github.zhztheplayer.velox4j.type.Type;
+
+import org.apache.calcite.rex.RexCall;
+
+import java.util.List;
+
+/**
+ * Converter for functions whose velox flinksql registrations cover scalar types only. Complex
+ * operands (BINARY, ARRAY, MAP, ROW) are rejected here so the planner falls back to the native
+ * operator instead of failing at runtime with an unresolved velox signature.

Review Comment:
   Nit: this does not fall back to the native operator. When `isSuitable` fails, `RexCallConverterFactory.getConverter` ends up with an empty converter list and throws (`No suitable converter found for: IFNULL ...`), and `StreamExecCalc.translateToPlanInternal` has no try/catch — so the job fails at plan translation.
   
   Suggest rewording, e.g.:
   
   ```
    * operands (BINARY, ARRAY, MAP, ROW) are rejected here so conversion fails
    * loudly at planning time instead of failing at runtime with an unresolved
    * velox signature.
   ```



-- 
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-13369][FLINK] Support function IFNULL [gluten]

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

   @ggjh-159 Thanks for the review! Pushed dc0bc10 (plus 5b993ca for the velox-side review follow-up on scalar-only coverage):                                          
   - toNullVariant: added the missing DATE case plus INTERVAL_SECOND and SYMBOL (all fall through to the same null-accepting VarCharValue carrier), so IFNULL(date_col, NULL) / IFNULL(NULL, date_col) now plan fine. The null-literal test covers DATE, SYMBOL and a second-interval null literal; interval types are built via createSqlIntervalType(SqlIntervalQualifier) since createSqlType(INTERVAL_SECOND) is rejected by Calcite.
   - Spotless: applied; the stray blank line is gone.                                                                                                                                                                                                           - Also note: IFNULL now uses ScalarOnlyRexCallConverter — non-scalar operands (BINARY/ARRAY/MAP/ROW) are rejected at the converter level so the planner falls back to the native operator, matching the scalar-only velox registrations raised in the velox-side review. 


-- 
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-13369][FLINK] Support function IFNULL [gluten]

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

   please update velox4j version @wud-if 


-- 
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-13369][FLINK] Support function IFNULL [gluten]

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


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