You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@doris.apache.org by pa...@apache.org on 2023/01/08 03:31:32 UTC

[doris] branch master updated: [fix](regression p0) add the alias function hist to histogram and fix p0 (#15708)

This is an automated email from the ASF dual-hosted git repository.

panxiaolei 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 36590da24b [fix](regression p0) add the alias function hist to histogram and fix p0 (#15708)
36590da24b is described below

commit 36590da24b44d57a638ec43906b12731fb1e5280
Author: ElvinWei <zh...@outlook.com>
AuthorDate: Sun Jan 8 11:31:23 2023 +0800

    [fix](regression p0) add the alias function hist to histogram and fix p0 (#15708)
    
    add the alias function hist to histogram and fix p0
---
 .../aggregate_function_histogram.cpp               |   1 +
 .../sql-functions/aggregate-functions/histogram.md |   6 +-
 .../sql-functions/aggregate-functions/histogram.md |   4 +-
 .../java/org/apache/doris/catalog/FunctionSet.java |   5 +-
 .../test_aggregate_histogram.groovy                | 136 ++++++++++-----------
 5 files changed, 80 insertions(+), 72 deletions(-)

diff --git a/be/src/vec/aggregate_functions/aggregate_function_histogram.cpp b/be/src/vec/aggregate_functions/aggregate_function_histogram.cpp
index 5ab7dd6035..983526a582 100644
--- a/be/src/vec/aggregate_functions/aggregate_function_histogram.cpp
+++ b/be/src/vec/aggregate_functions/aggregate_function_histogram.cpp
@@ -83,6 +83,7 @@ AggregateFunctionPtr create_aggregate_function_histogram(const std::string& name
 
 void register_aggregate_function_histogram(AggregateFunctionSimpleFactory& factory) {
     factory.register_function("histogram", create_aggregate_function_histogram);
+    factory.register_alias("histogram", "hist");
 }
 
 } // namespace doris::vectorized
\ No newline at end of file
diff --git a/docs/en/docs/sql-manual/sql-functions/aggregate-functions/histogram.md b/docs/en/docs/sql-manual/sql-functions/aggregate-functions/histogram.md
index 6cc96340dc..32a57c8735 100644
--- a/docs/en/docs/sql-manual/sql-functions/aggregate-functions/histogram.md
+++ b/docs/en/docs/sql-manual/sql-functions/aggregate-functions/histogram.md
@@ -28,7 +28,7 @@ under the License.
 ### description
 #### Syntax
 
-`histogram(expr)`
+`histogram(expr[, DOUBLE sample_rate, INT max_bucket_num])`
 
 The histogram function is used to describe the distribution of the data. It uses an "equal height" bucking strategy, and divides the data into buckets according to the value of the data. It describes each bucket with some simple data, such as the number of values that fall in the bucket. It is mainly used by the optimizer to estimate the range query.
 
@@ -38,6 +38,8 @@ Parameter description:
 - sample_rate:Optional. The proportion of sample data used to generate the histogram. The default is 0.2.
 - max_bucket_num:Optional. Limit the number of histogram buckets. The default value is 128.
 
+Alias function: `hist(expr[, DOUBLE sample_rate, INT max_bucket_num])`
+
 ### notice
 
 > Only supported in vectorized engine
@@ -108,4 +110,4 @@ Field description:
 
 ### keywords
 
-HISTOGRAM
+HISTOGRAM, HIST
diff --git a/docs/zh-CN/docs/sql-manual/sql-functions/aggregate-functions/histogram.md b/docs/zh-CN/docs/sql-manual/sql-functions/aggregate-functions/histogram.md
index 55085ee26d..891adb4776 100644
--- a/docs/zh-CN/docs/sql-manual/sql-functions/aggregate-functions/histogram.md
+++ b/docs/zh-CN/docs/sql-manual/sql-functions/aggregate-functions/histogram.md
@@ -38,6 +38,8 @@ histogram(直方图)函数用于描述数据分布情况,它使用“等
 - sample_rate:可选项。用于生成直方图的抽样数据比例,默认值 0.2。
 - max_bucket_num:可选项。用于限制直方图桶(bucket)的数量,默认值 128。
 
+别名函数:`hist(expr[, DOUBLE sample_rate, INT max_bucket_num])`
+
 ### notice
 
 ```
@@ -110,4 +112,4 @@ MySQL [test]> SELECT histogram(c_string, 0.5, 2) FROM histogram_test;
 
 ### keywords
 
-HISTOGRAM
+HISTOGRAM, HIST
diff --git a/fe/fe-core/src/main/java/org/apache/doris/catalog/FunctionSet.java b/fe/fe-core/src/main/java/org/apache/doris/catalog/FunctionSet.java
index d25395177a..651df130e7 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/catalog/FunctionSet.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/catalog/FunctionSet.java
@@ -935,6 +935,7 @@ public class FunctionSet<T> {
     public static final String COLLECT_LIST = "collect_list";
     public static final String COLLECT_SET = "collect_set";
     public static final String HISTOGRAM = "histogram";
+    public static final String HIST = "hist";
 
     private static final Map<Type, String> ORTHOGONAL_BITMAP_INTERSECT_INIT_SYMBOL =
             ImmutableMap.<Type, String>builder()
@@ -2608,9 +2609,11 @@ public class FunctionSet<T> {
                             .createBuiltin("topn_weighted", Lists.newArrayList(t, Type.BIGINT, Type.INT, Type.INT),
                                     new ArrayType(t), t,
                                     "", "", "", "", "", true, false, true, true));
+            addBuiltin(AggregateFunction.createBuiltin(HIST, Lists.newArrayList(t), Type.VARCHAR, t,
+                    "", "", "", "", "", true, false, true, true));
             addBuiltin(AggregateFunction.createBuiltin(HISTOGRAM, Lists.newArrayList(t), Type.VARCHAR, t,
                     "", "", "", "", "", true, false, true, true));
-            addBuiltin(AggregateFunction.createBuiltin(HISTOGRAM, Lists.newArrayList(t, Type.DOUBLE, Type.INT), Type.VARCHAR, t,
+            addBuiltin(AggregateFunction.createBuiltin(HIST, Lists.newArrayList(t, Type.DOUBLE, Type.INT), Type.VARCHAR, t,
                                     "", "", "", "", "", true, false, true, true));
             addBuiltin(AggregateFunction.createBuiltin(HISTOGRAM, Lists.newArrayList(t, Type.DOUBLE, Type.INT), Type.VARCHAR, t,
                     "", "", "", "", "", true, false, true, true));
diff --git a/regression-test/suites/query_p0/sql_functions/aggregate_functions/test_aggregate_histogram.groovy b/regression-test/suites/query_p0/sql_functions/aggregate_functions/test_aggregate_histogram.groovy
index dcd7ea0709..fc0f993971 100644
--- a/regression-test/suites/query_p0/sql_functions/aggregate_functions/test_aggregate_histogram.groovy
+++ b/regression-test/suites/query_p0/sql_functions/aggregate_functions/test_aggregate_histogram.groovy
@@ -105,23 +105,23 @@ suite("test_aggregate_histogram") {
     // Test without GROUP BY
     qt_select """
         SELECT
-            histogram(c_bool, 1.0, 1), 
-            histogram(c_tinyint, 1.0, 1), 
-            histogram(c_smallint, 1.0, 1), 
-            histogram(c_bigint, 1.0, 1), 
-            histogram(c_largeint, 1.0, 1), 
-            histogram(c_float, 1.0, 1), 
-            histogram(c_double, 1.0, 1), 
-            histogram(c_decimal, 1.0, 1), 
-            histogram(c_decimalv3, 1.0, 1), 
-            histogram(c_char, 1.0, 1), 
-            histogram(c_varchar, 1.0, 1), 
-            histogram(c_string, 1.0, 1), 
-            histogram(c_date, 1.0, 1), 
-            histogram(c_datev2, 1.0, 1), 
-            histogram(c_date_time, 1.0, 1), 
-            histogram(c_date_timev2, 1.0, 1), 
-            histogram(c_string_not_null, 1.0, 1)
+            `histogram`(c_bool, 1.0, 1), 
+            `histogram`(c_tinyint, 1.0, 1), 
+            `histogram`(c_smallint, 1.0, 1), 
+            `histogram`(c_bigint, 1.0, 1), 
+            `histogram`(c_largeint, 1.0, 1), 
+            `histogram`(c_float, 1.0, 1), 
+            `histogram`(c_double, 1.0, 1), 
+            `histogram`(c_decimal, 1.0, 1), 
+            `histogram`(c_decimalv3, 1.0, 1), 
+            `histogram`(c_char, 1.0, 1), 
+            `histogram`(c_varchar, 1.0, 1), 
+            `histogram`(c_string, 1.0, 1), 
+            `histogram`(c_date, 1.0, 1), 
+            `histogram`(c_datev2, 1.0, 1), 
+            `histogram`(c_date_time, 1.0, 1), 
+            `histogram`(c_date_timev2, 1.0, 1), 
+            `histogram`(c_string_not_null, 1.0, 1)
         FROM
             ${tableName}
     """
@@ -130,23 +130,23 @@ suite("test_aggregate_histogram") {
     qt_select """
         SELECT
             c_id, 
-            histogram(c_bool, 1.0, 1), 
-            histogram(c_tinyint, 1.0, 1), 
-            histogram(c_smallint, 1.0, 1), 
-            histogram(c_bigint, 1.0, 1), 
-            histogram(c_largeint, 1.0, 1), 
-            histogram(c_float, 1.0, 1), 
-            histogram(c_double, 1.0, 1), 
-            histogram(c_decimal, 1.0, 1), 
-            histogram(c_decimalv3, 1.0, 1), 
-            histogram(c_char, 1.0, 1), 
-            histogram(c_varchar, 1.0, 1), 
-            histogram(c_string, 1.0, 1), 
-            histogram(c_date, 1.0, 1), 
-            histogram(c_datev2, 1.0, 1), 
-            histogram(c_date_time, 1.0, 1), 
-            histogram(c_date_timev2, 1.0, 1), 
-            histogram(c_string_not_null, 1.0, 1)
+            hist(c_bool, 1.0, 1), 
+            hist(c_tinyint, 1.0, 1), 
+            hist(c_smallint, 1.0, 1), 
+            hist(c_bigint, 1.0, 1), 
+            hist(c_largeint, 1.0, 1), 
+            hist(c_float, 1.0, 1), 
+            hist(c_double, 1.0, 1), 
+            hist(c_decimal, 1.0, 1), 
+            hist(c_decimalv3, 1.0, 1), 
+            hist(c_char, 1.0, 1), 
+            hist(c_varchar, 1.0, 1), 
+            hist(c_string, 1.0, 1), 
+            hist(c_date, 1.0, 1), 
+            hist(c_datev2, 1.0, 1), 
+            hist(c_date_time, 1.0, 1), 
+            hist(c_date_timev2, 1.0, 1), 
+            hist(c_string_not_null, 1.0, 1)
         FROM
             ${tableName}
         GROUP BY
@@ -159,23 +159,23 @@ suite("test_aggregate_histogram") {
         CREATE TABLE ${tableCTAS1} PROPERTIES("replication_num" = "1") AS
         SELECT
             1, 
-            histogram(c_bool, 1.0, 2), 
-            histogram(c_tinyint, 1.0, 2), 
-            histogram(c_smallint, 1.0, 2), 
-            histogram(c_bigint, 1.0, 2), 
-            histogram(c_largeint, 1.0, 2), 
-            histogram(c_float, 1.0, 2), 
-            histogram(c_double, 1.0, 2), 
-            histogram(c_decimal, 1.0, 2), 
-            histogram(c_decimalv3, 1.0, 2), 
-            histogram(c_char, 1.0, 2), 
-            histogram(c_varchar, 1.0, 2), 
-            histogram(c_string, 1.0, 2), 
-            histogram(c_date, 1.0, 2), 
-            histogram(c_datev2, 1.0, 2), 
-            histogram(c_date_time, 1.0, 2), 
-            histogram(c_date_timev2, 1.0, 2), 
-            histogram(c_string_not_null, 1.0, 2)
+            hist(c_bool, 1.0, 2), 
+            hist(c_tinyint, 1.0, 2), 
+            hist(c_smallint, 1.0, 2), 
+            hist(c_bigint, 1.0, 2), 
+            hist(c_largeint, 1.0, 2), 
+            hist(c_float, 1.0, 2), 
+            hist(c_double, 1.0, 2), 
+            hist(c_decimal, 1.0, 2), 
+            hist(c_decimalv3, 1.0, 2), 
+            hist(c_char, 1.0, 2), 
+            hist(c_varchar, 1.0, 2), 
+            hist(c_string, 1.0, 2), 
+            hist(c_date, 1.0, 2), 
+            hist(c_datev2, 1.0, 2), 
+            hist(c_date_time, 1.0, 2), 
+            hist(c_date_timev2, 1.0, 2), 
+            hist(c_string_not_null, 1.0, 2)
         FROM
             ${tableName}
     """
@@ -184,23 +184,23 @@ suite("test_aggregate_histogram") {
         CREATE TABLE ${tableCTAS2} PROPERTIES("replication_num" = "1") AS
         SELECT
             1, 
-            histogram(c_bool, 1.0, 1), 
-            histogram(c_tinyint, 1.0, 1), 
-            histogram(c_smallint, 1.0, 1), 
-            histogram(c_bigint, 1.0, 1), 
-            histogram(c_largeint, 1.0, 1), 
-            histogram(c_float, 1.0, 1), 
-            histogram(c_double, 1.0, 1), 
-            histogram(c_decimal, 1.0, 1), 
-            histogram(c_decimalv3, 1.0, 1), 
-            histogram(c_char, 1.0, 1), 
-            histogram(c_varchar, 1.0, 1), 
-            histogram(c_string, 1.0, 1), 
-            histogram(c_date, 1.0, 1), 
-            histogram(c_datev2, 1.0, 1), 
-            histogram(c_date_time, 1.0, 1), 
-            histogram(c_date_timev2, 1.0, 1), 
-            histogram(c_string_not_null, 1.0, 1)
+            hist(c_bool, 1.0, 1), 
+            hist(c_tinyint, 1.0, 1), 
+            hist(c_smallint, 1.0, 1), 
+            hist(c_bigint, 1.0, 1), 
+            hist(c_largeint, 1.0, 1), 
+            hist(c_float, 1.0, 1), 
+            hist(c_double, 1.0, 1), 
+            hist(c_decimal, 1.0, 1), 
+            hist(c_decimalv3, 1.0, 1), 
+            hist(c_char, 1.0, 1), 
+            hist(c_varchar, 1.0, 1), 
+            hist(c_string, 1.0, 1), 
+            hist(c_date, 1.0, 1), 
+            hist(c_datev2, 1.0, 1), 
+            hist(c_date_time, 1.0, 1), 
+            hist(c_date_timev2, 1.0, 1), 
+            hist(c_string_not_null, 1.0, 1)
         FROM
             ${tableName}
     """


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org