This is an automated email from the ASF dual-hosted git repository.
philo-he pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/gluten.git
The following commit(s) were added to refs/heads/main by this push:
new 31fb4dad58 [GLUTEN-13457][FLINK][VL] Add support for NOT, IS FALSE, IS
NOT TRUE (#13461)
31fb4dad58 is described below
commit 31fb4dad58e7339ac4f4b820931d648160dc4746
Author: zhangxiong <[email protected]>
AuthorDate: Wed Nov 11 01:56:52 2026 +0800
[GLUTEN-13457][FLINK][VL] Add support for NOT, IS FALSE, IS NOT TRUE
(#13461)
---
.../rexnode/functions/IsTrueRexCallConverter.java | 67 ------------
.../rexnode/functions/RexCallConverterFactory.java | 7 +-
.../stream/custom/LogicalFunctionsTest.java | 112 +++++++++++++++++++++
3 files changed, 118 insertions(+), 68 deletions(-)
diff --git
a/gluten-flink/planner/src/main/java/org/apache/gluten/rexnode/functions/IsTrueRexCallConverter.java
b/gluten-flink/planner/src/main/java/org/apache/gluten/rexnode/functions/IsTrueRexCallConverter.java
deleted file mode 100644
index f086c97e44..0000000000
---
a/gluten-flink/planner/src/main/java/org/apache/gluten/rexnode/functions/IsTrueRexCallConverter.java
+++ /dev/null
@@ -1,67 +0,0 @@
-/*
- * 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.ValidationResult;
-
-import io.github.zhztheplayer.velox4j.expression.CallTypedExpr;
-import io.github.zhztheplayer.velox4j.expression.ConstantTypedExpr;
-import io.github.zhztheplayer.velox4j.expression.TypedExpr;
-import io.github.zhztheplayer.velox4j.type.BooleanType;
-import io.github.zhztheplayer.velox4j.type.Type;
-import io.github.zhztheplayer.velox4j.variant.BooleanValue;
-
-import org.apache.flink.table.planner.calcite.FlinkTypeFactory;
-import org.apache.flink.table.types.logical.LogicalType;
-import org.apache.flink.table.types.logical.LogicalTypeRoot;
-
-import org.apache.calcite.rex.RexCall;
-import org.apache.calcite.rex.RexNode;
-
-import java.util.List;
-
-public class IsTrueRexCallConverter extends BaseRexCallConverter {
- private static final String FUNCTION_NAME = "equalto";
-
- public IsTrueRexCallConverter() {
- super(FUNCTION_NAME);
- }
-
- @Override
- public ValidationResult isSuitable(RexCall callNode, RexConversionContext
context) {
- if (callNode.getOperands().size() != 1) {
- return ValidationResult.failure("Function isTrue operands number must be
1.");
- }
- RexNode rexNode = callNode.getOperands().get(0);
- LogicalType targetType = FlinkTypeFactory.toLogicalType(rexNode.getType());
- if (targetType.is(LogicalTypeRoot.BOOLEAN)) {
- return ValidationResult.success();
- } else {
- return ValidationResult.failure("Parameter is not Boolean type.");
- }
- }
-
- @Override
- public TypedExpr toTypedExpr(RexCall callNode, RexConversionContext context)
{
- List<TypedExpr> params = getParams(callNode, context);
- TypedExpr constantTrue = new ConstantTypedExpr(new BooleanType(), new
BooleanValue(true), null);
- params.add(constantTrue);
- Type resultType = getResultType(callNode);
- return new CallTypedExpr(resultType, params, functionName);
- }
-}
diff --git
a/gluten-flink/planner/src/main/java/org/apache/gluten/rexnode/functions/RexCallConverterFactory.java
b/gluten-flink/planner/src/main/java/org/apache/gluten/rexnode/functions/RexCallConverterFactory.java
index b299f564f3..8f98fbdbd3 100644
---
a/gluten-flink/planner/src/main/java/org/apache/gluten/rexnode/functions/RexCallConverterFactory.java
+++
b/gluten-flink/planner/src/main/java/org/apache/gluten/rexnode/functions/RexCallConverterFactory.java
@@ -131,7 +131,12 @@ public class RexCallConverterFactory {
Map.entry("SHA512", Arrays.asList(() -> new
DefaultRexCallConverter("sha512"))),
Map.entry("count_char", Arrays.asList(() -> new
DefaultRexCallConverter("count_char"))),
Map.entry("EXTRACT", Arrays.asList(() -> new
DefaultRexCallConverter("extract"))),
- Map.entry("IS TRUE", Arrays.asList(() -> new
IsTrueRexCallConverter())),
+ Map.entry("IS TRUE", Arrays.asList(() -> new
DefaultRexCallConverter("is_true"))),
+ Map.entry("IS FALSE", Arrays.asList(() -> new
DefaultRexCallConverter("is_false"))),
+ Map.entry("IS NOT TRUE", Arrays.asList(() -> new
DefaultRexCallConverter("is_not_true"))),
+ Map.entry(
+ "IS NOT FALSE", Arrays.asList(() -> new
DefaultRexCallConverter("is_not_false"))),
+ Map.entry("NOT", Arrays.asList(() -> new
DefaultRexCallConverter("not"))),
Map.entry("CONCAT", Arrays.asList(() -> new
DefaultRexCallConverter("concat"))),
Map.entry("CONCAT_WS", Arrays.asList(() -> new
DefaultRexCallConverter("concat_ws"))),
// A literal negative length is rejected by SubstringRexCallConverter
diff --git
a/gluten-flink/ut/src/test/java/org/apache/gluten/table/runtime/stream/custom/LogicalFunctionsTest.java
b/gluten-flink/ut/src/test/java/org/apache/gluten/table/runtime/stream/custom/LogicalFunctionsTest.java
new file mode 100644
index 0000000000..62d3ecddb3
--- /dev/null
+++
b/gluten-flink/ut/src/test/java/org/apache/gluten/table/runtime/stream/custom/LogicalFunctionsTest.java
@@ -0,0 +1,112 @@
+/*
+ * 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.table.runtime.stream.custom;
+
+import org.apache.gluten.table.runtime.stream.common.GlutenStreamingTestBase;
+
+import org.apache.flink.types.Row;
+
+import org.junit.jupiter.api.Test;
+
+import java.util.Arrays;
+import java.util.List;
+
+/** SQL-level tests for the logical operators over a boolean column containing
NULLs. */
+class LogicalFunctionsTest extends GlutenStreamingTestBase {
+
+ // Three-valued truth-table input: TRUE, FALSE, UNKNOWN.
+ private List<Row> truthTableRows() {
+ return Arrays.asList(Row.of(true), Row.of(false), Row.of((Object) null));
+ }
+
+ @Test
+ void testNot() {
+ createSimpleBoundedValuesTable("tblLogicalNot", "c boolean",
truthTableRows());
+ String query = "select NOT(c) from tblLogicalNot";
+ runAndCheck(query, Arrays.asList("+I[false]", "+I[true]", "+I[null]"));
+ }
+
+ @Test
+ void testIsTrue() {
+ createSimpleBoundedValuesTable("tblLogicalIsTrue", "c boolean",
truthTableRows());
+ String query = "select c IS TRUE from tblLogicalIsTrue";
+ runAndCheck(query, Arrays.asList("+I[true]", "+I[false]", "+I[false]"));
+ }
+
+ @Test
+ void testIsFalse() {
+ createSimpleBoundedValuesTable("tblLogicalIsFalse", "c boolean",
truthTableRows());
+ String query = "select c IS FALSE from tblLogicalIsFalse";
+ runAndCheck(query, Arrays.asList("+I[false]", "+I[true]", "+I[false]"));
+ }
+
+ @Test
+ void testIsNotTrue() {
+ createSimpleBoundedValuesTable("tblLogicalIsNotTrue", "c boolean",
truthTableRows());
+ String query = "select c IS NOT TRUE from tblLogicalIsNotTrue";
+ runAndCheck(query, Arrays.asList("+I[false]", "+I[true]", "+I[true]"));
+ }
+
+ @Test
+ void testIsNotFalse() {
+ createSimpleBoundedValuesTable("tblLogicalIsNotFalse", "c boolean",
truthTableRows());
+ String query = "select c IS NOT FALSE from tblLogicalIsNotFalse";
+ runAndCheck(query, Arrays.asList("+I[true]", "+I[false]", "+I[true]"));
+ }
+
+ @Test
+ void testNestedLogical() {
+ createSimpleBoundedValuesTable("tblLogicalNested", "c boolean",
truthTableRows());
+ // NOT(c IS FALSE): IS FALSE never returns NULL, so NOT sees
+ // {false,true,false} -> {true,false,true}.
+ // (NOT(c)) IS NOT TRUE (parens required: IS binds tighter than NOT, so
+ // NOT(c) IS NOT TRUE parses as NOT(c IS NOT TRUE)): NOT preserves NULL,
+ // then IS NOT TRUE maps {false,true,NULL} -> {true,false,true}, never
+ // NULL.
+ // NOT(c) IS NOT TRUE parses as NOT(c IS NOT TRUE); c IS NOT TRUE is
+ // never NULL, so NOT flips {false,true,true} -> {true,false,false}.
+ String query =
+ "select NOT(c IS FALSE), (NOT(c)) IS NOT TRUE, NOT(c) IS NOT TRUE from
tblLogicalNested";
+ runAndCheck(
+ query,
+ Arrays.asList("+I[true, true, true]", "+I[false, false, false]",
"+I[true, true, false]"));
+ }
+
+ @Test
+ void testConstantOperands() {
+ createSimpleBoundedValuesTable("tblLogicalConst", "c boolean",
truthTableRows());
+ // Constant and constant-foldable operands: a NULL constant operand still
+ // yields FALSE under IS TRUE, never NULL.
+ String query =
+ "select NOT(true), NOT(false), true IS TRUE, false IS FALSE, "
+ + "CAST(NULL AS BOOLEAN) IS TRUE, NOT(1 = 1) from tblLogicalConst";
+ runAndCheck(
+ query,
+ Arrays.asList(
+ "+I[false, true, true, true, false, false]",
+ "+I[false, true, true, true, false, false]",
+ "+I[false, true, true, true, false, false]"));
+ }
+
+ @Test
+ void testLogicalFilter() {
+ createSimpleBoundedValuesTable("tblLogicalFilter", "c boolean",
truthTableRows());
+ // IS NOT FALSE passes TRUE and UNKNOWN, rejects FALSE.
+ String query = "select c from tblLogicalFilter where c IS NOT FALSE";
+ runAndCheck(query, Arrays.asList("+I[true]", "+I[null]"));
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]