From 100bd351245db6284693366dee6f22ea38a15363 Mon Sep 17 00:00:00 2001 From: ggjh-159 Date: Fri, 5 Jun 2026 15:14:11 +0800 Subject: [PATCH] fix(planner): extract VARCHAR literal value without charset prefix Use getValueAs(String.class) instead of getValue().toString() which produces "_UTF-16LE'value'" from NlsString. --- .../gluten/rexnode/RexNodeConverter.java | 2 +- .../gluten/rexnode/RexNodeConverterTest.java | 66 +++++++++++++++++++ 2 files changed, 67 insertions(+), 1 deletion(-) create mode 100644 gluten-flink/ut/src/test/java/org/apache/gluten/rexnode/RexNodeConverterTest.java diff --git a/gluten-flink/planner/src/main/java/org/apache/gluten/rexnode/RexNodeConverter.java b/gluten-flink/planner/src/main/java/org/apache/gluten/rexnode/RexNodeConverter.java index 337300c5927..a3284703f2d 100644 --- a/gluten-flink/planner/src/main/java/org/apache/gluten/rexnode/RexNodeConverter.java +++ b/gluten-flink/planner/src/main/java/org/apache/gluten/rexnode/RexNodeConverter.java @@ -110,7 +110,7 @@ public static Variant toVariant(RexLiteral literal) { case DOUBLE: return new DoubleValue(Double.valueOf(literal.getValue().toString())); case VARCHAR: - return new VarCharValue(literal.getValue().toString()); + return new VarCharValue(literal.getValueAs(String.class)); case CHAR: // For CHAR, we convert it to VARCHAR return new VarCharValue(literal.getValueAs(String.class)); diff --git a/gluten-flink/ut/src/test/java/org/apache/gluten/rexnode/RexNodeConverterTest.java b/gluten-flink/ut/src/test/java/org/apache/gluten/rexnode/RexNodeConverterTest.java new file mode 100644 index 00000000000..0cae77d7b68 --- /dev/null +++ b/gluten-flink/ut/src/test/java/org/apache/gluten/rexnode/RexNodeConverterTest.java @@ -0,0 +1,66 @@ +/* + * 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; + +import io.github.zhztheplayer.velox4j.variant.VarCharValue; +import io.github.zhztheplayer.velox4j.variant.Variant; + +import org.apache.flink.table.planner.calcite.FlinkRexBuilder; +import org.apache.flink.table.planner.calcite.FlinkTypeFactory; +import org.apache.flink.table.planner.calcite.FlinkTypeSystem; + +import org.apache.calcite.rex.RexBuilder; +import org.apache.calcite.rex.RexLiteral; +import org.apache.calcite.sql.type.SqlTypeName; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; + +import static org.assertj.core.api.Assertions.assertThat; + +public class RexNodeConverterTest { + + private static FlinkTypeFactory typeFactory; + private static RexBuilder rexBuilder; + + @BeforeAll + public static void setUp() { + typeFactory = + new FlinkTypeFactory( + Thread.currentThread().getContextClassLoader(), FlinkTypeSystem.INSTANCE); + rexBuilder = new FlinkRexBuilder(typeFactory); + } + + @Test + public void testVarcharLiteralExtractsRawValue() { + RexLiteral literal = + (RexLiteral) + rexBuilder.makeLiteral("apple", typeFactory.createSqlType(SqlTypeName.VARCHAR), false); + Variant variant = RexNodeConverter.toVariant(literal); + assertThat(variant).isInstanceOf(VarCharValue.class); + assertThat(((VarCharValue) variant).getValue()).isEqualTo("apple"); + } + + @Test + public void testCharLiteralExtractsRawValue() { + RexLiteral literal = + (RexLiteral) + rexBuilder.makeLiteral("banana", typeFactory.createSqlType(SqlTypeName.CHAR), false); + Variant variant = RexNodeConverter.toVariant(literal); + assertThat(variant).isInstanceOf(VarCharValue.class); + assertThat(((VarCharValue) variant).getValue()).isEqualTo("banana"); + } +}