Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
2dot5
ClickHouse
提交
95060b1a
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,发现更多精彩内容 >>
提交
95060b1a
编写于
12月 20, 2012
作者:
A
Alexey Milovidov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
dbms: added more bitwise functions [#CONV-2944].
上级
1383bfd0
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
100 addition
and
226 deletion
+100
-226
dbms/include/DB/Functions/FunctionsArithmetic.h
dbms/include/DB/Functions/FunctionsArithmetic.h
+92
-226
dbms/include/DB/Functions/NumberTraits.h
dbms/include/DB/Functions/NumberTraits.h
+8
-0
未找到文件。
dbms/include/DB/Functions/FunctionsArithmetic.h
浏览文件 @
95060b1a
...
...
@@ -12,103 +12,91 @@ namespace DB
/** Арифметические функции: +, -, *, /, %,
* intDiv (целочисленное деление), унарный минус.
* Битовые функции: |, &, ^, ~.
*/
template
<
typename
A
,
typename
B
>
struct
Plus
Impl
template
<
typename
A
,
typename
B
,
typename
Op
>
struct
BinaryOperation
Impl
{
typedef
typename
NumberTraits
::
ResultOfAdditionMultiplication
<
A
,
B
>::
Type
ResultType
;
typedef
typename
Op
::
Result
Type
ResultType
;
static
void
vector_vector
(
const
std
::
vector
<
A
>
&
a
,
const
std
::
vector
<
B
>
&
b
,
std
::
vector
<
ResultType
>
&
c
)
{
/// Далее везде, static_cast - чтобы не было неправильного результата в выражениях вида Int64 c = UInt32(a) * Int32(-1).
size_t
size
=
a
.
size
();
for
(
size_t
i
=
0
;
i
<
size
;
++
i
)
c
[
i
]
=
static_cast
<
ResultType
>
(
a
[
i
])
+
b
[
i
]
;
c
[
i
]
=
Op
::
apply
(
a
[
i
],
b
[
i
])
;
}
static
void
vector_constant
(
const
std
::
vector
<
A
>
&
a
,
B
b
,
std
::
vector
<
ResultType
>
&
c
)
{
size_t
size
=
a
.
size
();
for
(
size_t
i
=
0
;
i
<
size
;
++
i
)
c
[
i
]
=
static_cast
<
ResultType
>
(
a
[
i
])
+
b
;
c
[
i
]
=
Op
::
apply
(
a
[
i
],
b
)
;
}
static
void
constant_vector
(
A
a
,
const
std
::
vector
<
B
>
&
b
,
std
::
vector
<
ResultType
>
&
c
)
{
size_t
size
=
b
.
size
();
for
(
size_t
i
=
0
;
i
<
size
;
++
i
)
c
[
i
]
=
static_cast
<
ResultType
>
(
a
)
+
b
[
i
]
;
c
[
i
]
=
Op
::
apply
(
a
,
b
[
i
])
;
}
static
void
constant_constant
(
A
a
,
B
b
,
ResultType
&
c
)
{
c
=
static_cast
<
ResultType
>
(
a
)
+
b
;
c
=
Op
::
apply
(
a
,
b
)
;
}
};
template
<
typename
A
,
typename
B
>
struct
Multiply
Impl
template
<
typename
A
,
typename
Op
>
struct
UnaryOperation
Impl
{
typedef
typename
NumberTraits
::
ResultOfAdditionMultiplication
<
A
,
B
>::
Type
ResultType
;
typedef
typename
Op
::
Result
Type
ResultType
;
static
void
vector
_vector
(
const
std
::
vector
<
A
>
&
a
,
const
std
::
vector
<
B
>
&
b
,
std
::
vector
<
ResultType
>
&
c
)
static
void
vector
(
const
std
::
vector
<
A
>
&
a
,
std
::
vector
<
ResultType
>
&
c
)
{
size_t
size
=
a
.
size
();
for
(
size_t
i
=
0
;
i
<
size
;
++
i
)
c
[
i
]
=
static_cast
<
ResultType
>
(
a
[
i
])
*
b
[
i
]
;
c
[
i
]
=
Op
::
apply
(
a
[
i
])
;
}
static
void
vector_constant
(
const
std
::
vector
<
A
>
&
a
,
B
b
,
std
::
vector
<
ResultType
>
&
c
)
static
void
constant
(
A
a
,
ResultType
&
c
)
{
size_t
size
=
a
.
size
();
for
(
size_t
i
=
0
;
i
<
size
;
++
i
)
c
[
i
]
=
static_cast
<
ResultType
>
(
a
[
i
])
*
b
;
c
=
Op
::
apply
(
a
);
}
};
static
void
constant_vector
(
A
a
,
const
std
::
vector
<
B
>
&
b
,
std
::
vector
<
ResultType
>
&
c
)
{
size_t
size
=
b
.
size
();
for
(
size_t
i
=
0
;
i
<
size
;
++
i
)
c
[
i
]
=
static_cast
<
ResultType
>
(
a
)
*
b
[
i
];
}
static
void
constant_constant
(
A
a
,
B
b
,
ResultType
&
c
)
template
<
typename
A
,
typename
B
>
struct
PlusImpl
{
typedef
typename
NumberTraits
::
ResultOfAdditionMultiplication
<
A
,
B
>::
Type
ResultType
;
static
inline
ResultType
apply
(
A
a
,
B
b
)
{
c
=
static_cast
<
ResultType
>
(
a
)
*
b
;
/// Далее везде, static_cast - чтобы не было неправильного результата в выражениях вида Int64 c = UInt32(a) * Int32(-1).
return
static_cast
<
ResultType
>
(
a
)
+
b
;
}
};
template
<
typename
A
,
typename
B
>
struct
M
inus
Impl
struct
M
ultiply
Impl
{
typedef
typename
NumberTraits
::
ResultOfSubtraction
<
A
,
B
>::
Type
ResultType
;
static
void
vector_vector
(
const
std
::
vector
<
A
>
&
a
,
const
std
::
vector
<
B
>
&
b
,
std
::
vector
<
ResultType
>
&
c
)
{
size_t
size
=
a
.
size
();
for
(
size_t
i
=
0
;
i
<
size
;
++
i
)
c
[
i
]
=
static_cast
<
ResultType
>
(
a
[
i
])
-
b
[
i
];
}
typedef
typename
NumberTraits
::
ResultOfAdditionMultiplication
<
A
,
B
>::
Type
ResultType
;
static
void
vector_constant
(
const
std
::
vector
<
A
>
&
a
,
B
b
,
std
::
vector
<
ResultType
>
&
c
)
static
inline
ResultType
apply
(
A
a
,
B
b
)
{
size_t
size
=
a
.
size
();
for
(
size_t
i
=
0
;
i
<
size
;
++
i
)
c
[
i
]
=
static_cast
<
ResultType
>
(
a
[
i
])
-
b
;
return
static_cast
<
ResultType
>
(
a
)
*
b
;
}
};
static
void
constant_vector
(
A
a
,
const
std
::
vector
<
B
>
&
b
,
std
::
vector
<
ResultType
>
&
c
)
{
size_t
size
=
b
.
size
();
for
(
size_t
i
=
0
;
i
<
size
;
++
i
)
c
[
i
]
=
static_cast
<
ResultType
>
(
a
)
-
b
[
i
];
}
template
<
typename
A
,
typename
B
>
struct
MinusImpl
{
typedef
typename
NumberTraits
::
ResultOfSubtraction
<
A
,
B
>::
Type
ResultType
;
static
void
constant_constant
(
A
a
,
B
b
,
ResultType
&
c
)
static
inline
ResultType
apply
(
A
a
,
B
b
)
{
c
=
static_cast
<
ResultType
>
(
a
)
-
b
;
return
static_cast
<
ResultType
>
(
a
)
-
b
;
}
};
...
...
@@ -117,30 +105,9 @@ struct DivideFloatingImpl
{
typedef
typename
NumberTraits
::
ResultOfFloatingPointDivision
<
A
,
B
>::
Type
ResultType
;
static
void
vector_vector
(
const
std
::
vector
<
A
>
&
a
,
const
std
::
vector
<
B
>
&
b
,
std
::
vector
<
ResultType
>
&
c
)
{
size_t
size
=
a
.
size
();
for
(
size_t
i
=
0
;
i
<
size
;
++
i
)
c
[
i
]
=
static_cast
<
ResultType
>
(
a
[
i
])
/
b
[
i
];
}
static
void
vector_constant
(
const
std
::
vector
<
A
>
&
a
,
B
b
,
std
::
vector
<
ResultType
>
&
c
)
{
size_t
size
=
a
.
size
();
for
(
size_t
i
=
0
;
i
<
size
;
++
i
)
c
[
i
]
=
static_cast
<
ResultType
>
(
a
[
i
])
/
b
;
}
static
void
constant_vector
(
A
a
,
const
std
::
vector
<
B
>
&
b
,
std
::
vector
<
ResultType
>
&
c
)
{
size_t
size
=
b
.
size
();
for
(
size_t
i
=
0
;
i
<
size
;
++
i
)
c
[
i
]
=
static_cast
<
ResultType
>
(
a
)
/
b
[
i
];
}
static
void
constant_constant
(
A
a
,
B
b
,
ResultType
&
c
)
static
inline
ResultType
apply
(
A
a
,
B
b
)
{
c
=
static_cast
<
ResultType
>
(
a
)
/
b
;
return
static_cast
<
ResultType
>
(
a
)
/
b
;
}
};
...
...
@@ -157,40 +124,10 @@ struct DivideIntegralImpl
{
typedef
typename
NumberTraits
::
ResultOfIntegerDivision
<
A
,
B
>::
Type
ResultType
;
static
void
vector_vector
(
const
std
::
vector
<
A
>
&
a
,
const
std
::
vector
<
B
>
&
b
,
std
::
vector
<
ResultType
>
&
c
)
{
size_t
size
=
a
.
size
();
for
(
size_t
i
=
0
;
i
<
size
;
++
i
)
{
throwIfZero
(
b
[
i
]);
c
[
i
]
=
static_cast
<
ResultType
>
(
a
[
i
])
/
b
[
i
];
}
}
static
void
vector_constant
(
const
std
::
vector
<
A
>
&
a
,
B
b
,
std
::
vector
<
ResultType
>
&
c
)
{
size_t
size
=
a
.
size
();
for
(
size_t
i
=
0
;
i
<
size
;
++
i
)
{
throwIfZero
(
b
);
c
[
i
]
=
static_cast
<
ResultType
>
(
a
[
i
])
/
b
;
}
}
static
void
constant_vector
(
A
a
,
const
std
::
vector
<
B
>
&
b
,
std
::
vector
<
ResultType
>
&
c
)
{
size_t
size
=
b
.
size
();
for
(
size_t
i
=
0
;
i
<
size
;
++
i
)
{
throwIfZero
(
b
[
i
]);
c
[
i
]
=
static_cast
<
ResultType
>
(
a
)
/
b
[
i
];
}
}
static
void
constant_constant
(
A
a
,
B
b
,
ResultType
&
c
)
static
inline
ResultType
apply
(
A
a
,
B
b
)
{
throwIfZero
(
b
);
c
=
static_cast
<
ResultType
>
(
a
)
/
b
;
return
static_cast
<
ResultType
>
(
a
)
/
b
;
}
};
...
...
@@ -199,43 +136,10 @@ struct ModuloImpl
{
typedef
typename
NumberTraits
::
ResultOfModulo
<
A
,
B
>::
Type
ResultType
;
static
void
vector_vector
(
const
std
::
vector
<
A
>
&
a
,
const
std
::
vector
<
B
>
&
b
,
std
::
vector
<
ResultType
>
&
c
)
{
size_t
size
=
a
.
size
();
for
(
size_t
i
=
0
;
i
<
size
;
++
i
)
{
throwIfZero
(
typename
NumberTraits
::
ToInteger
<
A
>::
Type
(
b
[
i
]));
c
[
i
]
=
typename
NumberTraits
::
ToInteger
<
A
>::
Type
(
a
[
i
])
%
typename
NumberTraits
::
ToInteger
<
A
>::
Type
(
b
[
i
]);
}
}
static
void
vector_constant
(
const
std
::
vector
<
A
>
&
a
,
B
b
,
std
::
vector
<
ResultType
>
&
c
)
{
size_t
size
=
a
.
size
();
for
(
size_t
i
=
0
;
i
<
size
;
++
i
)
{
throwIfZero
(
typename
NumberTraits
::
ToInteger
<
A
>::
Type
(
b
));
c
[
i
]
=
typename
NumberTraits
::
ToInteger
<
A
>::
Type
(
a
[
i
])
%
typename
NumberTraits
::
ToInteger
<
A
>::
Type
(
b
);
}
}
static
void
constant_vector
(
A
a
,
const
std
::
vector
<
B
>
&
b
,
std
::
vector
<
ResultType
>
&
c
)
{
size_t
size
=
b
.
size
();
for
(
size_t
i
=
0
;
i
<
size
;
++
i
)
{
throwIfZero
(
typename
NumberTraits
::
ToInteger
<
A
>::
Type
(
b
[
i
]));
c
[
i
]
=
typename
NumberTraits
::
ToInteger
<
A
>::
Type
(
a
)
%
typename
NumberTraits
::
ToInteger
<
A
>::
Type
(
b
[
i
]);
}
}
static
void
constant_constant
(
A
a
,
B
b
,
ResultType
&
c
)
static
inline
ResultType
apply
(
A
a
,
B
b
)
{
throwIfZero
(
typename
NumberTraits
::
ToInteger
<
A
>::
Type
(
b
));
c
=
typename
NumberTraits
::
ToInteger
<
A
>::
Type
(
a
)
return
typename
NumberTraits
::
ToInteger
<
A
>::
Type
(
a
)
%
typename
NumberTraits
::
ToInteger
<
A
>::
Type
(
b
);
}
};
...
...
@@ -245,39 +149,9 @@ struct BitwiseAndImpl
{
typedef
typename
NumberTraits
::
ResultOfBitwise
<
A
,
B
>::
Type
ResultType
;
static
void
vector_vector
(
const
std
::
vector
<
A
>
&
a
,
const
std
::
vector
<
B
>
&
b
,
std
::
vector
<
ResultType
>
&
c
)
{
size_t
size
=
a
.
size
();
for
(
size_t
i
=
0
;
i
<
size
;
++
i
)
{
c
[
i
]
=
static_cast
<
ResultType
>
(
a
[
i
])
&
static_cast
<
ResultType
>
(
b
[
i
]);
}
}
static
void
vector_constant
(
const
std
::
vector
<
A
>
&
a
,
B
b
,
std
::
vector
<
ResultType
>
&
c
)
{
size_t
size
=
a
.
size
();
for
(
size_t
i
=
0
;
i
<
size
;
++
i
)
{
c
[
i
]
=
static_cast
<
ResultType
>
(
a
[
i
])
&
static_cast
<
ResultType
>
(
b
);
}
}
static
void
constant_vector
(
A
a
,
const
std
::
vector
<
B
>
&
b
,
std
::
vector
<
ResultType
>
&
c
)
{
size_t
size
=
b
.
size
();
for
(
size_t
i
=
0
;
i
<
size
;
++
i
)
{
c
[
i
]
=
static_cast
<
ResultType
>
(
a
)
&
static_cast
<
ResultType
>
(
b
[
i
]);
}
}
static
void
constant_constant
(
A
a
,
B
b
,
ResultType
&
c
)
static
inline
ResultType
apply
(
A
a
,
B
b
)
{
c
=
static_cast
<
ResultType
>
(
a
)
return
static_cast
<
ResultType
>
(
a
)
&
static_cast
<
ResultType
>
(
b
);
}
};
...
...
@@ -287,40 +161,22 @@ struct BitwiseOrImpl
{
typedef
typename
NumberTraits
::
ResultOfBitwise
<
A
,
B
>::
Type
ResultType
;
static
void
vector_vector
(
const
std
::
vector
<
A
>
&
a
,
const
std
::
vector
<
B
>
&
b
,
std
::
vector
<
ResultType
>
&
c
)
{
size_t
size
=
a
.
size
();
for
(
size_t
i
=
0
;
i
<
size
;
++
i
)
{
c
[
i
]
=
static_cast
<
ResultType
>
(
a
[
i
])
|
static_cast
<
ResultType
>
(
b
[
i
]);
}
}
static
void
vector_constant
(
const
std
::
vector
<
A
>
&
a
,
B
b
,
std
::
vector
<
ResultType
>
&
c
)
{
size_t
size
=
a
.
size
();
for
(
size_t
i
=
0
;
i
<
size
;
++
i
)
{
c
[
i
]
=
static_cast
<
ResultType
>
(
a
[
i
])
|
static_cast
<
ResultType
>
(
b
);
}
}
static
void
constant_vector
(
A
a
,
const
std
::
vector
<
B
>
&
b
,
std
::
vector
<
ResultType
>
&
c
)
static
inline
ResultType
apply
(
A
a
,
B
b
)
{
size_t
size
=
b
.
size
();
for
(
size_t
i
=
0
;
i
<
size
;
++
i
)
{
c
[
i
]
=
static_cast
<
ResultType
>
(
a
)
|
static_cast
<
ResultType
>
(
b
[
i
]);
}
return
static_cast
<
ResultType
>
(
a
)
|
static_cast
<
ResultType
>
(
b
);
}
static
void
constant_constant
(
A
a
,
B
b
,
ResultType
&
c
)
};
template
<
typename
A
,
typename
B
>
struct
BitwiseXorImpl
{
typedef
typename
NumberTraits
::
ResultOfBitwise
<
A
,
B
>::
Type
ResultType
;
static
inline
ResultType
apply
(
A
a
,
B
b
)
{
c
=
static_cast
<
ResultType
>
(
a
)
|
static_cast
<
ResultType
>
(
b
);
return
static_cast
<
ResultType
>
(
a
)
^
static_cast
<
ResultType
>
(
b
);
}
};
...
...
@@ -329,21 +185,26 @@ struct NegateImpl
{
typedef
typename
NumberTraits
::
ResultOfNegate
<
A
>::
Type
ResultType
;
static
void
vector
(
const
std
::
vector
<
A
>
&
a
,
std
::
vector
<
ResultType
>
&
c
)
static
inline
ResultType
apply
(
A
a
)
{
size_t
size
=
a
.
size
();
for
(
size_t
i
=
0
;
i
<
size
;
++
i
)
c
[
i
]
=
-
a
[
i
];
return
-
a
;
}
};
static
void
constant
(
A
a
,
ResultType
&
c
)
template
<
typename
A
>
struct
BitwiseNotImpl
{
typedef
typename
NumberTraits
::
ResultOfBitwiseNot
<
A
>::
Type
ResultType
;
static
inline
ResultType
apply
(
A
a
)
{
c
=
-
a
;
return
~
static_cast
<
ResultType
>
(
a
)
;
}
};
template
<
template
<
typename
,
typename
>
class
Impl
,
typename
Name
>
template
<
template
<
typename
,
typename
>
class
Op
,
typename
Name
>
class
FunctionBinaryArithmetic
:
public
IFunction
{
private:
...
...
@@ -353,7 +214,7 @@ private:
if
(
dynamic_cast
<
const
T1
*>
(
&*
arguments
[
1
]))
{
type_res
=
new
typename
DataTypeFromFieldType
<
typename
Impl
<
typename
T0
::
FieldType
,
typename
T1
::
FieldType
>::
ResultType
>::
Type
;
typename
Op
<
typename
T0
::
FieldType
,
typename
T1
::
FieldType
>::
ResultType
>::
Type
;
return
true
;
}
return
false
;
...
...
@@ -388,27 +249,27 @@ private:
{
if
(
ColumnVector
<
T1
>
*
col_right
=
dynamic_cast
<
ColumnVector
<
T1
>
*>
(
&*
block
.
getByPosition
(
arguments
[
1
]).
column
))
{
typedef
typename
Impl
<
T0
,
T1
>::
ResultType
ResultType
;
typedef
typename
Op
<
T0
,
T1
>::
ResultType
ResultType
;
ColumnVector
<
ResultType
>
*
col_res
=
new
ColumnVector
<
ResultType
>
;
block
.
getByPosition
(
result
).
column
=
col_res
;
typename
ColumnVector
<
ResultType
>::
Container_t
&
vec_res
=
col_res
->
getData
();
vec_res
.
resize
(
col_left
->
getData
().
size
());
Impl
<
T0
,
T1
>::
vector_vector
(
col_left
->
getData
(),
col_right
->
getData
(),
vec_res
);
BinaryOperationImpl
<
T0
,
T1
,
Op
<
T0
,
T1
>
>::
vector_vector
(
col_left
->
getData
(),
col_right
->
getData
(),
vec_res
);
return
true
;
}
else
if
(
ColumnConst
<
T1
>
*
col_right
=
dynamic_cast
<
ColumnConst
<
T1
>
*>
(
&*
block
.
getByPosition
(
arguments
[
1
]).
column
))
{
typedef
typename
Impl
<
T0
,
T1
>::
ResultType
ResultType
;
typedef
typename
Op
<
T0
,
T1
>::
ResultType
ResultType
;
ColumnVector
<
ResultType
>
*
col_res
=
new
ColumnVector
<
ResultType
>
;
block
.
getByPosition
(
result
).
column
=
col_res
;
typename
ColumnVector
<
ResultType
>::
Container_t
&
vec_res
=
col_res
->
getData
();
vec_res
.
resize
(
col_left
->
getData
().
size
());
Impl
<
T0
,
T1
>::
vector_constant
(
col_left
->
getData
(),
col_right
->
getData
(),
vec_res
);
BinaryOperationImpl
<
T0
,
T1
,
Op
<
T0
,
T1
>
>::
vector_constant
(
col_left
->
getData
(),
col_right
->
getData
(),
vec_res
);
return
true
;
}
...
...
@@ -421,23 +282,23 @@ private:
{
if
(
ColumnVector
<
T1
>
*
col_right
=
dynamic_cast
<
ColumnVector
<
T1
>
*>
(
&*
block
.
getByPosition
(
arguments
[
1
]).
column
))
{
typedef
typename
Impl
<
T0
,
T1
>::
ResultType
ResultType
;
typedef
typename
Op
<
T0
,
T1
>::
ResultType
ResultType
;
ColumnVector
<
ResultType
>
*
col_res
=
new
ColumnVector
<
ResultType
>
;
block
.
getByPosition
(
result
).
column
=
col_res
;
typename
ColumnVector
<
ResultType
>::
Container_t
&
vec_res
=
col_res
->
getData
();
vec_res
.
resize
(
col_left
->
size
());
Impl
<
T0
,
T1
>::
constant_vector
(
col_left
->
getData
(),
col_right
->
getData
(),
vec_res
);
BinaryOperationImpl
<
T0
,
T1
,
Op
<
T0
,
T1
>
>::
constant_vector
(
col_left
->
getData
(),
col_right
->
getData
(),
vec_res
);
return
true
;
}
else
if
(
ColumnConst
<
T1
>
*
col_right
=
dynamic_cast
<
ColumnConst
<
T1
>
*>
(
&*
block
.
getByPosition
(
arguments
[
1
]).
column
))
{
typedef
typename
Impl
<
T0
,
T1
>::
ResultType
ResultType
;
typedef
typename
Op
<
T0
,
T1
>::
ResultType
ResultType
;
ResultType
res
=
0
;
Impl
<
T0
,
T1
>::
constant_constant
(
col_left
->
getData
(),
col_right
->
getData
(),
res
);
BinaryOperationImpl
<
T0
,
T1
,
Op
<
T0
,
T1
>
>::
constant_constant
(
col_left
->
getData
(),
col_right
->
getData
(),
res
);
ColumnConst
<
ResultType
>
*
col_res
=
new
ColumnConst
<
ResultType
>
(
col_left
->
size
(),
res
);
block
.
getByPosition
(
result
).
column
=
col_res
;
...
...
@@ -544,7 +405,7 @@ public:
};
template
<
template
<
typename
>
class
Impl
,
typename
Name
>
template
<
template
<
typename
>
class
Op
,
typename
Name
>
class
FunctionUnaryArithmetic
:
public
IFunction
{
private:
...
...
@@ -554,7 +415,7 @@ private:
if
(
dynamic_cast
<
const
T0
*>
(
&*
arguments
[
0
]))
{
result
=
new
typename
DataTypeFromFieldType
<
typename
Impl
<
typename
T0
::
FieldType
>::
ResultType
>::
Type
;
typename
Op
<
typename
T0
::
FieldType
>::
ResultType
>::
Type
;
return
true
;
}
return
false
;
...
...
@@ -565,23 +426,23 @@ private:
{
if
(
ColumnVector
<
T0
>
*
col
=
dynamic_cast
<
ColumnVector
<
T0
>
*>
(
&*
block
.
getByPosition
(
arguments
[
0
]).
column
))
{
typedef
typename
Impl
<
T0
>::
ResultType
ResultType
;
typedef
typename
Op
<
T0
>::
ResultType
ResultType
;
ColumnVector
<
ResultType
>
*
col_res
=
new
ColumnVector
<
ResultType
>
;
block
.
getByPosition
(
result
).
column
=
col_res
;
typename
ColumnVector
<
ResultType
>::
Container_t
&
vec_res
=
col_res
->
getData
();
vec_res
.
resize
(
col
->
getData
().
size
());
Impl
<
T0
>::
vector
(
col
->
getData
(),
vec_res
);
UnaryOperationImpl
<
T0
,
Op
<
T0
>
>::
vector
(
col
->
getData
(),
vec_res
);
return
true
;
}
else
if
(
ColumnConst
<
T0
>
*
col
=
dynamic_cast
<
ColumnConst
<
T0
>
*>
(
&*
block
.
getByPosition
(
arguments
[
0
]).
column
))
{
typedef
typename
Impl
<
T0
>::
ResultType
ResultType
;
typedef
typename
Op
<
T0
>::
ResultType
ResultType
;
ResultType
res
=
0
;
Impl
<
T0
>::
constant
(
col
->
getData
(),
res
);
UnaryOperationImpl
<
T0
,
Op
<
T0
>
>::
constant
(
col
->
getData
(),
res
);
ColumnConst
<
ResultType
>
*
col_res
=
new
ColumnConst
<
ResultType
>
(
col
->
size
(),
res
);
block
.
getByPosition
(
result
).
column
=
col_res
;
...
...
@@ -651,9 +512,11 @@ struct NameMultiply { static const char * get() { return "multiply"; } };
struct
NameDivideFloating
{
static
const
char
*
get
()
{
return
"divide"
;
}
};
struct
NameDivideIntegral
{
static
const
char
*
get
()
{
return
"intDiv"
;
}
};
struct
NameModulo
{
static
const
char
*
get
()
{
return
"modulo"
;
}
};
struct
NameNegate
{
static
const
char
*
get
()
{
return
"negate"
;
}
};
struct
NameBitwiseAnd
{
static
const
char
*
get
()
{
return
"bitwiseAnd"
;
}
};
struct
NameBitwiseOr
{
static
const
char
*
get
()
{
return
"bitwiseOr"
;
}
};
struct
NameNegate
{
static
const
char
*
get
()
{
return
"negate"
;
}
};
struct
NameBitwiseXor
{
static
const
char
*
get
()
{
return
"bitwiseXor"
;
}
};
struct
NameBitwiseNot
{
static
const
char
*
get
()
{
return
"bitwiseNot"
;
}
};
typedef
FunctionBinaryArithmetic
<
PlusImpl
,
NamePlus
>
FunctionPlus
;
typedef
FunctionBinaryArithmetic
<
MinusImpl
,
NameMinus
>
FunctionMinus
;
...
...
@@ -661,9 +524,12 @@ typedef FunctionBinaryArithmetic<MultiplyImpl, NameMultiply> FunctionMultipl
typedef
FunctionBinaryArithmetic
<
DivideFloatingImpl
,
NameDivideFloating
>
FunctionDivideFloating
;
typedef
FunctionBinaryArithmetic
<
DivideIntegralImpl
,
NameDivideIntegral
>
FunctionDivideIntegral
;
typedef
FunctionBinaryArithmetic
<
ModuloImpl
,
NameModulo
>
FunctionModulo
;
typedef
FunctionBinaryArithmetic
<
BitwiseAndImpl
,
NameBitwiseAnd
>
FunctionBitwiseAnd
;
typedef
FunctionBinaryArithmetic
<
BitwiseOrImpl
,
NameBitwiseOr
>
FunctionBitwiseOr
;
typedef
FunctionUnaryArithmetic
<
NegateImpl
,
NameNegate
>
FunctionNegate
;
typedef
FunctionBinaryArithmetic
<
BitwiseAndImpl
,
NameBitwiseAnd
>
FunctionBitwiseAnd
;
typedef
FunctionBinaryArithmetic
<
BitwiseOrImpl
,
NameBitwiseOr
>
FunctionBitwiseOr
;
typedef
FunctionBinaryArithmetic
<
BitwiseXorImpl
,
NameBitwiseXor
>
FunctionBitwiseXor
;
typedef
FunctionUnaryArithmetic
<
BitwiseNotImpl
,
NameBitwiseNot
>
FunctionBitwiseNot
;
}
dbms/include/DB/Functions/NumberTraits.h
浏览文件 @
95060b1a
...
...
@@ -163,6 +163,14 @@ namespace NumberTraits
Bits64
,
typename
Traits
<
B
>::
Bits
>::
type
>::
type
>::
Type
Type
;
};
template
<
typename
A
>
struct
ResultOfBitwiseNot
{
typedef
typename
Construct
<
typename
Traits
<
A
>::
Sign
,
Integer
,
typename
Traits
<
A
>::
Bits
>::
Type
Type
;
};
/** Перед применением оператора % и побитовых операций, операнды приводятся к целым числам. */
template
<
typename
A
>
struct
ToInteger
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录