Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
924060929 committed Dec 11, 2024
1 parent d6fbc8a commit 0423c37
Showing 1 changed file with 25 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,15 @@ public void computeFd(DataTrait.Builder builder) {
public static Pair<List<List<NamedExpression>>, List<Boolean>> castCommonDataTypeAndNullableByConstants(
List<List<NamedExpression>> constantExprsList) {
int columnCount = constantExprsList.isEmpty() ? 0 : constantExprsList.get(0).size();
Pair<List<DataType>, List<Boolean>> commonInfo
= computeCommonDataTypeAndNullable(constantExprsList, columnCount);
List<List<NamedExpression>> castedRows = castToCommonType(constantExprsList, commonInfo.key(), columnCount);
List<Boolean> nullables = commonInfo.second;
return Pair.of(castedRows, nullables);
}

private static Pair<List<DataType>, List<Boolean>> computeCommonDataTypeAndNullable(
List<List<NamedExpression>> constantExprsList, int columnCount) {
List<Boolean> nullables = Lists.newArrayList();
List<DataType> commonDataTypes = Lists.newArrayListWithCapacity(columnCount);
for (int columnId = 0; columnId < columnCount; columnId++) {
Expand All @@ -312,19 +320,29 @@ public static Pair<List<List<NamedExpression>>, List<Boolean>> castCommonDataTyp
nullables.add(nullable);
commonDataTypes.add(commonDataType);
}
return Pair.of(commonDataTypes, nullables);
}

private static List<List<NamedExpression>> castToCommonType(
List<List<NamedExpression>> rows, List<DataType> commonDataTypes, int columnCount) {
ImmutableList.Builder<List<NamedExpression>> castedConstants
= ImmutableList.builderWithExpectedSize(constantExprsList.size());
for (List<NamedExpression> row : constantExprsList) {
= ImmutableList.builderWithExpectedSize(rows.size());
for (List<NamedExpression> row : rows) {
ImmutableList.Builder<NamedExpression> castedRow = ImmutableList.builderWithExpectedSize(columnCount);
for (int i = 0; i < row.size(); i++) {
NamedExpression constant = row.get(i);
castedRow.add((NamedExpression) constant.withChildren(
TypeCoercionUtils.castIfNotSameTypeStrict(constant, commonDataTypes.get(i))
));
NamedExpression constantAlias = row.get(i);
DataType commonType = commonDataTypes.get(i);
Expression constant = constantAlias.child(0);
if (commonType.equals(constant.getDataType())) {
castedRow.add(constantAlias);
} else {
Expression expression
= TypeCoercionUtils.castIfNotSameTypeStrict(constant, commonType);
castedRow.add((NamedExpression) constant.withChildren(expression));
}
}
castedConstants.add(castedRow.build());
}
return Pair.of(castedConstants.build(), nullables);
return castedConstants.build();
}
}

0 comments on commit 0423c37

Please sign in to comment.