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 @@ -159,6 +159,10 @@ public void testKind1OutputTypeRestrict() {
"select case when s1<=0 then true else 22 end from table1",
"701: All CASE results must be the same type or coercible to a common type. Cannot find common type between BOOLEAN and INT32, all types (without duplicates): [BOOLEAN, INT32]",
DATABASE);
tableAssertTestFail(
"select case when s1<=0 then 0 when s1>1 then null end from table1",
"701: All result types must be the same:",
DATABASE);

// TEXT and other types cannot exist at the same time
retArray = new String[] {"good,", "bad,", "okok,", "okok,"};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;

import static com.google.common.base.Preconditions.checkArgument;
Expand Down Expand Up @@ -228,7 +228,7 @@ protected Type visitIfExpression(IfExpression node, Context context) {

@Override
protected Type visitSearchedCaseExpression(SearchedCaseExpression node, Context context) {
Set<Type> resultTypes =
LinkedHashSet<Type> resultTypes =
node.getWhenClauses().stream()
.map(
clause -> {
Expand All @@ -239,9 +239,12 @@ protected Type visitSearchedCaseExpression(SearchedCaseExpression node, Context
operandType);
return setExpressionType(clause, process(clause.getResult(), context));
})
.collect(Collectors.toSet());
.collect(Collectors.toCollection(LinkedHashSet::new));

checkArgument(resultTypes.size() == 1, "All result types must be the same: %s", resultTypes);
if (resultTypes.size() != 1) {
throw new SemanticException(
String.format("All result types must be the same: %s", resultTypes));
}
Type resultType = resultTypes.iterator().next();
node.getDefaultValue()
.ifPresent(
Expand All @@ -261,7 +264,7 @@ protected Type visitSearchedCaseExpression(SearchedCaseExpression node, Context
protected Type visitSimpleCaseExpression(SimpleCaseExpression node, Context context) {
Type operandType = process(node.getOperand(), context);

Set<Type> resultTypes =
LinkedHashSet<Type> resultTypes =
node.getWhenClauses().stream()
.map(
clause -> {
Expand All @@ -273,9 +276,13 @@ protected Type visitSimpleCaseExpression(SimpleCaseExpression node, Context cont
operandType);
return setExpressionType(clause, process(clause.getResult(), context));
})
.collect(Collectors.toSet());
.collect(Collectors.toCollection(LinkedHashSet::new));

if (resultTypes.size() != 1) {
throw new SemanticException(
String.format("All result types must be the same: %s", resultTypes));
}

checkArgument(resultTypes.size() == 1, "All result types must be the same: %s", resultTypes);
Type resultType = resultTypes.iterator().next();
node.getDefaultValue()
.ifPresent(
Expand All @@ -293,12 +300,15 @@ protected Type visitSimpleCaseExpression(SimpleCaseExpression node, Context cont

@Override
protected Type visitCoalesceExpression(CoalesceExpression node, Context context) {
Set<Type> types =
LinkedHashSet<Type> types =
node.getOperands().stream()
.map(operand -> process(operand, context))
.collect(Collectors.toSet());
.collect(Collectors.toCollection(LinkedHashSet::new));

checkArgument(types.size() == 1, "All operands must have the same type: %s", types);
if (types.size() != 1) {
throw new SemanticException(
String.format("All operands must have the same type: %s", types));
}
return setExpressionType(node, types.iterator().next());
}

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@
<thrift.version>0.14.1</thrift.version>
<xz.version>1.9</xz.version>
<zstd-jni.version>1.5.6-3</zstd-jni.version>
<tsfile.version>2.2.0-250722-SNAPSHOT</tsfile.version>
<tsfile.version>2.2.0-250730-SNAPSHOT</tsfile.version>
</properties>
<!--
if we claim dependencies in dependencyManagement, then we do not claim
Expand Down
Loading