[fix](DECIMALV3) Fix the error in DECIMALV3 when explicitly casting. (#19926)
before mysql [test]>select cast(1 as DECIMALV3(16, 2)) / cast(3 as DECIMALV3(16, 2)); +-----------------------------------------------------------+ | CAST(1 AS DECIMALV3(16, 2)) / CAST(3 AS DECIMALV3(16, 2)) | +-----------------------------------------------------------+ | 0.00 | +-----------------------------------------------------------+ mysql [test]>select * from divtest; +------+------+ | id | val | +------+------+ | 3 | 5.00 | | 2 | 4.00 | | 1 | 3.00 | +------+------+ mysql [test]>select cast(1 as decimalv3(16,2)) / val from divtest; +-------------------------------------+ | CAST(1 AS DECIMALV3(16, 2)) / `val` | +-------------------------------------+ | 0 | | 0 | | 0 | +-------------------------------------+ after mysql [test]>select cast(1 as DECIMALV3(16, 2)) / cast(3 as DECIMALV3(16, 2)); +-----------------------------------------------------------+ | CAST(1 AS DECIMALV3(16, 2)) / CAST(3 AS DECIMALV3(16, 2)) | +-----------------------------------------------------------+ | 0.33 | +-----------------------------------------------------------+ mysql [test]>select cast(1 as decimalv3(16,2)) / val from divtest; +-------------------------------------+ | CAST(1 AS DECIMALV3(16, 2)) / `val` | +-------------------------------------+ | 0.250000 | | 0.200000 | | 0.333333 | +-------------------------------------+ This is because in the previous code, the constant 1.000 would be transformed into 1. remove "ReduceType
This commit is contained in:
@ -543,11 +543,6 @@ public class ArithmeticExpr extends Expr {
|
||||
@Override
|
||||
public void analyzeImpl(Analyzer analyzer) throws AnalysisException {
|
||||
if (VectorizedUtil.isVectorized()) {
|
||||
for (Expr child : children) {
|
||||
if (child instanceof DecimalLiteral && child.getType().isDecimalV3()) {
|
||||
((DecimalLiteral) child).tryToReduceType();
|
||||
}
|
||||
}
|
||||
// bitnot is the only unary op, deal with it here
|
||||
if (op == Operator.BITNOT) {
|
||||
Type t = getChild(0).getType();
|
||||
|
||||
@ -0,0 +1,9 @@
|
||||
-- This file is automatically generated. You should know what you did if you want to edit this
|
||||
-- !select1 --
|
||||
0.33333333
|
||||
0.25000000
|
||||
0.20000000
|
||||
|
||||
-- !select2 --
|
||||
0.33
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
-- This file is automatically generated. You should know what you did if you want to edit this
|
||||
-- !q14 --
|
||||
16.2838
|
||||
16.283855
|
||||
|
||||
|
||||
@ -0,0 +1,50 @@
|
||||
// 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_cast_as_decimalv3") {
|
||||
sql """ DROP TABLE IF EXISTS divtest """
|
||||
sql """
|
||||
CREATE TABLE IF NOT EXISTS divtest (
|
||||
`id` int(11) ,
|
||||
`val` decimalv3(16,2)
|
||||
)
|
||||
UNIQUE KEY(`id`)
|
||||
DISTRIBUTED BY HASH(`id`) BUCKETS 10
|
||||
PROPERTIES (
|
||||
"enable_unique_key_merge_on_write" = "true",
|
||||
"replication_num" = "1"
|
||||
);
|
||||
"""
|
||||
sql """
|
||||
set enable_nereids_planner=false,enable_fold_constant_by_be = false
|
||||
"""
|
||||
sql """
|
||||
INSERT INTO divtest VALUES(1,3.00)
|
||||
"""
|
||||
sql """
|
||||
INSERT INTO divtest VALUES(2,4.00)
|
||||
"""
|
||||
sql """
|
||||
INSERT INTO divtest VALUES(3,5.00)
|
||||
"""
|
||||
qt_select1 """
|
||||
select cast(1 as decimalv3(16,2)) / val from divtest order by id
|
||||
"""
|
||||
qt_select2 """
|
||||
select cast(1 as DECIMALV3(16, 2)) / cast(3 as DECIMALV3(16, 2))
|
||||
"""
|
||||
}
|
||||
Reference in New Issue
Block a user