This is an automated email from the ASF dual-hosted git repository. morningman pushed a commit to branch dev-1.0.1 in repository https://gitbox.apache.org/repos/asf/incubator-doris.git
commit 71beda2664f32efdc1b6c6fc495b92846f0f8138 Author: zhangstar333 <87313068+zhangstar...@users.noreply.github.com> AuthorDate: Sat May 14 09:50:45 2022 +0800 [fix](Function) fix case when function return null with abs function (#9493) --- be/src/exprs/case_expr.cpp | 1 + be/src/exprs/case_expr.h | 1 + .../data/correctness/test_case_when.out | 5 ++ .../suites/correctness/test_case_when.groovy | 67 ++++++++++++++++++++++ 4 files changed, 74 insertions(+) diff --git a/be/src/exprs/case_expr.cpp b/be/src/exprs/case_expr.cpp index e1290fc7b0..4ab3475048 100644 --- a/be/src/exprs/case_expr.cpp +++ b/be/src/exprs/case_expr.cpp @@ -218,6 +218,7 @@ CASE_COMPUTE_FN_WRAPPER(TinyIntVal, tiny_int_val) CASE_COMPUTE_FN_WRAPPER(SmallIntVal, small_int_val) CASE_COMPUTE_FN_WRAPPER(IntVal, int_val) CASE_COMPUTE_FN_WRAPPER(BigIntVal, big_int_val) +CASE_COMPUTE_FN_WRAPPER(LargeIntVal, large_int_val) CASE_COMPUTE_FN_WRAPPER(FloatVal, float_val) CASE_COMPUTE_FN_WRAPPER(DoubleVal, double_val) CASE_COMPUTE_FN_WRAPPER(StringVal, string_val) diff --git a/be/src/exprs/case_expr.h b/be/src/exprs/case_expr.h index 8bcbc48269..83d4d24508 100644 --- a/be/src/exprs/case_expr.h +++ b/be/src/exprs/case_expr.h @@ -36,6 +36,7 @@ public: virtual SmallIntVal get_small_int_val(ExprContext* ctx, TupleRow* row) override; virtual IntVal get_int_val(ExprContext* ctx, TupleRow* row) override; virtual BigIntVal get_big_int_val(ExprContext* ctx, TupleRow* row) override; + virtual LargeIntVal get_large_int_val(ExprContext* context, TupleRow*) override; virtual FloatVal get_float_val(ExprContext* ctx, TupleRow* row) override; virtual DoubleVal get_double_val(ExprContext* ctx, TupleRow* row) override; virtual StringVal get_string_val(ExprContext* ctx, TupleRow* row) override; diff --git a/regression-test/data/correctness/test_case_when.out b/regression-test/data/correctness/test_case_when.out new file mode 100644 index 0000000000..d4db120b76 --- /dev/null +++ b/regression-test/data/correctness/test_case_when.out @@ -0,0 +1,5 @@ +-- This file is automatically generated. You should know what you did if you want to edit this +-- !select_default -- +2 01 -1 +3 00 1 + diff --git a/regression-test/suites/correctness/test_case_when.groovy b/regression-test/suites/correctness/test_case_when.groovy new file mode 100644 index 0000000000..f5afe3026f --- /dev/null +++ b/regression-test/suites/correctness/test_case_when.groovy @@ -0,0 +1,67 @@ +// 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_case_when") { + def tableName = "dws_scan_qrcode_user_ts" + + + sql """ DROP TABLE IF EXISTS ${tableName} """ + sql """ + CREATE TABLE IF NOT EXISTS ${tableName} + ( + dt DATE NOT NULL , + hour_time INT NOT NULL , + merchant_id INT NOT NULL , + channel_id char(5) NOT NULL , + station_type char(5) NULL , + station_name varchar(55) NULL , + source char(5) NULL , + passenger_flow BIGINT SUM DEFAULT '1' , + user_id bitmap BITMAP_UNION , + price BIGINT SUM , + discount BIGINT SUM + ) + AGGREGATE KEY(dt,hour_time, merchant_id,channel_id,station_type,station_name,`source`) + DISTRIBUTED BY HASH(dt,hour_time,merchant_id,channel_id) BUCKETS 1 + PROPERTIES("replication_num" = "1"); + """ + + sql " INSERT INTO ${tableName} (`dt`, `hour_time`, `merchant_id`, `channel_id`, `station_type`, `station_name`, `source`, `passenger_flow`, `user_id`, `price`, `discount`) VALUES ('2019-01-01', 1, 45010002, '01', '00', 'xx站', '', 1, to_bitmap(0), 300, 300); " + sql " INSERT INTO ${tableName} (`dt`, `hour_time`, `merchant_id`, `channel_id`, `station_type`, `station_name`, `source`, `passenger_flow`, `user_id`, `price`, `discount`) VALUES ('2019-01-01', 1, 45010002, '01', '00', 'xxx站', '', 3, to_bitmap(0), 400, 400); " + sql " INSERT INTO ${tableName} (`dt`, `hour_time`, `merchant_id`, `channel_id`, `station_type`, `station_name`, `source`, `passenger_flow`, `user_id`, `price`, `discount`) VALUES ('2019-01-01', 2, 45010002, '00', '01', 'xx站', 'CHL', 1, to_bitmap(0), NULL, 23); " + sql " INSERT INTO ${tableName} (`dt`, `hour_time`, `merchant_id`, `channel_id`, `station_type`, `station_name`, `source`, `passenger_flow`, `user_id`, `price`, `discount`) VALUES ('2019-01-01', 3, 45010002, '00', '00', 'xx站', 'CHL', 1, to_bitmap(0), NULL, NULL); " + sql " INSERT INTO ${tableName} (`dt`, `hour_time`, `merchant_id`, `channel_id`, `station_type`, `station_name`, `source`, `passenger_flow`, `user_id`, `price`, `discount`) VALUES ('2019-01-01', 3, 45010002, '01', '00', 'xxxx站', '', 4, to_bitmap(0), 60, 60); " + sql " INSERT INTO ${tableName} (`dt`, `hour_time`, `merchant_id`, `channel_id`, `station_type`, `station_name`, `source`, `passenger_flow`, `user_id`, `price`, `discount`) VALUES ('2019-01-01', 3, 45010002, '01', '00', 'xxxx站', '', 2, to_bitmap(0), 200, 200); " + sql " INSERT INTO ${tableName} (`dt`, `hour_time`, `merchant_id`, `channel_id`, `station_type`, `station_name`, `source`, `passenger_flow`, `user_id`, `price`, `discount`) VALUES ('2019-01-01', 4, 45010002, '01', '00', 'xxxx站', '', 5, to_bitmap(0), 1000, 1000); " + sql " INSERT INTO ${tableName} (`dt`, `hour_time`, `merchant_id`, `channel_id`, `station_type`, `station_name`, `source`, `passenger_flow`, `user_id`, `price`, `discount`) VALUES ('2019-01-01', 4, 45010002, '01', '00', 'xxx站', '', 1, to_bitmap(0), 20, 20); " + + + // not_vectorized + sql """ set enable_vectorized_engine = false """ + + qt_select_default """ + select hour_time as date_hour, station_type, + CASE WHEN station_type = '00' THEN sum(passenger_flow) + ELSE -ABS(sum(passenger_flow)) + end passenger_flow + from ${tableName} + where dt = '2019-01-01' + and merchant_id in (45010002, 45010003) + and channel_id = '00' + group by hour_time, station_type; + """ +} \ No newline at end of file --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org