github-actions[bot] commented on code in PR #62201:
URL: https://github.com/apache/doris/pull/62201#discussion_r3051073229
##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/CreateMap.java:
##########
@@ -109,12 +115,78 @@ public List<FunctionSignature> getSignatures() {
if (arity() == 0) {
return SIGNATURES;
} else {
- return ImmutableList.of(FunctionSignature.of(
- getDataType(),
- children.stream()
- .map(ExpressionTrait::getDataType)
- .collect(ImmutableList.toImmutableList())
- ));
+ // split children into keys and values
+ List<Expression> keyExpressions = new ArrayList<>();
+ List<Expression> valueExpressions = new ArrayList<>();
+ for (int i = 0; i < children.size(); i++) {
+ if (i % 2 == 0) {
+ keyExpressions.add(children.get(i));
+ } else {
+ valueExpressions.add(children.get(i));
+ }
+ }
+
+ // find common key type
+ Map<Boolean, List<Expression>> keyPartitioned =
keyExpressions.stream()
+ .collect(Collectors.partitioningBy(
+ e -> (e instanceof Literal && ((Literal)
e).isStringLikeLiteral())));
+ List<DataType> keyForFindCommon =
keyPartitioned.get(false).stream()
+
.map(ExpressionTrait::getDataType).collect(Collectors.toList());
+ Optional<DataType> commonKeyType =
TypeCoercionUtils.findWiderCommonTypeByVariable(
+ keyForFindCommon, false, true);
+ if (!commonKeyType.isPresent()) {
+
SearchSignature.throwCanNotFoundFunctionException(this.getName(),
getArguments());
+ } else {
+ for (Expression stringLiteral : keyPartitioned.get(true)) {
Review Comment:
`characterLiteralTypeCoercion(...).isPresent()` is not a strong enough
compatibility check here. It only proves that the string can be parsed into
*some* literal, not that it still fits `commonKeyType`. For example,
`map(cast(1 as tinyint), 'v1', '300', 'v2')` sets `commonKeyType` to `tinyint`,
and `characterLiteralTypeCoercion("300", tinyint)` returns a `SmallIntLiteral`,
so this branch keeps `tinyint` instead of widening. The later implicit cast
then tries to force `'300'` into `tinyint`, which regresses the previous
`Array`-based coercion behavior. The same problem is duplicated in the value
loop below.
--
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]