[fix](Nereids) build array and map literal expression failed (#27060)

1. empty array and map literal
2. multi-layer nested array and map literal
This commit is contained in:
morrySnow
2023-11-16 14:08:24 +08:00
committed by GitHub
parent d20441f002
commit 2b401785ce
5 changed files with 52 additions and 8 deletions

View File

@ -1905,11 +1905,15 @@ public class LogicalPlanBuilder extends DorisParserBaseVisitor<Object> {
* TODO remove this function after we refactor type coercion.
*/
private List<Literal> typeCoercionItems(List<Literal> items) {
DataType dataType = new Array(items.toArray(new Literal[0])).expectedInputTypes().get(0);
Array array = new Array(items.toArray(new Literal[0]));
if (array.expectedInputTypes().isEmpty()) {
return ImmutableList.of();
}
DataType dataType = array.expectedInputTypes().get(0);
return items.stream()
.map(item -> item.checkedCastTo(dataType))
.map(Literal.class::cast)
.collect(Collectors.toList());
.collect(ImmutableList.toImmutableList());
}
@Override

View File

@ -120,13 +120,14 @@ public interface ComputeSignature extends FunctionTrait, ImplicitCastInputTypes
/** use processor to process computeSignature */
static boolean processComplexType(DataType signatureType, DataType realType,
BiFunction<DataType, DataType, Boolean> processor) {
if (signatureType instanceof ArrayType && realType instanceof ArrayType) {
return processor.apply(((ArrayType) signatureType).getItemType(),
((ArrayType) realType).getItemType());
return processComplexType(((ArrayType) signatureType).getItemType(),
((ArrayType) realType).getItemType(), processor);
} else if (signatureType instanceof MapType && realType instanceof MapType) {
return processor.apply(((MapType) signatureType).getKeyType(), ((MapType) realType).getKeyType())
&& processor.apply(((MapType) signatureType).getValueType(), ((MapType) realType).getValueType());
return processComplexType(((MapType) signatureType).getKeyType(),
((MapType) realType).getKeyType(), processor)
&& processComplexType(((MapType) signatureType).getValueType(),
((MapType) realType).getValueType(), processor);
} else if (signatureType instanceof StructType && realType instanceof StructType) {
// TODO: do not support struct type now
// throw new AnalysisException("do not support struct type now");

View File

@ -33,6 +33,12 @@ import java.util.List;
public interface IdenticalSignature extends ComputeSignature {
/** isIdentical */
static boolean isIdentical(DataType signatureType, DataType realType) {
return ComputeSignature.processComplexType(
signatureType, realType, IdenticalSignature::isPrimitiveIdentical);
}
/** isIdentical */
static boolean isPrimitiveIdentical(DataType signatureType, DataType realType) {
try {
// TODO: copy matchesType to DataType
// TODO: resolve AnyDataType invoke toCatalogDataType

View File

@ -31,8 +31,14 @@ import java.util.List;
* when matching a particular instantiation. That is, their fixed arguments.
*/
public interface NullOrIdenticalSignature extends ComputeSignature {
/** isNullOrIdentical */
static boolean isNullOrIdentical(DataType signatureType, DataType realType) {
return ComputeSignature.processComplexType(
signatureType, realType, NullOrIdenticalSignature::isPrimitiveNullOrIdentical);
}
/** isNullOrIdentical */
static boolean isPrimitiveNullOrIdentical(DataType signatureType, DataType realType) {
try {
// TODO: copy matchesType to DataType
// TODO: resolve AnyDataType invoke toCatalogDataType