xy720 commented on code in PR #16948: URL: https://github.com/apache/doris/pull/16948#discussion_r1111890046
########## 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"); + } + valueType = Type.getAssignmentCompatibleType(valueType, exprs[idx + 1].getType(), true); + if (valueType == Type.INVALID) { + throw new AnalysisException("Invalid value type in Map"); } - children.add(expr); - ++ idx; + children.add(exprs[idx]); + children.add(exprs[idx + 1]); Review Comment: Just a example: ``` for (int idx = 0; idx < exprs.length && idx + 1 < exprs.length; idx += 2) { if (MapType.supportKeyType(exprs[idx].getType())) { throw new AnalysisException("Invalid key type in Map, not support " + keyType); } keyType = Type.getAssignmentCompatibleType(keyType, exprs[idx].getType(), true); valueType = Type.getAssignmentCompatibleType(valueType, exprs[idx + 1].getType(), true); } if (keyType == Type.INVALID) { throw new AnalysisException("Invalid key type in Map."); } if (valueType == Type.INVALID) { throw new AnalysisException("Invalid value type in Map."); } for (int idx = 0; idx < exprs.length && idx + 1 < exprs.length; idx += 2) { if (exprs[idx].getType().equals(keyType)) { children.add(expr[idx]); } else { children.add(expr[idx].castTo(keyType)); } if (exprs[idx+1].getType().equals(valueType)) { children.add(expr[idx+1]); } else { children.add(expr[idx+1].castTo(valueType)); } } ``` ########## 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、Types such as float、double、bitmap、hll is also scala type but shouldn't be key type. 3、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