This is an automated email from the ASF dual-hosted git repository.
yiguolei pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/master by this push:
new cdef7752861 [fix](multi_distinct_count) fix wrong result of
multi_distinct_count of datetime (#58775)
cdef7752861 is described below
commit cdef77528610cd1aae2903e741bee5cc966e260c
Author: TengJianPing <[email protected]>
AuthorDate: Mon Dec 8 09:02:30 2025 +0800
[fix](multi_distinct_count) fix wrong result of multi_distinct_count of
datetime (#58775)
### What problem does this PR solve?
Issue Number: close #xxx
Related PR: #xxx
Problem Summary:
### Release note
None
### Check List (For Author)
- Test <!-- At least one of them must be included. -->
- [ ] Regression test
- [ ] Unit Test
- [ ] Manual test (add detailed scripts or steps below)
- [ ] No need to test or manual test. Explain why:
- [ ] This is a refactor/code format and no logic has been changed.
- [ ] Previous test can cover this change.
- [ ] No code files have been changed.
- [ ] Other reason <!-- Add your reason? -->
- Behavior changed:
- [ ] No.
- [ ] Yes. <!-- Explain the behavior change -->
- Does this need documentation?
- [ ] No.
- [ ] Yes. <!-- Add document PR link here. eg:
https://github.com/apache/doris-website/pull/1214 -->
### Check List (For Reviewer who merge this PR)
- [ ] Confirm the release note
- [ ] Confirm test cases
- [ ] Confirm document
- [ ] Add branch pick label <!-- Add branch pick label that this PR
should merge into -->
---
.../aggregate_function_uniq.cpp | 12 ++---
.../functions/agg/MultiDistinctCount.java | 8 +---
.../data/datatype_p0/date/test_agg_functions.out | 14 ++++++
.../datatype_p0/datetimev2/test_agg_functions.out | 23 +++++++++
.../datatype_p0/date/test_agg_functions.groovy | 45 ++++++++++++++++++
.../datetimev2/test_agg_functions.groovy | 54 ++++++++++++++++++++++
6 files changed, 143 insertions(+), 13 deletions(-)
diff --git a/be/src/vec/aggregate_functions/aggregate_function_uniq.cpp
b/be/src/vec/aggregate_functions/aggregate_function_uniq.cpp
index 399dfc59334..efe3f9ca90c 100644
--- a/be/src/vec/aggregate_functions/aggregate_function_uniq.cpp
+++ b/be/src/vec/aggregate_functions/aggregate_function_uniq.cpp
@@ -37,12 +37,12 @@ AggregateFunctionPtr create_aggregate_function_uniq(const
std::string& name,
const DataTypePtr&
result_type,
const bool
result_is_nullable,
const
AggregateFunctionAttr& attr) {
- return creator_with_type_list<TYPE_BOOLEAN, TYPE_TINYINT, TYPE_SMALLINT,
TYPE_INT, TYPE_BIGINT,
- TYPE_LARGEINT, TYPE_DECIMAL32,
TYPE_DECIMAL64, TYPE_DECIMAL128I,
- TYPE_DECIMAL256, TYPE_VARCHAR, TYPE_ARRAY,
TYPE_FLOAT,
- TYPE_DOUBLE>::create<AggregateFunctionUniq,
- Data>(argument_types,
result_is_nullable,
- attr);
+ return creator_with_type_list<
+ TYPE_BOOLEAN, TYPE_TINYINT, TYPE_SMALLINT, TYPE_INT, TYPE_BIGINT,
TYPE_LARGEINT,
+ TYPE_DECIMAL32, TYPE_DECIMAL64, TYPE_DECIMAL128I, TYPE_DECIMAL256,
TYPE_VARCHAR,
+ TYPE_ARRAY, TYPE_FLOAT, TYPE_DOUBLE, TYPE_DATEV2,
+ TYPE_DATETIMEV2>::create<AggregateFunctionUniq,
Data>(argument_types,
+
result_is_nullable, attr);
}
void register_aggregate_function_uniq(AggregateFunctionSimpleFactory& factory)
{
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/MultiDistinctCount.java
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/MultiDistinctCount.java
index 1dadd80d6da..9e71a3eb647 100644
---
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/MultiDistinctCount.java
+++
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/MultiDistinctCount.java
@@ -18,16 +18,13 @@
package org.apache.doris.nereids.trees.expressions.functions.agg;
import org.apache.doris.catalog.FunctionSignature;
-import org.apache.doris.nereids.analyzer.Unbound;
import org.apache.doris.nereids.exceptions.AnalysisException;
-import org.apache.doris.nereids.trees.expressions.Cast;
import org.apache.doris.nereids.trees.expressions.Expression;
import
org.apache.doris.nereids.trees.expressions.functions.ExplicitlyCastableSignature;
import org.apache.doris.nereids.trees.expressions.literal.BigIntLiteral;
import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor;
import org.apache.doris.nereids.types.BigIntType;
import org.apache.doris.nereids.types.coercion.AnyDataType;
-import org.apache.doris.nereids.types.coercion.DateLikeType;
import org.apache.doris.nereids.util.ExpressionUtils;
import com.google.common.base.Preconditions;
@@ -56,10 +53,7 @@ public class MultiDistinctCount extends
NotNullableAggregateFunction
private MultiDistinctCount(boolean distinct, List<Expression> children) {
super("multi_distinct_count", false, new LinkedHashSet<>(children)
- .stream()
- .map(arg -> !(arg instanceof Unbound) && arg.getDataType()
instanceof DateLikeType
- ? new Cast(arg, BigIntType.INSTANCE) : arg)
- .collect(ImmutableList.toImmutableList()));
+ .stream().collect(ImmutableList.toImmutableList()));
if (super.children().size() > 1) {
throw new AnalysisException("MultiDistinctCount's children size
must be 1");
}
diff --git a/regression-test/data/datatype_p0/date/test_agg_functions.out
b/regression-test/data/datatype_p0/date/test_agg_functions.out
new file mode 100644
index 00000000000..676e5acabe2
--- /dev/null
+++ b/regression-test/data/datatype_p0/date/test_agg_functions.out
@@ -0,0 +1,14 @@
+-- This file is automatically generated. You should know what you did if you
want to edit this
+-- !all --
+\N
+\N
+0000-01-01
+0000-01-01
+2023-08-08
+2023-08-08
+9999-12-31
+9999-12-31
+
+-- !count_distinct --
+3
+
diff --git a/regression-test/data/datatype_p0/datetimev2/test_agg_functions.out
b/regression-test/data/datatype_p0/datetimev2/test_agg_functions.out
new file mode 100644
index 00000000000..9ac542e082c
--- /dev/null
+++ b/regression-test/data/datatype_p0/datetimev2/test_agg_functions.out
@@ -0,0 +1,23 @@
+-- This file is automatically generated. You should know what you did if you
want to edit this
+-- !all --
+\N
+\N
+0000-01-01T00:00
+0000-01-01T00:00
+0000-01-01T00:00:00.000001
+0000-01-01T00:00:00.123456
+0000-01-01T00:00:00.999999
+2023-08-08T20:20:20
+2023-08-08T20:20:20
+2023-08-08T20:20:20.000001
+2023-08-08T20:20:20.123456
+2023-08-08T20:20:20.999999
+9999-12-31T23:59:59
+9999-12-31T23:59:59
+9999-12-31T23:59:59.000001
+9999-12-31T23:59:59.123456
+9999-12-31T23:59:59.999999
+
+-- !count_distinct --
+12
+
diff --git a/regression-test/suites/datatype_p0/date/test_agg_functions.groovy
b/regression-test/suites/datatype_p0/date/test_agg_functions.groovy
new file mode 100644
index 00000000000..cf039275953
--- /dev/null
+++ b/regression-test/suites/datatype_p0/date/test_agg_functions.groovy
@@ -0,0 +1,45 @@
+
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+suite("test_agg_functions") {
+ sql "drop table if exists test_datev2_agg_functions"
+
+ sql """
+ CREATE TABLE `test_datev2_agg_functions` (
+ `f1` datev2
+ )
+ PROPERTIES (
+ "replication_allocation" = "tag.location.default: 1"
+ )
+ """
+
+ sql """insert into test_datev2_agg_functions values
+ (null),
+ (null),
+ ('0000-01-01 00:00:00'),
+ ('0000-01-01 00:00:00'),
+ ('2023-08-08 20:20:20'),
+ ('2023-08-08 20:20:20'),
+ ('9999-12-31 23:59:59'),
+ ('9999-12-31 23:59:59');
+ """
+ qt_all "select * from test_datev2_agg_functions order by 1"
+ qt_count_distinct """
+ select multi_distinct_count(f1) from test_datev2_agg_functions;
+ """
+}
diff --git
a/regression-test/suites/datatype_p0/datetimev2/test_agg_functions.groovy
b/regression-test/suites/datatype_p0/datetimev2/test_agg_functions.groovy
new file mode 100644
index 00000000000..6cf978bb63a
--- /dev/null
+++ b/regression-test/suites/datatype_p0/datetimev2/test_agg_functions.groovy
@@ -0,0 +1,54 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+suite("test_agg_functions") {
+ sql "drop table if exists test_datetimev2_agg_functions"
+
+ sql """
+ CREATE TABLE `test_datetimev2_agg_functions` (
+ `f1` datetimev2(6)
+ )
+ PROPERTIES (
+ "replication_allocation" = "tag.location.default: 1"
+ )
+ """
+
+ sql """insert into test_datetimev2_agg_functions values
+ (null),
+ (null),
+ ('0000-01-01 00:00:00'),
+ ('0000-01-01 00:00:00.000000'),
+ ('0000-01-01 00:00:00.000001'),
+ ('0000-01-01 00:00:00.123456'),
+ ('0000-01-01 00:00:00.999999'),
+ ('2023-08-08 20:20:20'),
+ ('2023-08-08 20:20:20.000000'),
+ ('2023-08-08 20:20:20.000001'),
+ ('2023-08-08 20:20:20.123456'),
+ ('2023-08-08 20:20:20.999999'),
+ ('9999-12-31 23:59:59'),
+ ('9999-12-31 23:59:59.000000'),
+ ('9999-12-31 23:59:59.000001'),
+ ('9999-12-31 23:59:59.123456'),
+ ('9999-12-31 23:59:59.999999');
+ """
+ qt_all "select * from test_datetimev2_agg_functions order by 1"
+ qt_count_distinct """
+ select multi_distinct_count(f1) from test_datetimev2_agg_functions;
+ """
+
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]