Skip to content
Permalink
Browse files
[fix](Function) fix case when function return null with abs function (#…
  • Loading branch information
zhangstar333 committed May 14, 2022
1 parent b817efd commit fa6e4db4ca0276d2c0c5b33aa9b5602e96395d8c
Showing 4 changed files with 74 additions and 0 deletions.
@@ -223,6 +223,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)
@@ -38,6 +38,7 @@ class CaseExpr : public Expr {
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;
@@ -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

@@ -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;
"""
}

0 comments on commit fa6e4db

Please sign in to comment.