amorynan commented on code in PR #15966:
URL: https://github.com/apache/doris/pull/15966#discussion_r1089863363


##########
fe/fe-core/src/main/java/org/apache/doris/analysis/MapLiteral.java:
##########
@@ -0,0 +1,179 @@
+// 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.analysis;
+
+import org.apache.doris.catalog.MapType;
+import org.apache.doris.catalog.Type;
+import org.apache.doris.common.AnalysisException;
+import org.apache.doris.thrift.TExprNode;
+import org.apache.doris.thrift.TExprNodeType;
+import org.apache.doris.thrift.TTypeDesc;
+import org.apache.doris.thrift.TTypeNode;
+
+import org.apache.commons.lang.StringUtils;
+
+import java.io.DataInput;
+import java.io.DataOutput;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+
+// INSERT INTO table_map VALUES ({'key1':1, 'key2':10, 'k3':100}), 
({'key1':2,'key2':20}), ({'key1':3,'key2':30});
+// MapLiteral is one row-based literal
+public class MapLiteral extends LiteralExpr {
+
+    public MapLiteral() {
+        type = new MapType(Type.NULL, Type.NULL);
+        children = new ArrayList<>();
+    }
+
+    public MapLiteral(LiteralExpr... exprs) throws AnalysisException {
+        Type keyType = Type.NULL;
+        Type valueType = Type.NULL;
+        children = new ArrayList<>();
+        int idx = 0;
+        for (LiteralExpr expr : exprs) {
+            if (idx % 2 == 0) {
+                if (keyType == Type.NULL) {
+                    keyType = expr.getType();
+                } else {
+                    keyType = Type.getAssignmentCompatibleType(keyType, 
expr.getType(), false);
+                }
+                if (keyType == Type.INVALID) {
+                    throw new AnalysisException("Invalid element type in Map");
+                }
+            } else {
+                if (valueType == Type.NULL) {
+                    valueType = expr.getType();
+                } else {
+                    valueType = Type.getAssignmentCompatibleType(valueType, 
expr.getType(), false);
+                }
+                if (valueType == Type.INVALID) {
+                    throw new AnalysisException("Invalid element type in Map");
+                }
+            }
+            children.add(expr);
+            ++ idx;
+        }
+
+        type = new MapType(keyType, valueType);
+    }
+
+    protected MapLiteral(MapLiteral other) {
+        super(other);
+    }
+
+    @Override
+    public Expr uncheckedCastTo(Type targetType) throws AnalysisException {
+        if (!targetType.isMapType()) {
+            return super.uncheckedCastTo(targetType);
+        }
+        MapLiteral literal = new MapLiteral(this);
+        Type keyType = ((MapType) targetType).getKeyType();
+        Type valueType = ((MapType) targetType).getValueType();
+
+        for (int i = 0; i < children.size(); ++ i) {
+            Expr child = children.get(i);
+            if ((i & 1) == 0) {

Review Comment:
   done!



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