morrySnow commented on code in PR #41370:
URL: https://github.com/apache/doris/pull/41370#discussion_r1794609182


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/MultiTopN.java:
##########
@@ -0,0 +1,94 @@
+// 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.
+
+package org.apache.doris.nereids.trees.expressions.functions.agg;
+
+import org.apache.doris.catalog.FunctionSignature;
+import org.apache.doris.nereids.exceptions.AnalysisException;
+import org.apache.doris.nereids.trees.expressions.Expression;
+import 
org.apache.doris.nereids.trees.expressions.functions.ExplicitlyCastableSignature;
+import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor;
+import org.apache.doris.nereids.types.StringType;
+import org.apache.doris.nereids.types.coercion.AnyDataType;
+
+import com.google.common.base.Preconditions;
+import com.google.common.collect.ImmutableList;
+
+import java.util.List;
+
+/**
+ * AggregateFunction 'multi_topn'. This class is generated by GenerateFunction.
+ */
+public class MultiTopN extends NullableAggregateFunction
+        implements ExplicitlyCastableSignature {
+
+    public static final List<FunctionSignature> SIGNATURES = ImmutableList.of(
+            FunctionSignature.ret(StringType.INSTANCE)
+                    .varArgs(AnyDataType.INSTANCE_WITHOUT_INDEX)
+    );
+
+    public MultiTopN(Expression... varArgs) {
+        this(false, varArgs);
+    }
+
+    public MultiTopN(boolean distinct, Expression... varArgs) {
+        this(distinct, false, varArgs);
+    }
+
+    public MultiTopN(boolean distinct, boolean alwaysNullable, Expression... 
varArgs) {

Review Comment:
   private?



##########
regression-test/suites/inverted_index_p0/test_index_multi_topn.groovy:
##########
@@ -0,0 +1,103 @@
+// 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_index_multi_topn", "p0"){
+    def indexTbNameV1 = "test_index_multi_topn_v1"
+    def indexTbNameV2 = "test_index_multi_topn_v2"
+
+    sql "DROP TABLE IF EXISTS ${indexTbNameV1}"
+    sql "DROP TABLE IF EXISTS ${indexTbNameV2}"
+
+    def create_table = {table_name, idx_version ->
+      sql """
+        CREATE TABLE ${table_name} (
+          `@timestamp` int(11) NULL COMMENT "",
+          `clientip` text NULL COMMENT "",
+          `request` text NULL COMMENT "",
+          `status` text NULL COMMENT "",
+          `size` text NULL COMMENT ""
+        ) ENGINE=OLAP
+        DUPLICATE KEY(`@timestamp`)
+        COMMENT "OLAP"
+        DISTRIBUTED BY RANDOM BUCKETS 1
+        PROPERTIES (
+          "replication_allocation" = "tag.location.default: 1",
+          "inverted_index_storage_format" = "${idx_version}",
+          "disable_auto_compaction" = "true"
+        );
+      """
+    }
+
+    def load_httplogs_data = {table_name, label, read_flag, format_flag, 
file_name, ignore_failure=false,
+                        expected_succ_rows = -1, load_to_single_tablet = 
'true' ->
+        
+        // load the json data
+        streamLoad {
+            table "${table_name}"
+            
+            // set http request header params
+            set 'label', label + "_" + UUID.randomUUID().toString()
+            set 'read_json_by_line', read_flag
+            set 'format', format_flag
+            file file_name // import json file
+            time 10000 // limit inflight 10s
+            if (expected_succ_rows >= 0) {
+                set 'max_filter_ratio', '1'
+            }
+
+            // if declared a check callback, the default check condition will 
ignore.
+            // So you must check all condition
+            check { result, exception, startTime, endTime ->
+                       if (ignore_failure && expected_succ_rows < 0) { return }
+                    if (exception != null) {
+                        throw exception
+                    }
+                    log.info("Stream load result: ${result}".toString())
+                    def json = parseJson(result)
+                    assertEquals("success", json.Status.toLowerCase())
+                    if (expected_succ_rows >= 0) {
+                        assertEquals(json.NumberLoadedRows, expected_succ_rows)
+                    } else {
+                        assertEquals(json.NumberTotalRows, 
json.NumberLoadedRows + json.NumberUnselectedRows)
+                        assertTrue(json.NumberLoadedRows > 0 && json.LoadBytes 
> 0)
+                }
+            }
+        }
+    }
+
+    try {
+        create_table(indexTbNameV1, 'V1')
+        create_table(indexTbNameV2, 'V2')
+
+        load_httplogs_data.call(indexTbNameV1, 'test_index_multi_topn_v1', 
'true', 'json', 'documents-1000.json')
+        load_httplogs_data.call(indexTbNameV2, 'test_index_multi_topn_v2', 
'true', 'json', 'documents-1000.json')
+
+        sql "sync"
+
+        sql """ set enable_common_expr_pushdown = true """
+
+        qt_sql """ select clientip, count(*) as count from ${indexTbNameV1} 
group by clientip order by count desc limit 10; """
+        qt_sql """ select multi_topn(clientip, 10, 300) from ${indexTbNameV1}; 
"""

Review Comment:
   since check is only require constant, u should turn of constant folding by 
`set debug_skip_fold_constant=true` and add test like
   - multi_topn(clientip, 10 + 20, 300)
   - multi_topn(clientip, -100, 300)
   - multi_topn(clientip, abs(-50), 300)



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


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

Reply via email to