[Improve](map-type) Add contains_null for map (#16948)

Add contains_null for map type.
This commit is contained in:
amory
2023-02-23 20:47:26 +08:00
committed by GitHub
parent c416bfbaef
commit 7229751bd9
13 changed files with 125 additions and 73 deletions

View File

@ -24,6 +24,7 @@ import org.apache.doris.thrift.TTypeNodeType;
import com.google.common.base.Preconditions;
import com.google.common.base.Strings;
import com.google.common.collect.Lists;
import com.google.gson.annotations.SerializedName;
import java.util.Objects;
@ -138,7 +139,7 @@ public class ArrayType extends Type {
container.types.add(node);
Preconditions.checkNotNull(itemType);
node.setType(TTypeNodeType.ARRAY);
node.setContainsNull(containsNull);
node.setContainsNulls(Lists.newArrayList(containsNull));
itemType.toThrift(container);
}

View File

@ -24,6 +24,7 @@ import org.apache.doris.thrift.TTypeNodeType;
import com.google.common.base.Preconditions;
import com.google.common.base.Strings;
import com.google.common.collect.Lists;
import com.google.gson.annotations.SerializedName;
import java.util.Objects;
@ -35,19 +36,30 @@ public class MapType extends Type {
@SerializedName(value = "keyType")
private final Type keyType;
@SerializedName(value = "isKeyContainsNull")
private final boolean isKeyContainsNull; // Now always true
@SerializedName(value = "valueType")
private final Type valueType;
@SerializedName(value = "isValueContainsNull")
private final boolean isValueContainsNull; // Now always true
public MapType() {
this.keyType = NULL;
this.isKeyContainsNull = true;
this.valueType = NULL;
this.isValueContainsNull = true;
}
public MapType(Type keyType, Type valueType) {
Preconditions.checkNotNull(keyType);
Preconditions.checkNotNull(valueType);
this.keyType = keyType;
this.isKeyContainsNull = true;
this.valueType = valueType;
this.isValueContainsNull = true;
}
@Override
@ -59,6 +71,14 @@ public class MapType extends Type {
return keyType;
}
public Boolean getIsKeyContainsNull() {
return isKeyContainsNull;
}
public Boolean getIsValueContainsNull() {
return isValueContainsNull;
}
public Type getValueType() {
return valueType;
}
@ -141,6 +161,7 @@ public class MapType extends Type {
Preconditions.checkNotNull(keyType);
Preconditions.checkNotNull(valueType);
node.setType(TTypeNodeType.MAP);
node.setContainsNulls(Lists.newArrayList(isKeyContainsNull, isValueContainsNull));
keyType.toThrift(container);
valueType.toThrift(container);
}

View File

@ -194,6 +194,7 @@ public abstract class Type {
mapSubTypes.add(CHAR);
mapSubTypes.add(VARCHAR);
mapSubTypes.add(STRING);
mapSubTypes.add(NULL);
structSubTypes = Lists.newArrayList();
structSubTypes.add(BOOLEAN);
@ -606,7 +607,7 @@ public abstract class Type {
&& !sourceType.isNull()) {
// TODO: current not support cast any non-array type(except for null) to nested array type.
return false;
} else if (targetType.isStructType() && sourceType.isStringType()) {
} else if ((targetType.isStructType() || targetType.isMapType()) && sourceType.isStringType()) {
return true;
} else if (sourceType.isStructType() && targetType.isStructType()) {
return StructType.canCastTo((StructType) sourceType, (StructType) targetType);