Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX](complextype) fxi array nested struct literal #26778

Merged
merged 3 commits into from
Nov 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions be/src/olap/rowset/segment_v2/column_reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ Status ColumnReader::create(const ColumnReaderOptions& opts, const ColumnMetaPB&
case FieldType::OLAP_FIELD_TYPE_STRUCT: {
// not support empty struct
DCHECK(meta.children_columns_size() >= 1);
num_rows = meta.children_columns(0).num_rows();
// create struct column reader
std::unique_ptr<ColumnReader> struct_reader(
new ColumnReader(opts, meta, num_rows, file_reader));
Expand Down
10 changes: 10 additions & 0 deletions fe/fe-common/src/main/java/org/apache/doris/catalog/ArrayType.java
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,16 @@ public static boolean canCastTo(ArrayType type, ArrayType targetType) {
return Type.canCastTo(type.getItemType(), targetType.getItemType());
}

public static Type getAssignmentCompatibleType(ArrayType t1, ArrayType t2, boolean strict) {
Type itemCompatibleType = Type.getAssignmentCompatibleType(t1.getItemType(), t2.getItemType(), strict);

if (itemCompatibleType.isInvalid()) {
return ScalarType.INVALID;
}

return new ArrayType(itemCompatibleType, t1.getContainsNull() || t2.getContainsNull());
}

@Override
public void toThrift(TTypeDesc container) {
TTypeNode node = new TTypeNode();
Expand Down
15 changes: 15 additions & 0 deletions fe/fe-common/src/main/java/org/apache/doris/catalog/MapType.java
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,21 @@ public static boolean canCastTo(MapType type, MapType targetType) {
|| targetType.getValueType().isStringType() && type.getValueType().isStringType());
}

public static Type getAssignmentCompatibleType(MapType t1, MapType t2, boolean strict) {
Type keyCompatibleType = Type.getAssignmentCompatibleType(t1.getKeyType(), t2.getKeyType(), strict);
if (keyCompatibleType.isInvalid()) {
return ScalarType.INVALID;
}
Type valCompatibleType = Type.getAssignmentCompatibleType(t1.getValueType(), t2.getValueType(), strict);
if (valCompatibleType.isInvalid()) {
return ScalarType.INVALID;
}

return new MapType(keyCompatibleType, valCompatibleType,
t1.getIsKeyContainsNull() || t2.getIsKeyContainsNull(),
t1.getIsValueContainsNull() || t2.getIsValueContainsNull());
}

@Override
public boolean supportSubType(Type subType) {
for (Type supportedType : Type.getMapSubTypes()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.gson.annotations.SerializedName;
import org.apache.commons.lang3.StringUtils;

import java.util.ArrayList;
import java.util.Arrays;
Expand Down Expand Up @@ -110,6 +111,29 @@ public static boolean canCastTo(StructType type, StructType targetType) {
return true;
}

public static Type getAssignmentCompatibleType(StructType t1, StructType t2, boolean strict) {
ArrayList<StructField> fieldsLeft = t1.getFields();
ArrayList<StructField> fieldsRight = t2.getFields();
ArrayList<StructField> fieldsRes = new ArrayList<>();

for (int i = 0; i < t1.getFields().size(); ++i) {
StructField leftField = fieldsLeft.get(i);
StructField rightField = fieldsRight.get(i);
Type itemCompatibleType = Type.getAssignmentCompatibleType(leftField.getType(), rightField.getType(),
strict);
if (itemCompatibleType.isInvalid()) {
return ScalarType.INVALID;
}
fieldsRes.add(new StructField(StringUtils.isEmpty(leftField.getName()) ? rightField.getName()
: leftField.getName(),
itemCompatibleType, StringUtils.isEmpty(leftField.getComment()) ? rightField.getComment()
: leftField.getComment(), leftField.getContainsNull() || rightField.getContainsNull()));

}

return new StructType(fieldsRes);
}

@Override
public boolean isSupported() {
for (StructField f : fields) {
Expand Down
27 changes: 10 additions & 17 deletions fe/fe-common/src/main/java/org/apache/doris/catalog/Type.java
Original file line number Diff line number Diff line change
Expand Up @@ -746,19 +746,14 @@ public static Type getAssignmentCompatibleType(Type t1, Type t2, boolean strict)
}

if (t1.isArrayType() && t2.isArrayType()) {
ArrayType arrayType1 = (ArrayType) t1;
ArrayType arrayType2 = (ArrayType) t2;
Type itemCompatibleType = Type.getAssignmentCompatibleType(arrayType1.getItemType(),
arrayType2.getItemType(), strict);

if (itemCompatibleType.isInvalid()) {
return itemCompatibleType;
}

return new ArrayType(itemCompatibleType, arrayType1.getContainsNull() || arrayType2.getContainsNull());
} else if (t1.isArrayType() && t2.isNull()) {
return ArrayType.getAssignmentCompatibleType((ArrayType) t1, (ArrayType) t2, strict);
} else if (t1.isMapType() && t2.isMapType()) {
return MapType.getAssignmentCompatibleType((MapType) t1, (MapType) t2, strict);
} else if (t1.isStructType() && t2.isStructType()) {
return StructType.getAssignmentCompatibleType((StructType) t1, (StructType) t2, strict);
} else if (t1.isComplexType() && t2.isNull()) {
return t1;
} else if (t1.isNull() && t2.isArrayType()) {
} else if (t1.isNull() && t2.isComplexType()) {
return t2;
}

Expand Down Expand Up @@ -1963,17 +1958,15 @@ public static boolean matchExactType(Type type1, Type type2, boolean ignorePreci
} else if (type2.isArrayType()) {
// For types array, we also need to check contains null for case like
// cast(array<not_null(int)> as array<int>)
if (!((ArrayType) type2).getContainsNull() == ((ArrayType) type1).getContainsNull()) {
if (((ArrayType) type2).getContainsNull() != ((ArrayType) type1).getContainsNull()) {
return false;
}
return matchExactType(((ArrayType) type2).getItemType(), ((ArrayType) type1).getItemType());
} else if (type2.isMapType()) {
// For types array, we also need to check contains null for case like
// cast(array<not_null(int)> as array<int>)
if (!((MapType) type2).getIsKeyContainsNull() == ((MapType) type1).getIsKeyContainsNull()) {
if (((MapType) type2).getIsKeyContainsNull() != ((MapType) type1).getIsKeyContainsNull()) {
return false;
}
if (!((MapType) type2).getIsValueContainsNull() == ((MapType) type1).getIsValueContainsNull()) {
if (((MapType) type2).getIsValueContainsNull() != ((MapType) type1).getIsValueContainsNull()) {
return false;
}
return matchExactType(((MapType) type2).getKeyType(), ((MapType) type1).getKeyType())
Expand Down

This file was deleted.

This file was deleted.

Loading