Skip to content

Commit

Permalink
[Bug](decimal) Fix incorrect result for decimal multiply (apache#13591)
Browse files Browse the repository at this point in the history
Fix incorrect result for decimal multiply
  • Loading branch information
Gabriel39 authored Oct 25, 2022
1 parent 57e248e commit 7fe7c01
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 1 deletion.
6 changes: 5 additions & 1 deletion be/src/vec/functions/multiply.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,12 @@ struct MultiplyImpl {
int8 sgn[size];

for (int i = 0; i < size; i++) {
sgn[i] = ((DecimalV2Value(a[i]).value() >= 0) == (DecimalV2Value(b[i]).value() >= 0))
sgn[i] = ((DecimalV2Value(a[i]).value() > 0) && (DecimalV2Value(b[i]).value() > 0)) ||
((DecimalV2Value(a[i]).value() < 0) &&
(DecimalV2Value(b[i]).value() < 0))
? 1
: ((DecimalV2Value(a[i]).value() == 0) || (DecimalV2Value(b[i]).value() == 0))
? 0
: -1;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
-- This file is automatically generated. You should know what you did if you want to edit this
-- !select --
0E-9
0E-9

-- !select --
\N
0E-9

Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// 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_multiply") {
sql """ set enable_vectorized_engine = true """

def tableName = "test_multiply"
sql """ CREATE TABLE `${tableName}` (
`user_id` LARGEINT NOT NULL COMMENT "用户id",
`col2` DECIMAL(27,9) COMMENT "数据灌入日期时间",
`col3` DECIMAL(16,8) COMMENT "数据灌入日期时间")
DUPLICATE KEY(`user_id`) DISTRIBUTED BY HASH(`user_id`)
PROPERTIES ( "replication_num" = "1" ); """

sql """ insert into `${tableName}` values(1,null,2.2); """
sql """ insert into `${tableName}` values(1,0,0); """
qt_select """ select COALESCE(col2, 0) * COALESCE(col3, 0) from `${tableName}`; """
qt_select """ select col2 * col3 from `${tableName}`; """
}

0 comments on commit 7fe7c01

Please sign in to comment.