Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
2dot5
ClickHouse
提交
bf318701
C
ClickHouse
项目概览
2dot5
/
ClickHouse
通知
3
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
C
ClickHouse
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
bf318701
编写于
12月 27, 2020
作者:
A
alexey-milovidov
提交者:
GitHub
12月 27, 2020
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #18145 from myrrc/improvement/multiply-decimals-and-floats
Allow multiplication of Decimal and Float
上级
1e8b180e
b086a78f
变更
7
展开全部
显示空白变更内容
内联
并排
Showing
7 changed file
with
591 addition
and
377 deletion
+591
-377
src/Core/DecimalFunctions.h
src/Core/DecimalFunctions.h
+1
-0
src/Functions/FunctionBinaryArithmetic.h
src/Functions/FunctionBinaryArithmetic.h
+534
-373
src/Functions/intDiv.cpp
src/Functions/intDiv.cpp
+3
-1
src/Functions/modulo.cpp
src/Functions/modulo.cpp
+3
-1
src/Functions/multiply.cpp
src/Functions/multiply.cpp
+9
-2
tests/queries/0_stateless/01603_decimal_mult_float.reference
tests/queries/0_stateless/01603_decimal_mult_float.reference
+14
-0
tests/queries/0_stateless/01603_decimal_mult_float.sql
tests/queries/0_stateless/01603_decimal_mult_float.sql
+27
-0
未找到文件。
src/Core/DecimalFunctions.h
浏览文件 @
bf318701
...
...
@@ -6,6 +6,7 @@
#include <common/arithmeticOverflow.h>
#include <limits>
#include <type_traits>
namespace
DB
...
...
src/Functions/FunctionBinaryArithmetic.h
浏览文件 @
bf318701
此差异已折叠。
点击以展开。
src/Functions/intDiv.cpp
浏览文件 @
bf318701
...
...
@@ -88,6 +88,8 @@ struct DivideIntegralByConstantImpl
}
namespace
impl_
{
template
<
>
struct
BinaryOperationImpl
<
UInt64
,
UInt8
,
DivideIntegralImpl
<
UInt64
,
UInt8
>>
:
DivideIntegralByConstantImpl
<
UInt64
,
UInt8
>
{};
template
<
>
struct
BinaryOperationImpl
<
UInt64
,
UInt16
,
DivideIntegralImpl
<
UInt64
,
UInt16
>>
:
DivideIntegralByConstantImpl
<
UInt64
,
UInt16
>
{};
template
<
>
struct
BinaryOperationImpl
<
UInt64
,
UInt32
,
DivideIntegralImpl
<
UInt64
,
UInt32
>>
:
DivideIntegralByConstantImpl
<
UInt64
,
UInt32
>
{};
...
...
@@ -107,7 +109,7 @@ template <> struct BinaryOperationImpl<Int32, Int8, DivideIntegralImpl<Int32, In
template
<
>
struct
BinaryOperationImpl
<
Int32
,
Int16
,
DivideIntegralImpl
<
Int32
,
Int16
>>
:
DivideIntegralByConstantImpl
<
Int32
,
Int16
>
{};
template
<
>
struct
BinaryOperationImpl
<
Int32
,
Int32
,
DivideIntegralImpl
<
Int32
,
Int32
>>
:
DivideIntegralByConstantImpl
<
Int32
,
Int32
>
{};
template
<
>
struct
BinaryOperationImpl
<
Int32
,
Int64
,
DivideIntegralImpl
<
Int32
,
Int64
>>
:
DivideIntegralByConstantImpl
<
Int32
,
Int64
>
{};
}
struct
NameIntDiv
{
static
constexpr
auto
name
=
"intDiv"
;
};
using
FunctionIntDiv
=
BinaryArithmeticOverloadResolver
<
DivideIntegralImpl
,
NameIntDiv
,
false
>
;
...
...
src/Functions/modulo.cpp
浏览文件 @
bf318701
...
...
@@ -79,6 +79,8 @@ struct ModuloByConstantImpl
* Can be expanded to all possible combinations, but more code is needed.
*/
namespace
impl_
{
template
<
>
struct
BinaryOperationImpl
<
UInt64
,
UInt8
,
ModuloImpl
<
UInt64
,
UInt8
>>
:
ModuloByConstantImpl
<
UInt64
,
UInt8
>
{};
template
<
>
struct
BinaryOperationImpl
<
UInt64
,
UInt16
,
ModuloImpl
<
UInt64
,
UInt16
>>
:
ModuloByConstantImpl
<
UInt64
,
UInt16
>
{};
template
<
>
struct
BinaryOperationImpl
<
UInt64
,
UInt32
,
ModuloImpl
<
UInt64
,
UInt32
>>
:
ModuloByConstantImpl
<
UInt64
,
UInt32
>
{};
...
...
@@ -98,7 +100,7 @@ template <> struct BinaryOperationImpl<Int32, Int8, ModuloImpl<Int32, Int8>> : M
template
<
>
struct
BinaryOperationImpl
<
Int32
,
Int16
,
ModuloImpl
<
Int32
,
Int16
>>
:
ModuloByConstantImpl
<
Int32
,
Int16
>
{};
template
<
>
struct
BinaryOperationImpl
<
Int32
,
Int32
,
ModuloImpl
<
Int32
,
Int32
>>
:
ModuloByConstantImpl
<
Int32
,
Int32
>
{};
template
<
>
struct
BinaryOperationImpl
<
Int32
,
Int64
,
ModuloImpl
<
Int32
,
Int64
>>
:
ModuloByConstantImpl
<
Int32
,
Int64
>
{};
}
struct
NameModulo
{
static
constexpr
auto
name
=
"modulo"
;
};
using
FunctionModulo
=
BinaryArithmeticOverloadResolver
<
ModuloImpl
,
NameModulo
,
false
>
;
...
...
src/Functions/multiply.cpp
浏览文件 @
bf318701
#include <type_traits>
#include <Functions/FunctionFactory.h>
#include <Functions/FunctionBinaryArithmetic.h>
#include <common/arithmeticOverflow.h>
...
...
@@ -25,10 +26,16 @@ struct MultiplyImpl
return
static_cast
<
Result
>
(
a
)
*
b
;
}
/// Apply operation and check overflow. It's used for Deci
a
mal operations. @returns true if overflowed, false otherwise.
/// Apply operation and check overflow. It's used for Decimal operations. @returns true if overflowed, false otherwise.
template
<
typename
Result
=
ResultType
>
static
inline
bool
apply
(
A
a
,
B
b
,
Result
&
c
)
{
if
constexpr
(
std
::
is_same_v
<
Result
,
float
>
||
std
::
is_same_v
<
Result
,
double
>
)
{
c
=
static_cast
<
Result
>
(
a
)
*
b
;
return
false
;
}
else
return
common
::
mulOverflow
(
static_cast
<
Result
>
(
a
),
b
,
c
);
}
...
...
tests/queries/0_stateless/01603_decimal_mult_float.reference
0 → 100644
浏览文件 @
bf318701
2.4
10.165
0.00012000000000000002
150.16500000000002
7.775900000000001
56.62269
598.8376688440277
299.41883723437786
0.7485470860550345
2.245641373854596
1.641386318314034
1.641386318314034
1.641386334333447
1.641386334333447
tests/queries/0_stateless/01603_decimal_mult_float.sql
0 → 100644
浏览文件 @
bf318701
SELECT
toDecimal32
(
2
,
2
)
*
1
.
2
;
SELECT
toDecimal64
(
0
.
5
,
2
)
*
20
.
33
;
SELECT
0
.
00001
*
toDecimal32
(
12
,
2
);
SELECT
30
.
033
*
toDecimal32
(
5
,
1
);
CREATE
TABLE
IF
NOT
EXISTS
test01603
(
f64
Float64
,
d
Decimal64
(
3
)
DEFAULT
toDecimal32
(
f64
,
3
),
f32
Float32
DEFAULT
f64
)
ENGINE
=
MergeTree
()
ORDER
BY
f32
;
INSERT
INTO
test01603
(
f64
)
SELECT
1
/
(
number
+
1
)
FROM
system
.
numbers
LIMIT
1000
;
SELECT
sum
(
d
*
1
.
1
)
FROM
test01603
;
SELECT
sum
(
8
.
01
*
d
)
FROM
test01603
;
SELECT
sum
(
f64
*
toDecimal64
(
80
,
2
))
FROM
test01603
;
SELECT
sum
(
toDecimal64
(
40
,
2
)
*
f32
)
FROM
test01603
;
SELECT
sum
(
f64
*
toDecimal64
(
0
.
1
,
2
))
FROM
test01603
;
SELECT
sum
(
toDecimal64
(
0
.
3
,
2
)
*
f32
)
FROM
test01603
;
SELECT
sum
(
f64
*
d
)
FROM
test01603
;
SELECT
sum
(
d
*
f64
)
FROM
test01603
;
SELECT
sum
(
f32
*
d
)
FROM
test01603
;
SELECT
sum
(
d
*
f32
)
FROM
test01603
;
DROP
TABLE
IF
EXISTS
test01603
;
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录