Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -408,25 +408,23 @@ public static List<Literal> getResultExpression(DataType type, PValues resultCon
int num = resultContent.getFloatValueCount();
for (int i = 0; i < num; ++i) {
float value = resultContent.getFloatValue(i);
Literal literal = null;
if (Float.isNaN(value)) {
literal = new NullLiteral(type);
return Collections.emptyList();
} else {
literal = new FloatLiteral(value);
Literal literal = new FloatLiteral(value);
res.add(literal);
}
res.add(literal);
}
} else if (type.isDoubleType()) {
int num = resultContent.getDoubleValueCount();
for (int i = 0; i < num; ++i) {
double value = resultContent.getDoubleValue(i);
Literal literal = null;
if (Double.isNaN(value)) {
literal = new NullLiteral(type);
return Collections.emptyList();
} else {
literal = new DoubleLiteral(value);
Literal literal = new DoubleLiteral(value);
res.add(literal);
}
res.add(literal);
}
} else if (type.isDecimalV2Type()) {
int num = resultContent.getBytesValueCount();
Expand Down Expand Up @@ -505,8 +503,13 @@ public static List<Literal> getResultExpression(DataType type, PValues resultCon
int childCount = resultContent.getChildElementCount();
List<Literal> allLiterals = new ArrayList<>();
for (int i = 0; i < childCount; ++i) {
allLiterals.addAll(getResultExpression(arrayType.getItemType(),
resultContent.getChildElement(i)));
List<Literal> resultExpression = getResultExpression(arrayType.getItemType(),
resultContent.getChildElement(i));
// If any child element couldn't fold, stop folding this Array.
if (resultExpression.isEmpty()) {
return Collections.emptyList();
}
allLiterals.addAll(resultExpression);
}
int offsetCount = resultContent.getChildOffsetCount();
if (offsetCount == 1) {
Expand All @@ -530,10 +533,19 @@ public static List<Literal> getResultExpression(DataType type, PValues resultCon
List<Literal> allKeys = new ArrayList<>();
List<Literal> allValues = new ArrayList<>();
for (int i = 0; i < childCount; i = i + 2) {
allKeys.addAll(getResultExpression(mapType.getKeyType(),
resultContent.getChildElement(i)));
allValues.addAll(getResultExpression(mapType.getValueType(),
resultContent.getChildElement(i + 1)));
// If any key or value couldn't fold, stop folding this Map.
List<Literal> key = getResultExpression(mapType.getKeyType(),
resultContent.getChildElement(i));
if (key.isEmpty()) {
return Collections.emptyList();
}
allKeys.addAll(key);
List<Literal> value = getResultExpression(mapType.getValueType(),
resultContent.getChildElement(i + 1));
if (value.isEmpty()) {
return Collections.emptyList();
}
allValues.addAll(value);
}
int offsetCount = resultContent.getChildOffsetCount();
if (offsetCount == 1) {
Expand All @@ -558,8 +570,13 @@ public static List<Literal> getResultExpression(DataType type, PValues resultCon
int childCount = resultContent.getChildElementCount();
List<List<Literal>> allFields = new ArrayList<>();
for (int i = 0; i < childCount; ++i) {
allFields.add(getResultExpression(structType.getFields().get(i).getDataType(),
resultContent.getChildElement(i)));
List<Literal> resultExpression = getResultExpression(structType.getFields().get(i).getDataType(),
resultContent.getChildElement(i));
// If any field couldn't fold, stop folding this Struct.
if (resultExpression.isEmpty()) {
return Collections.emptyList();
}
allFields.add(resultExpression);
}
for (int i = 0; i < allFields.get(0).size(); ++i) {
List<Literal> fields = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,14 @@ suite("fold_constant_by_be") {
sql "select IS_IPV4_MAPPED(NULLABLE(ipv6_string_to_num_or_default('192.168.1.1')));"
contains "192.168.1.1"
}
explain {
sql "select cosine_distance([0], [0]);"
contains "cosine_distance"
notContains("NULL")
}

explain {
sql "select array(cosine_distance([1], [1]), cast(\"NaN\" as float));"
contains "array(cosine_distance"
}
}