Skip to content

Commit b6941b9

Browse files
committed
[fix](fe) Restrict multi distinct count variant check
### What problem does this PR solve? Issue Number: close #25672 Related PR: None Problem Summary: The previous variant fix made MultiDistinctCount reuse the full COUNT DISTINCT argument check, which also rejects complex types. Existing P0 cases use multi_distinct_count on ARRAY values, so that broader check caused regressions. Keep the existing COUNT DISTINCT complex-type validation for Count, but make MultiDistinctCount only apply the new VARIANT rejection. ### Release note None ### Check List (For Author) - Test: Unit Test - `./run-fe-ut.sh --run org.apache.doris.nereids.trees.expressions.functions.agg.CountTest` - Behavior changed: No - Does this need documentation: No
1 parent c6d04c1 commit b6941b9

3 files changed

Lines changed: 18 additions & 5 deletions

File tree

fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/Count.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,15 +99,20 @@ public void checkLegalityAfterRewrite() {
9999
}
100100

101101
static void checkDistinctArgument(Expression argument, String functionSql) {
102+
checkVariantArgument(argument, functionSql);
103+
DataType argumentType = argument.getDataType();
104+
if (argumentType.isComplexType() || argumentType.isObjectType() || argumentType.isJsonType()) {
105+
throw new AnalysisException("COUNT DISTINCT could not process type " + functionSql);
106+
}
107+
}
108+
109+
static void checkVariantArgument(Expression argument, String functionSql) {
102110
DataType argumentType = argument.getDataType();
103111
if (argumentType.isVariantType()) {
104112
throw new AnalysisException("COUNT DISTINCT does not support VARIANT argument in " + functionSql
105113
+ ". Cast the VARIANT expression to STRING or another supported scalar type before using "
106114
+ "COUNT DISTINCT.");
107115
}
108-
if (argumentType.isComplexType() || argumentType.isObjectType() || argumentType.isJsonType()) {
109-
throw new AnalysisException("COUNT DISTINCT could not process type " + functionSql);
110-
}
111116
}
112117

113118
public boolean isStar() {

fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/MultiDistinctCount.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ private MultiDistinctCount(boolean distinct, List<Expression> children) {
5858
throw new AnalysisException("MultiDistinctCount's children size must be 1");
5959
}
6060
for (Expression argument : super.children()) {
61-
Count.checkDistinctArgument(argument, "COUNT DISTINCT " + argument.toSql());
61+
Count.checkVariantArgument(argument, "COUNT DISTINCT " + argument.toSql());
6262
}
6363
}
6464

@@ -71,7 +71,7 @@ protected MultiDistinctCount(AggregateFunctionParams functionParams) {
7171
public MultiDistinctCount withDistinctAndChildren(boolean distinct, List<Expression> children) {
7272
Preconditions.checkArgument(children.size() == 1, "MultiDistinctCount's children size must be 1");
7373
for (Expression argument : children) {
74-
Count.checkDistinctArgument(argument, "COUNT DISTINCT " + argument.toSql());
74+
Count.checkVariantArgument(argument, "COUNT DISTINCT " + argument.toSql());
7575
}
7676
return new MultiDistinctCount(getFunctionParams(false, children));
7777
}

fe/fe-core/src/test/java/org/apache/doris/nereids/trees/expressions/functions/agg/CountTest.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919

2020
import org.apache.doris.nereids.exceptions.AnalysisException;
2121
import org.apache.doris.nereids.trees.expressions.SlotReference;
22+
import org.apache.doris.nereids.types.ArrayType;
23+
import org.apache.doris.nereids.types.IntegerType;
2224
import org.apache.doris.nereids.types.VariantType;
2325

2426
import org.junit.jupiter.api.Assertions;
@@ -42,4 +44,10 @@ void testMultiDistinctCountRejectsVariant() {
4244
Assertions.assertTrue(exception.getMessage().contains("COUNT DISTINCT does not support VARIANT argument"));
4345
Assertions.assertTrue(exception.getMessage().contains("Cast the VARIANT expression"));
4446
}
47+
48+
@Test
49+
void testMultiDistinctCountAllowsArray() {
50+
Assertions.assertDoesNotThrow(
51+
() -> new MultiDistinctCount(SlotReference.of("arr", ArrayType.of(IntegerType.INSTANCE))));
52+
}
4553
}

0 commit comments

Comments
 (0)