xy720 commented on code in PR #16948: URL: https://github.com/apache/doris/pull/16948#discussion_r1111821110
########## fe/fe-core/src/main/java/org/apache/doris/analysis/MapLiteral.java: ########## @@ -47,30 +47,18 @@ public MapLiteral(LiteralExpr... exprs) throws AnalysisException { Type keyType = Type.NULL; Type valueType = Type.NULL; children = new ArrayList<>(); - int idx = 0; - // TODO(xy): limit key type to scalar type - for (LiteralExpr expr : exprs) { - if (idx % 2 == 0) { - if (keyType == Type.NULL) { - keyType = expr.getType(); - } else { - keyType = Type.getAssignmentCompatibleType(keyType, expr.getType(), true); - } - 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(), true); - } - if (valueType == Type.INVALID) { - throw new AnalysisException("Invalid element type in Map"); - } + for (int idx = 0; idx < exprs.length && idx + 1 < exprs.length; idx += 2) { + // limit key type to scalar type + keyType = Type.getAssignmentCompatibleType(keyType, exprs[idx].getType(), true); + if (keyType == Type.INVALID || !keyType.isScalarType()) { + throw new AnalysisException("Invalid key type in Map Only support scalar type"); Review Comment: 1、Put this error outside the loop. 2、When the exprs are all scala types, this error may still be thrown. 3、Types such as float、double、bitmap、hll is also scala type but shouldn't be key type. 4、Users may be don't know what is `scala type`. Use actual type in msg. -- 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