xy720 commented on code in PR #17344:
URL: https://github.com/apache/doris/pull/17344#discussion_r1126075820


##########
fe/fe-common/src/main/java/org/apache/doris/catalog/TemplateType.java:
##########
@@ -0,0 +1,132 @@
+// 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.catalog;
+
+import org.apache.doris.thrift.TColumnType;
+import org.apache.doris.thrift.TTypeDesc;
+
+import com.google.common.base.Strings;
+import com.google.gson.annotations.SerializedName;
+
+import java.util.Map;
+
+/**
+ * Describes a TemplateType type, used for SQL function argument and return 
type,
+ *  NOT used for table column type.
+ */
+public class TemplateType extends Type {
+
+    @SerializedName(value = "name")
+    private final String name;
+
+    public TemplateType(String name) {
+        this.name = name;
+    }
+
+    @Override
+    public PrimitiveType getPrimitiveType() {
+        return PrimitiveType.TEMPLATE;
+    }
+
+    @Override
+    public boolean equals(Object other) {
+        if (!(other instanceof TemplateType)) {
+            return false;
+        }
+        TemplateType o = (TemplateType) other;
+        return o.name.equals(name);
+    }
+
+    @Override
+    public boolean matchesType(Type t) {
+        // not matches any type
+        return false;
+    }
+
+    @Override
+    public boolean hasTemplateType() {
+        return true;
+    }
+
+    @Override
+    public Type specializeTemplateType(Type specificType, Map<String, Type> 
specializedTypeMap,
+                                       boolean useSpecializedType) throws 
TypeException {
+        if (specificType.hasTemplateType() && !specificType.isNull()) {
+            throw new TypeException(specificType + " should not 
hasTemplateType");
+        }
+
+        Type specializedType = specializedTypeMap.get(name);
+        if (useSpecializedType) {
+            if (specializedType == null) {
+                throw new TypeException("template type " + name + " is not 
specialized yet");
+            }
+            return specializedType;
+        }
+
+        if (specializedType != null
+                && !specificType.equals(specializedType)
+                && !specificType.matchesType(specializedType)
+                && !Type.isImplicitlyCastable(specificType, specializedType, 
true)
+                && !Type.canCastTo(specificType, specializedType)) {
+            throw new TypeException(
+                String.format("can not specialize template type %s to %s since 
it's already specialized as %s",
+                    name, specificType, specializedType));
+        }
+
+        if (specializedType == null) {

Review Comment:
   As discussion, when specializedType != null
   specializedTypeMap should store the CompatibleType of specificType and 
specializedType.
   You can use `Type.getAssignmentCompatibleType` method.



-- 
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-unsubscr...@doris.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org
For additional commands, e-mail: commits-h...@doris.apache.org

Reply via email to