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


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/spm/matcher/SPMFrozenTreeReplacer.java:
##########
@@ -0,0 +1,247 @@
+// 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.spm.matcher;
+
+import org.apache.doris.nereids.analyzer.UnboundFunction;
+import org.apache.doris.nereids.spm.SPMPlanTreeSupport;
+import org.apache.doris.nereids.spm.placeholder.SPMSubquerySupport;
+import org.apache.doris.nereids.spm.placeholder.SpmConstList;
+import org.apache.doris.nereids.trees.expressions.Expression;
+import org.apache.doris.nereids.trees.expressions.InPredicate;
+import org.apache.doris.nereids.trees.expressions.InSubquery;
+import org.apache.doris.nereids.trees.expressions.SubqueryExpr;
+import org.apache.doris.nereids.trees.expressions.literal.Literal;
+import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor;
+import org.apache.doris.nereids.trees.plans.logical.LogicalPlan;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Replaces unqualified marker function calls in a parsed frozen plan 
expression. Scalar ids select matched
+ * expressions; a list marker inside an IN predicate selects replacement 
options. Outer casts and operators remain
+ * in place. The caller checks for unresolved marker calls before using the 
rewritten plan.
+ */
+public class SPMFrozenTreeReplacer extends ExpressionVisitor<Expression, 
Map<Long, Expression>> {
+
+    /** Function name of the scalar placeholder as printed into the frozen 
planSql. */
+    public static final String CONST_VAR_FUNC = "_spm_const_var";
+
+    /** Function name of the IN-list placeholder as printed into the frozen 
planSql. */
+    public static final String CONST_LIST_FUNC = "_spm_const_list";
+
+    /**
+     * Returns whether the expression is a frozen-tree placeholder call
+     * (_spm_const_var(id) / _spm_const_list(id)) that was NOT substituted
+     * such an expression must never reach the analyzer (the function is not 
registered),
+     * so a rewritten tree containing one must be rejected by the caller.
+     */
+    public static boolean isUnsubstitutedPlaceholder(Expression expr) {
+        if (expr instanceof UnboundFunction) {
+            UnboundFunction function = (UnboundFunction) expr;
+            // The marker is emitted by SPM itself, ALWAYS as an unqualified 
call. A
+            // QUALIFIED call such as db._spm_const_var(1) is a legal user UDF 
reference:
+            // classifying it as a placeholder would let the replacer replace 
the whole
+            // real function call by the user's literal (returning the literal 
instead of
+            // evaluating the UDF). Provenance (BaselinePlan.planFrozen) is 
the primary
+            // guard; this name + namespace check keeps the legacy parse-based 
fallback
+            // from forging a frozen tree out of ordinary raw-fallback text.
+            String dbName = function.getDbName();
+            if (dbName != null && !dbName.isEmpty()) {
+                return false;
+            }
+            String name = function.getName();
+            if (!CONST_VAR_FUNC.equals(name) && !CONST_LIST_FUNC.equals(name)) 
{
+                return false;
+            }
+            // SPM emits a single integer-literal id argument. A GLOBAL
+            // user UDF may legally be named _spm_const_var (an unqualified 
call has no
+            // namespace), and _spm_const_var(k) is exactly such a call - 
classifying it
+            // as an unresolved marker made the residue scan reject a 
perfectly replayable
+            // frozen plan (which, once persisted, has no parameterized-tree 
fallback and
+            // silently stops applying).
+            return placeholderId(function) != null;

Review Comment:
   [P2] Require exact marker arity for legacy frozen rows. When `planFrozen` is 
absent, `isFrozenPlanSql` classifies any unqualified 
`_spm_const_var`/`_spm_const_list` call whose first argument is numeric as an 
SPM marker, because `placeholderId` ignores extra arguments and integer type. A 
legitimate legacy UDF such as `_spm_const_var(1, 7)` is then replaced wholesale 
by the caller's value instead of invoking the UDF. Require exactly one integer 
literal marker argument or keep ambiguous legacy text on the raw/parameterized 
path.



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