github-actions[bot] commented on code in PR #68131:
URL: https://github.com/apache/doris/pull/68131#discussion_r4069766918


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/Decode.java:
##########
@@ -0,0 +1,91 @@
+// 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.doris.nereids.trees.expressions.functions.scalar;
+
+import org.apache.doris.catalog.FunctionSignature;
+import org.apache.doris.nereids.exceptions.AnalysisException;
+import org.apache.doris.nereids.trees.expressions.Expression;
+import 
org.apache.doris.nereids.trees.expressions.functions.ExplicitlyCastableSignature;
+import org.apache.doris.nereids.trees.expressions.functions.PropagateNullable;
+import org.apache.doris.nereids.trees.expressions.shape.BinaryExpression;
+import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor;
+import org.apache.doris.nereids.types.StringType;
+import org.apache.doris.nereids.types.VarBinaryType;
+
+import com.google.common.base.Preconditions;
+import com.google.common.collect.ImmutableList;
+
+import java.util.List;
+
+/**
+ * ScalarFunction 'decode'. This class is generated by GenerateFunction.
+ */
+public class Decode extends ScalarFunction
+        implements BinaryExpression, ExplicitlyCastableSignature, 
PropagateNullable {
+
+    public static final List<FunctionSignature> SIGNATURES = ImmutableList.of(
+            
FunctionSignature.ret(StringType.INSTANCE).args(VarBinaryType.INSTANCE, 
StringType.INSTANCE)
+    );
+
+    /**
+     * constructor with 2 arguments.
+     */
+    public Decode(Expression binary, Expression characterSet) {
+        super("decode", binary, characterSet);
+    }
+
+    /** constructor for withChildren and reuse signature */
+    private Decode(ScalarFunctionParams functionParams) {
+        super(functionParams);
+    }
+
+    @Override
+    public void checkLegalityBeforeTypeCoercion() {
+        if (!getArgument(1).isConstant()) {
+            throw new AnalysisException("the second argument of function "
+                    + getName() + " must be constant: " + toSql());
+        }
+    }
+
+    // Invalid character sets must still be rejected when the first argument 
is a
+    // null literal. FoldConstantRuleOnFE otherwise rewrites PropagateNullable
+    // calls with any null child to NULL and skips backend evaluation.
+    @Override
+    public boolean foldable() {
+        return false;

Review Comment:
   [P2] Keep valid literal calls reachable by planner folding
   
   `FoldConstantRuleOnFE.visitBoundFunction()` calls `preProcess()` first, and 
that method returns this expression immediately when `foldable()` is false. 
Thus a real `OneRowRelation -> Project(decode(X'E4B8AD', 'UTF-8'))` plan never 
reaches the new `StringArithmetic.decode` implementation; the project remains a 
function instead of becoming `Project('δΈ­')`, so 
`PhysicalOneRowRelation.computeResultInFe()` cannot return the literal result 
without a BE. The new tests call `ExpressionEvaluator` directly, whose separate 
`isConstant()` gate bypasses this production path, so they do not prove planner 
folding. Please preserve invalid-charset-before-NULL behavior with targeted 
validation/folding instead of disabling folding for every input, and add a 
planner-level test; `Encode` has the same reachability problem.



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/Encode.java:
##########
@@ -0,0 +1,91 @@
+// 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.doris.nereids.trees.expressions.functions.scalar;
+
+import org.apache.doris.catalog.FunctionSignature;
+import org.apache.doris.nereids.exceptions.AnalysisException;
+import org.apache.doris.nereids.trees.expressions.Expression;
+import 
org.apache.doris.nereids.trees.expressions.functions.ExplicitlyCastableSignature;
+import org.apache.doris.nereids.trees.expressions.functions.PropagateNullable;
+import org.apache.doris.nereids.trees.expressions.shape.BinaryExpression;
+import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor;
+import org.apache.doris.nereids.types.StringType;
+import org.apache.doris.nereids.types.VarBinaryType;
+
+import com.google.common.base.Preconditions;
+import com.google.common.collect.ImmutableList;
+
+import java.util.List;
+
+/**
+ * ScalarFunction 'encode'. This class is generated by GenerateFunction.
+ */
+public class Encode extends ScalarFunction
+        implements BinaryExpression, ExplicitlyCastableSignature, 
PropagateNullable {
+
+    public static final List<FunctionSignature> SIGNATURES = ImmutableList.of(
+            
FunctionSignature.ret(VarBinaryType.INSTANCE).args(StringType.INSTANCE, 
StringType.INSTANCE)
+    );
+
+    /**
+     * constructor with 2 arguments.
+     */
+    public Encode(Expression source, Expression characterSet) {
+        super("encode", source, characterSet);
+    }
+
+    /** constructor for withChildren and reuse signature */
+    private Encode(ScalarFunctionParams functionParams) {
+        super(functionParams);
+    }
+
+    @Override
+    public void checkLegalityBeforeTypeCoercion() {
+        if (!getArgument(1).isConstant()) {

Review Comment:
   [P2] Preserve Hive's per-row charset contract
   
   This rejects `encode(payload, charset_name)` (and the equivalent `decode` 
call), but Hive treats a constant charset only as a cache optimization: 
[`GenericUDFEncode`](https://github.com/apache/hive/blob/master/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDFEncode.java#L71-L98)
 and 
[`GenericUDFDecode`](https://github.com/apache/hive/blob/master/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDFDecode.java#L80-L108)
 read argument 2 per row when it is not constant. Since this PR is advertised 
as Hive-compatible, migrated queries using a charset column now fail analysis 
instead of running. Please retain per-row charsets (the BE already has a 
bounded converter cache) and add mixed-charset/NULL regression coverage; 
otherwise narrow the API and release claim explicitly to constant-only charsets.



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