Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
jobily
Questdb
提交
6767dfe4
Q
Questdb
项目概览
jobily
/
Questdb
大约 1 年 前同步成功
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
Q
Questdb
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
6767dfe4
编写于
5月 23, 2021
作者:
V
Vlad Ilyushchenko
提交者:
GitHub
5月 23, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat(sql): bitwise ops implementation (#1046)
上级
3cb01d42
变更
16
隐藏空白更改
内联
并排
Showing
16 changed file
with
839 addition
and
5 deletion
+839
-5
core/src/main/java/io/questdb/griffin/ExpressionParser.java
core/src/main/java/io/questdb/griffin/ExpressionParser.java
+1
-1
core/src/main/java/io/questdb/griffin/OperatorExpression.java
.../src/main/java/io/questdb/griffin/OperatorExpression.java
+3
-1
core/src/main/java/io/questdb/griffin/engine/functions/math/BitwiseAndIntFunctionFactory.java
...n/engine/functions/math/BitwiseAndIntFunctionFactory.java
+76
-0
core/src/main/java/io/questdb/griffin/engine/functions/math/BitwiseAndLongFunctionFactory.java
.../engine/functions/math/BitwiseAndLongFunctionFactory.java
+76
-0
core/src/main/java/io/questdb/griffin/engine/functions/math/BitwiseNotIntFunctionFactory.java
...n/engine/functions/math/BitwiseNotIntFunctionFactory.java
+68
-0
core/src/main/java/io/questdb/griffin/engine/functions/math/BitwiseNotLongFunctionFactory.java
.../engine/functions/math/BitwiseNotLongFunctionFactory.java
+69
-0
core/src/main/java/io/questdb/griffin/engine/functions/math/BitwiseOrIntFunctionFactory.java
...in/engine/functions/math/BitwiseOrIntFunctionFactory.java
+76
-0
core/src/main/java/io/questdb/griffin/engine/functions/math/BitwiseOrLongFunctionFactory.java
...n/engine/functions/math/BitwiseOrLongFunctionFactory.java
+76
-0
core/src/main/java/io/questdb/griffin/engine/functions/math/BitwiseXorIntFunctionFactory.java
...n/engine/functions/math/BitwiseXorIntFunctionFactory.java
+76
-0
core/src/main/java/io/questdb/griffin/engine/functions/math/BitwiseXorLongFunctionFactory.java
.../engine/functions/math/BitwiseXorLongFunctionFactory.java
+76
-0
core/src/main/java/io/questdb/griffin/engine/functions/math/PowDoubleFunctionFactory.java
...iffin/engine/functions/math/PowDoubleFunctionFactory.java
+1
-1
core/src/main/java/module-info.java
core/src/main/java/module-info.java
+12
-1
core/src/main/resources/META-INF/services/io.questdb.griffin.FunctionFactory
...rces/META-INF/services/io.questdb.griffin.FunctionFactory
+10
-0
core/src/test/java/io/questdb/griffin/BitwiseTest.java
core/src/test/java/io/questdb/griffin/BitwiseTest.java
+152
-0
core/src/test/java/io/questdb/griffin/ExpressionParserTest.java
...rc/test/java/io/questdb/griffin/ExpressionParserTest.java
+1
-1
core/src/test/java/io/questdb/griffin/PowerTest.java
core/src/test/java/io/questdb/griffin/PowerTest.java
+66
-0
未找到文件。
core/src/main/java/io/questdb/griffin/ExpressionParser.java
浏览文件 @
6767dfe4
...
@@ -679,7 +679,7 @@ class ExpressionParser {
...
@@ -679,7 +679,7 @@ class ExpressionParser {
int
operatorType
=
op
.
type
;
int
operatorType
=
op
.
type
;
if
(
thisChar
==
'-'
)
{
if
(
thisChar
==
'-'
||
thisChar
==
'~'
)
{
switch
(
prevBranch
)
{
switch
(
prevBranch
)
{
case
BRANCH_OPERATOR:
case
BRANCH_OPERATOR:
case
BRANCH_LEFT_BRACE:
case
BRANCH_LEFT_BRACE:
...
...
core/src/main/java/io/questdb/griffin/OperatorExpression.java
浏览文件 @
6767dfe4
...
@@ -37,7 +37,6 @@ public final class OperatorExpression {
...
@@ -37,7 +37,6 @@ public final class OperatorExpression {
static
final
ObjList
<
OperatorExpression
>
operators
=
new
ObjList
<
OperatorExpression
>()
{{
static
final
ObjList
<
OperatorExpression
>
operators
=
new
ObjList
<
OperatorExpression
>()
{{
add
(
new
OperatorExpression
(
"."
,
DOT_PRECEDENCE
,
false
,
BINARY
));
add
(
new
OperatorExpression
(
"."
,
DOT_PRECEDENCE
,
false
,
BINARY
));
add
(
new
OperatorExpression
(
"::"
,
DOT_PRECEDENCE
,
false
,
BINARY
));
add
(
new
OperatorExpression
(
"::"
,
DOT_PRECEDENCE
,
false
,
BINARY
));
add
(
new
OperatorExpression
(
"^"
,
2
,
false
,
BINARY
));
add
(
new
OperatorExpression
(
"*"
,
3
,
true
,
BINARY
));
add
(
new
OperatorExpression
(
"*"
,
3
,
true
,
BINARY
));
add
(
new
OperatorExpression
(
"/"
,
3
,
true
,
BINARY
));
add
(
new
OperatorExpression
(
"/"
,
3
,
true
,
BINARY
));
add
(
new
OperatorExpression
(
"%"
,
3
,
true
,
BINARY
));
add
(
new
OperatorExpression
(
"%"
,
3
,
true
,
BINARY
));
...
@@ -55,6 +54,9 @@ public final class OperatorExpression {
...
@@ -55,6 +54,9 @@ public final class OperatorExpression {
add
(
new
OperatorExpression
(
"!~"
,
7
,
true
,
BINARY
));
add
(
new
OperatorExpression
(
"!~"
,
7
,
true
,
BINARY
));
add
(
new
OperatorExpression
(
"in"
,
7
,
true
,
SET
,
false
));
add
(
new
OperatorExpression
(
"in"
,
7
,
true
,
SET
,
false
));
add
(
new
OperatorExpression
(
"between"
,
7
,
true
,
SET
,
false
));
add
(
new
OperatorExpression
(
"between"
,
7
,
true
,
SET
,
false
));
add
(
new
OperatorExpression
(
"&"
,
8
,
true
,
BINARY
));
add
(
new
OperatorExpression
(
"^"
,
9
,
false
,
BINARY
));
add
(
new
OperatorExpression
(
"|"
,
10
,
true
,
BINARY
));
add
(
new
OperatorExpression
(
"and"
,
11
,
true
,
BINARY
,
false
));
add
(
new
OperatorExpression
(
"and"
,
11
,
true
,
BINARY
,
false
));
add
(
new
OperatorExpression
(
"or"
,
11
,
true
,
BINARY
,
false
));
add
(
new
OperatorExpression
(
"or"
,
11
,
true
,
BINARY
,
false
));
add
(
new
OperatorExpression
(
"not"
,
11
,
true
,
UNARY
,
false
));
add
(
new
OperatorExpression
(
"not"
,
11
,
true
,
UNARY
,
false
));
...
...
core/src/main/java/io/questdb/griffin/engine/functions/math/BitwiseAndIntFunctionFactory.java
0 → 100644
浏览文件 @
6767dfe4
/*******************************************************************************
* ___ _ ____ ____
* / _ \ _ _ ___ ___| |_| _ \| __ )
* | | | | | | |/ _ \/ __| __| | | | _ \
* | |_| | |_| | __/\__ \ |_| |_| | |_) |
* \__\_\\__,_|\___||___/\__|____/|____/
*
* Copyright (c) 2014-2019 Appsicle
* Copyright (c) 2019-2020 QuestDB
*
* Licensed 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.
*
******************************************************************************/
package
io.questdb.griffin.engine.functions.math
;
import
io.questdb.cairo.CairoConfiguration
;
import
io.questdb.cairo.sql.Function
;
import
io.questdb.cairo.sql.Record
;
import
io.questdb.griffin.FunctionFactory
;
import
io.questdb.griffin.SqlException
;
import
io.questdb.griffin.SqlExecutionContext
;
import
io.questdb.griffin.engine.functions.BinaryFunction
;
import
io.questdb.griffin.engine.functions.IntFunction
;
import
io.questdb.std.Numbers
;
import
io.questdb.std.ObjList
;
public
class
BitwiseAndIntFunctionFactory
implements
FunctionFactory
{
@Override
public
String
getSignature
()
{
return
"&(II)"
;
}
@Override
public
Function
newInstance
(
ObjList
<
Function
>
args
,
int
position
,
CairoConfiguration
configuration
,
SqlExecutionContext
sqlExecutionContext
)
throws
SqlException
{
return
new
BitAndIntFunction
(
position
,
args
.
getQuick
(
0
),
args
.
getQuick
(
1
));
}
public
static
final
class
BitAndIntFunction
extends
IntFunction
implements
BinaryFunction
{
private
final
Function
left
;
private
final
Function
right
;
public
BitAndIntFunction
(
int
position
,
Function
left
,
Function
right
)
{
super
(
position
);
this
.
left
=
left
;
this
.
right
=
right
;
}
@Override
public
Function
getLeft
()
{
return
left
;
}
@Override
public
Function
getRight
()
{
return
right
;
}
@Override
public
int
getInt
(
Record
rec
)
{
final
int
l
=
left
.
getInt
(
rec
);
final
int
r
=
right
.
getInt
(
rec
);
return
l
!=
Numbers
.
INT_NaN
&&
r
!=
Numbers
.
INT_NaN
?
l
&
r
:
Numbers
.
INT_NaN
;
}
}
}
core/src/main/java/io/questdb/griffin/engine/functions/math/BitwiseAndLongFunctionFactory.java
0 → 100644
浏览文件 @
6767dfe4
/*******************************************************************************
* ___ _ ____ ____
* / _ \ _ _ ___ ___| |_| _ \| __ )
* | | | | | | |/ _ \/ __| __| | | | _ \
* | |_| | |_| | __/\__ \ |_| |_| | |_) |
* \__\_\\__,_|\___||___/\__|____/|____/
*
* Copyright (c) 2014-2019 Appsicle
* Copyright (c) 2019-2020 QuestDB
*
* Licensed 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.
*
******************************************************************************/
package
io.questdb.griffin.engine.functions.math
;
import
io.questdb.cairo.CairoConfiguration
;
import
io.questdb.cairo.sql.Function
;
import
io.questdb.cairo.sql.Record
;
import
io.questdb.griffin.FunctionFactory
;
import
io.questdb.griffin.SqlException
;
import
io.questdb.griffin.SqlExecutionContext
;
import
io.questdb.griffin.engine.functions.BinaryFunction
;
import
io.questdb.griffin.engine.functions.LongFunction
;
import
io.questdb.std.Numbers
;
import
io.questdb.std.ObjList
;
public
class
BitwiseAndLongFunctionFactory
implements
FunctionFactory
{
@Override
public
String
getSignature
()
{
return
"&(LL)"
;
}
@Override
public
Function
newInstance
(
ObjList
<
Function
>
args
,
int
position
,
CairoConfiguration
configuration
,
SqlExecutionContext
sqlExecutionContext
)
throws
SqlException
{
return
new
BitAndLongFunction
(
position
,
args
.
getQuick
(
0
),
args
.
getQuick
(
1
));
}
public
static
final
class
BitAndLongFunction
extends
LongFunction
implements
BinaryFunction
{
private
final
Function
left
;
private
final
Function
right
;
public
BitAndLongFunction
(
int
position
,
Function
left
,
Function
right
)
{
super
(
position
);
this
.
left
=
left
;
this
.
right
=
right
;
}
@Override
public
Function
getLeft
()
{
return
left
;
}
@Override
public
Function
getRight
()
{
return
right
;
}
@Override
public
long
getLong
(
Record
rec
)
{
final
long
l
=
left
.
getLong
(
rec
);
final
long
r
=
right
.
getLong
(
rec
);
return
l
!=
Numbers
.
LONG_NaN
&&
r
!=
Numbers
.
LONG_NaN
?
l
&
r
:
Numbers
.
LONG_NaN
;
}
}
}
core/src/main/java/io/questdb/griffin/engine/functions/math/BitwiseNotIntFunctionFactory.java
0 → 100644
浏览文件 @
6767dfe4
/*******************************************************************************
* ___ _ ____ ____
* / _ \ _ _ ___ ___| |_| _ \| __ )
* | | | | | | |/ _ \/ __| __| | | | _ \
* | |_| | |_| | __/\__ \ |_| |_| | |_) |
* \__\_\\__,_|\___||___/\__|____/|____/
*
* Copyright (c) 2014-2019 Appsicle
* Copyright (c) 2019-2020 QuestDB
*
* Licensed 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.
*
******************************************************************************/
package
io.questdb.griffin.engine.functions.math
;
import
io.questdb.cairo.CairoConfiguration
;
import
io.questdb.cairo.sql.Function
;
import
io.questdb.cairo.sql.Record
;
import
io.questdb.griffin.FunctionFactory
;
import
io.questdb.griffin.SqlException
;
import
io.questdb.griffin.SqlExecutionContext
;
import
io.questdb.griffin.engine.functions.IntFunction
;
import
io.questdb.griffin.engine.functions.UnaryFunction
;
import
io.questdb.std.Numbers
;
import
io.questdb.std.ObjList
;
public
class
BitwiseNotIntFunctionFactory
implements
FunctionFactory
{
@Override
public
String
getSignature
()
{
return
"~(I)"
;
}
@Override
public
Function
newInstance
(
ObjList
<
Function
>
args
,
int
position
,
CairoConfiguration
configuration
,
SqlExecutionContext
sqlExecutionContext
)
throws
SqlException
{
return
new
BitNotIntFunction
(
position
,
args
.
getQuick
(
0
));
}
public
static
final
class
BitNotIntFunction
extends
IntFunction
implements
UnaryFunction
{
private
final
Function
value
;
public
BitNotIntFunction
(
int
position
,
Function
value
)
{
super
(
position
);
this
.
value
=
value
;
}
@Override
public
Function
getArg
()
{
return
value
;
}
@Override
public
int
getInt
(
Record
rec
)
{
final
int
val
=
value
.
getInt
(
rec
);
return
val
!=
Numbers
.
INT_NaN
?
~
val
:
Numbers
.
INT_NaN
;
}
}
}
core/src/main/java/io/questdb/griffin/engine/functions/math/BitwiseNotLongFunctionFactory.java
0 → 100644
浏览文件 @
6767dfe4
/*******************************************************************************
* ___ _ ____ ____
* / _ \ _ _ ___ ___| |_| _ \| __ )
* | | | | | | |/ _ \/ __| __| | | | _ \
* | |_| | |_| | __/\__ \ |_| |_| | |_) |
* \__\_\\__,_|\___||___/\__|____/|____/
*
* Copyright (c) 2014-2019 Appsicle
* Copyright (c) 2019-2020 QuestDB
*
* Licensed 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.
*
******************************************************************************/
package
io.questdb.griffin.engine.functions.math
;
import
io.questdb.cairo.CairoConfiguration
;
import
io.questdb.cairo.sql.Function
;
import
io.questdb.cairo.sql.Record
;
import
io.questdb.griffin.FunctionFactory
;
import
io.questdb.griffin.SqlException
;
import
io.questdb.griffin.SqlExecutionContext
;
import
io.questdb.griffin.engine.functions.LongFunction
;
import
io.questdb.griffin.engine.functions.UnaryFunction
;
import
io.questdb.griffin.engine.functions.constants.LongConstant
;
import
io.questdb.std.Numbers
;
import
io.questdb.std.ObjList
;
public
class
BitwiseNotLongFunctionFactory
implements
FunctionFactory
{
@Override
public
String
getSignature
()
{
return
"~(L)"
;
}
@Override
public
Function
newInstance
(
ObjList
<
Function
>
args
,
int
position
,
CairoConfiguration
configuration
,
SqlExecutionContext
sqlExecutionContext
)
throws
SqlException
{
return
new
BitNotLongFunction
(
position
,
args
.
getQuick
(
0
));
}
public
static
final
class
BitNotLongFunction
extends
LongFunction
implements
UnaryFunction
{
private
final
Function
value
;
public
BitNotLongFunction
(
int
position
,
Function
value
)
{
super
(
position
);
this
.
value
=
value
;
}
@Override
public
Function
getArg
()
{
return
value
;
}
@Override
public
long
getLong
(
Record
rec
)
{
final
long
val
=
value
.
getLong
(
rec
);
return
val
!=
Numbers
.
LONG_NaN
?
~
val
:
Numbers
.
LONG_NaN
;
}
}
}
core/src/main/java/io/questdb/griffin/engine/functions/math/BitwiseOrIntFunctionFactory.java
0 → 100644
浏览文件 @
6767dfe4
/*******************************************************************************
* ___ _ ____ ____
* / _ \ _ _ ___ ___| |_| _ \| __ )
* | | | | | | |/ _ \/ __| __| | | | _ \
* | |_| | |_| | __/\__ \ |_| |_| | |_) |
* \__\_\\__,_|\___||___/\__|____/|____/
*
* Copyright (c) 2014-2019 Appsicle
* Copyright (c) 2019-2020 QuestDB
*
* Licensed 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.
*
******************************************************************************/
package
io.questdb.griffin.engine.functions.math
;
import
io.questdb.cairo.CairoConfiguration
;
import
io.questdb.cairo.sql.Function
;
import
io.questdb.cairo.sql.Record
;
import
io.questdb.griffin.FunctionFactory
;
import
io.questdb.griffin.SqlException
;
import
io.questdb.griffin.SqlExecutionContext
;
import
io.questdb.griffin.engine.functions.BinaryFunction
;
import
io.questdb.griffin.engine.functions.IntFunction
;
import
io.questdb.std.Numbers
;
import
io.questdb.std.ObjList
;
public
class
BitwiseOrIntFunctionFactory
implements
FunctionFactory
{
@Override
public
String
getSignature
()
{
return
"|(II)"
;
}
@Override
public
Function
newInstance
(
ObjList
<
Function
>
args
,
int
position
,
CairoConfiguration
configuration
,
SqlExecutionContext
sqlExecutionContext
)
throws
SqlException
{
return
new
BitOrIntFunction
(
position
,
args
.
getQuick
(
0
),
args
.
getQuick
(
1
));
}
public
static
final
class
BitOrIntFunction
extends
IntFunction
implements
BinaryFunction
{
private
final
Function
left
;
private
final
Function
right
;
public
BitOrIntFunction
(
int
position
,
Function
left
,
Function
right
)
{
super
(
position
);
this
.
left
=
left
;
this
.
right
=
right
;
}
@Override
public
Function
getLeft
()
{
return
left
;
}
@Override
public
Function
getRight
()
{
return
right
;
}
@Override
public
int
getInt
(
Record
rec
)
{
final
int
l
=
left
.
getInt
(
rec
);
final
int
r
=
right
.
getInt
(
rec
);
return
l
!=
Numbers
.
INT_NaN
&&
r
!=
Numbers
.
INT_NaN
?
l
|
r
:
Numbers
.
INT_NaN
;
}
}
}
core/src/main/java/io/questdb/griffin/engine/functions/math/BitwiseOrLongFunctionFactory.java
0 → 100644
浏览文件 @
6767dfe4
/*******************************************************************************
* ___ _ ____ ____
* / _ \ _ _ ___ ___| |_| _ \| __ )
* | | | | | | |/ _ \/ __| __| | | | _ \
* | |_| | |_| | __/\__ \ |_| |_| | |_) |
* \__\_\\__,_|\___||___/\__|____/|____/
*
* Copyright (c) 2014-2019 Appsicle
* Copyright (c) 2019-2020 QuestDB
*
* Licensed 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.
*
******************************************************************************/
package
io.questdb.griffin.engine.functions.math
;
import
io.questdb.cairo.CairoConfiguration
;
import
io.questdb.cairo.sql.Function
;
import
io.questdb.cairo.sql.Record
;
import
io.questdb.griffin.FunctionFactory
;
import
io.questdb.griffin.SqlException
;
import
io.questdb.griffin.SqlExecutionContext
;
import
io.questdb.griffin.engine.functions.BinaryFunction
;
import
io.questdb.griffin.engine.functions.LongFunction
;
import
io.questdb.std.Numbers
;
import
io.questdb.std.ObjList
;
public
class
BitwiseOrLongFunctionFactory
implements
FunctionFactory
{
@Override
public
String
getSignature
()
{
return
"|(LL)"
;
}
@Override
public
Function
newInstance
(
ObjList
<
Function
>
args
,
int
position
,
CairoConfiguration
configuration
,
SqlExecutionContext
sqlExecutionContext
)
throws
SqlException
{
return
new
BitOrLongFunction
(
position
,
args
.
getQuick
(
0
),
args
.
getQuick
(
1
));
}
public
static
final
class
BitOrLongFunction
extends
LongFunction
implements
BinaryFunction
{
private
final
Function
left
;
private
final
Function
right
;
public
BitOrLongFunction
(
int
position
,
Function
left
,
Function
right
)
{
super
(
position
);
this
.
left
=
left
;
this
.
right
=
right
;
}
@Override
public
Function
getLeft
()
{
return
left
;
}
@Override
public
Function
getRight
()
{
return
right
;
}
@Override
public
long
getLong
(
Record
rec
)
{
final
long
l
=
left
.
getLong
(
rec
);
final
long
r
=
right
.
getLong
(
rec
);
return
l
!=
Numbers
.
LONG_NaN
&&
r
!=
Numbers
.
LONG_NaN
?
l
|
r
:
Numbers
.
LONG_NaN
;
}
}
}
core/src/main/java/io/questdb/griffin/engine/functions/math/BitwiseXorIntFunctionFactory.java
0 → 100644
浏览文件 @
6767dfe4
/*******************************************************************************
* ___ _ ____ ____
* / _ \ _ _ ___ ___| |_| _ \| __ )
* | | | | | | |/ _ \/ __| __| | | | _ \
* | |_| | |_| | __/\__ \ |_| |_| | |_) |
* \__\_\\__,_|\___||___/\__|____/|____/
*
* Copyright (c) 2014-2019 Appsicle
* Copyright (c) 2019-2020 QuestDB
*
* Licensed 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.
*
******************************************************************************/
package
io.questdb.griffin.engine.functions.math
;
import
io.questdb.cairo.CairoConfiguration
;
import
io.questdb.cairo.sql.Function
;
import
io.questdb.cairo.sql.Record
;
import
io.questdb.griffin.FunctionFactory
;
import
io.questdb.griffin.SqlException
;
import
io.questdb.griffin.SqlExecutionContext
;
import
io.questdb.griffin.engine.functions.BinaryFunction
;
import
io.questdb.griffin.engine.functions.IntFunction
;
import
io.questdb.std.Numbers
;
import
io.questdb.std.ObjList
;
public
class
BitwiseXorIntFunctionFactory
implements
FunctionFactory
{
@Override
public
String
getSignature
()
{
return
"^(II)"
;
}
@Override
public
Function
newInstance
(
ObjList
<
Function
>
args
,
int
position
,
CairoConfiguration
configuration
,
SqlExecutionContext
sqlExecutionContext
)
throws
SqlException
{
return
new
BitXorIntFunction
(
position
,
args
.
getQuick
(
0
),
args
.
getQuick
(
1
));
}
public
static
final
class
BitXorIntFunction
extends
IntFunction
implements
BinaryFunction
{
private
final
Function
left
;
private
final
Function
right
;
public
BitXorIntFunction
(
int
position
,
Function
left
,
Function
right
)
{
super
(
position
);
this
.
left
=
left
;
this
.
right
=
right
;
}
@Override
public
Function
getLeft
()
{
return
left
;
}
@Override
public
Function
getRight
()
{
return
right
;
}
@Override
public
int
getInt
(
Record
rec
)
{
final
int
l
=
left
.
getInt
(
rec
);
final
int
r
=
right
.
getInt
(
rec
);
return
l
!=
Numbers
.
INT_NaN
&&
r
!=
Numbers
.
INT_NaN
?
l
^
r
:
Numbers
.
INT_NaN
;
}
}
}
core/src/main/java/io/questdb/griffin/engine/functions/math/BitwiseXorLongFunctionFactory.java
0 → 100644
浏览文件 @
6767dfe4
/*******************************************************************************
* ___ _ ____ ____
* / _ \ _ _ ___ ___| |_| _ \| __ )
* | | | | | | |/ _ \/ __| __| | | | _ \
* | |_| | |_| | __/\__ \ |_| |_| | |_) |
* \__\_\\__,_|\___||___/\__|____/|____/
*
* Copyright (c) 2014-2019 Appsicle
* Copyright (c) 2019-2020 QuestDB
*
* Licensed 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.
*
******************************************************************************/
package
io.questdb.griffin.engine.functions.math
;
import
io.questdb.cairo.CairoConfiguration
;
import
io.questdb.cairo.sql.Function
;
import
io.questdb.cairo.sql.Record
;
import
io.questdb.griffin.FunctionFactory
;
import
io.questdb.griffin.SqlException
;
import
io.questdb.griffin.SqlExecutionContext
;
import
io.questdb.griffin.engine.functions.BinaryFunction
;
import
io.questdb.griffin.engine.functions.LongFunction
;
import
io.questdb.std.Numbers
;
import
io.questdb.std.ObjList
;
public
class
BitwiseXorLongFunctionFactory
implements
FunctionFactory
{
@Override
public
String
getSignature
()
{
return
"^(LL)"
;
}
@Override
public
Function
newInstance
(
ObjList
<
Function
>
args
,
int
position
,
CairoConfiguration
configuration
,
SqlExecutionContext
sqlExecutionContext
)
throws
SqlException
{
return
new
BitXorLongFunction
(
position
,
args
.
getQuick
(
0
),
args
.
getQuick
(
1
));
}
public
static
final
class
BitXorLongFunction
extends
LongFunction
implements
BinaryFunction
{
private
final
Function
left
;
private
final
Function
right
;
public
BitXorLongFunction
(
int
position
,
Function
left
,
Function
right
)
{
super
(
position
);
this
.
left
=
left
;
this
.
right
=
right
;
}
@Override
public
Function
getLeft
()
{
return
left
;
}
@Override
public
Function
getRight
()
{
return
right
;
}
@Override
public
long
getLong
(
Record
rec
)
{
final
long
l
=
left
.
getLong
(
rec
);
final
long
r
=
right
.
getLong
(
rec
);
return
l
!=
Numbers
.
LONG_NaN
&&
r
!=
Numbers
.
LONG_NaN
?
l
^
r
:
Numbers
.
LONG_NaN
;
}
}
}
core/src/main/java/io/questdb/griffin/engine/functions/math/PowDoubleFunctionFactory.java
浏览文件 @
6767dfe4
...
@@ -36,7 +36,7 @@ import io.questdb.std.ObjList;
...
@@ -36,7 +36,7 @@ import io.questdb.std.ObjList;
public
class
PowDoubleFunctionFactory
implements
FunctionFactory
{
public
class
PowDoubleFunctionFactory
implements
FunctionFactory
{
@Override
@Override
public
String
getSignature
()
{
public
String
getSignature
()
{
return
"
^
(DD)"
;
return
"
power
(DD)"
;
}
}
@Override
@Override
...
...
core/src/main/java/module-info.java
浏览文件 @
6767dfe4
...
@@ -23,6 +23,7 @@
...
@@ -23,6 +23,7 @@
******************************************************************************/
******************************************************************************/
import
io.questdb.griffin.FunctionFactory
;
import
io.questdb.griffin.FunctionFactory
;
import
io.questdb.griffin.engine.functions.math.*
;
open
module
io
.
questdb
{
open
module
io
.
questdb
{
requires
transitive
jdk
.
unsupported
;
requires
transitive
jdk
.
unsupported
;
...
@@ -530,6 +531,16 @@ open module io.questdb {
...
@@ -530,6 +531,16 @@ open module io.questdb {
io
.
questdb
.
griffin
.
engine
.
functions
.
analytic
.
RowNumberFunctionFactory
,
io
.
questdb
.
griffin
.
engine
.
functions
.
analytic
.
RowNumberFunctionFactory
,
// metadata functions
// metadata functions
io
.
questdb
.
griffin
.
engine
.
functions
.
metadata
.
BuildFunctionFactory
io
.
questdb
.
griffin
.
engine
.
functions
.
metadata
.
BuildFunctionFactory
,
// bit operations
BitwiseAndLongFunctionFactory
,
BitwiseOrLongFunctionFactory
,
BitwiseNotLongFunctionFactory
,
BitwiseXorLongFunctionFactory
,
BitwiseAndIntFunctionFactory
,
BitwiseOrIntFunctionFactory
,
BitwiseNotIntFunctionFactory
,
BitwiseXorIntFunctionFactory
;
;
}
}
core/src/main/resources/META-INF/services/io.questdb.griffin.FunctionFactory
浏览文件 @
6767dfe4
...
@@ -492,3 +492,13 @@ io.questdb.griffin.engine.functions.analytic.RowNumberFunctionFactory
...
@@ -492,3 +492,13 @@ io.questdb.griffin.engine.functions.analytic.RowNumberFunctionFactory
# metadata functions
# metadata functions
io.questdb.griffin.engine.functions.metadata.BuildFunctionFactory
io.questdb.griffin.engine.functions.metadata.BuildFunctionFactory
# Bitwise operators
io.questdb.griffin.engine.functions.math.BitwiseAndLongFunctionFactory
io.questdb.griffin.engine.functions.math.BitwiseOrLongFunctionFactory
io.questdb.griffin.engine.functions.math.BitwiseXorLongFunctionFactory
io.questdb.griffin.engine.functions.math.BitwiseNotLongFunctionFactory
io.questdb.griffin.engine.functions.math.BitwiseAndIntFunctionFactory
io.questdb.griffin.engine.functions.math.BitwiseOrIntFunctionFactory
io.questdb.griffin.engine.functions.math.BitwiseXorIntFunctionFactory
io.questdb.griffin.engine.functions.math.BitwiseNotIntFunctionFactory
\ No newline at end of file
core/src/test/java/io/questdb/griffin/BitwiseTest.java
0 → 100644
浏览文件 @
6767dfe4
/*******************************************************************************
* ___ _ ____ ____
* / _ \ _ _ ___ ___| |_| _ \| __ )
* | | | | | | |/ _ \/ __| __| | | | _ \
* | |_| | |_| | __/\__ \ |_| |_| | |_) |
* \__\_\\__,_|\___||___/\__|____/|____/
*
* Copyright (c) 2014-2019 Appsicle
* Copyright (c) 2019-2020 QuestDB
*
* Licensed 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.
*
******************************************************************************/
package
io.questdb.griffin
;
import
io.questdb.test.tools.TestUtils
;
import
org.junit.Test
;
public
class
BitwiseTest
extends
AbstractGriffinTest
{
@Test
public
void
testIntNot
()
throws
Exception
{
assertBitwiseOp
(
"select ~1024"
,
"-1025\n"
);
}
@Test
public
void
testIntNotNull
()
throws
Exception
{
assertBitwiseOp
(
"select ~cast(NaN as int)"
,
"NaN\n"
);
}
@Test
public
void
testIntOr
()
throws
Exception
{
assertBitwiseOp
(
"select 2 | 4"
,
"6\n"
);
}
@Test
public
void
testIntOrLeftNull
()
throws
Exception
{
assertBitwiseOp
(
"select NaN | 4"
,
"NaN\n"
);
}
@Test
public
void
testIntOrRightNull
()
throws
Exception
{
assertBitwiseOp
(
"select 2 | NaN"
,
"NaN\n"
);
}
@Test
public
void
testLongOr
()
throws
Exception
{
assertBitwiseOp
(
"select 2L | 4"
,
"6\n"
);
}
@Test
public
void
testLongOrLeftNull
()
throws
Exception
{
assertBitwiseOp
(
"select NaN | 4L"
,
"NaN\n"
);
}
@Test
public
void
testLongOrRightNull
()
throws
Exception
{
assertBitwiseOp
(
"select 2L | NaN"
,
"NaN\n"
);
}
@Test
public
void
testLongAnd
()
throws
Exception
{
assertBitwiseOp
(
"select 6L & 4"
,
"4\n"
);
}
@Test
public
void
testLongAndLeftNull
()
throws
Exception
{
assertBitwiseOp
(
"select NaN & 4L"
,
"NaN\n"
);
}
@Test
public
void
testLongAndRightNull
()
throws
Exception
{
assertBitwiseOp
(
"select 2L & NaN"
,
"NaN\n"
);
}
@Test
public
void
testIntAnd
()
throws
Exception
{
assertBitwiseOp
(
"select 6 & 4"
,
"4\n"
);
}
@Test
public
void
testIntAndLeftNull
()
throws
Exception
{
assertBitwiseOp
(
"select NaN & 4"
,
"NaN\n"
);
}
@Test
public
void
testIntAndRightNull
()
throws
Exception
{
assertBitwiseOp
(
"select 2 & NaN"
,
"NaN\n"
);
}
@Test
public
void
testIntXor
()
throws
Exception
{
assertBitwiseOp
(
"select 6 ^ 4"
,
"2\n"
);
}
@Test
public
void
testIntXorLeftNull
()
throws
Exception
{
assertBitwiseOp
(
"select NaN ^ 4"
,
"NaN\n"
);
}
@Test
public
void
testIntXorRightNull
()
throws
Exception
{
assertBitwiseOp
(
"select 2 ^ NaN"
,
"NaN\n"
);
}
@Test
public
void
testLongXor
()
throws
Exception
{
assertBitwiseOp
(
"select 6L ^ 4"
,
"2\n"
);
}
@Test
public
void
testLongXorLeftNull
()
throws
Exception
{
assertBitwiseOp
(
"select NaN ^ 4L"
,
"NaN\n"
);
}
@Test
public
void
testLongXorRightNull
()
throws
Exception
{
assertBitwiseOp
(
"select 2L ^ NaN"
,
"NaN\n"
);
}
@Test
public
void
testLongNot
()
throws
Exception
{
assertBitwiseOp
(
"select ~255L"
,
"-256\n"
);
}
@Test
public
void
testLongNotNull
()
throws
Exception
{
assertBitwiseOp
(
"select ~cast(NaN as long)"
,
"NaN\n"
);
}
private
void
assertBitwiseOp
(
String
sql
,
String
expected
)
throws
Exception
{
assertMemoryLeak
(()
->
TestUtils
.
assertSql
(
compiler
,
sqlExecutionContext
,
sql
,
sink
,
"column\n"
+
expected
));
}
}
core/src/test/java/io/questdb/griffin/ExpressionParserTest.java
浏览文件 @
6767dfe4
...
@@ -508,7 +508,7 @@ public class ExpressionParserTest extends AbstractCairoTest {
...
@@ -508,7 +508,7 @@ public class ExpressionParserTest extends AbstractCairoTest {
@Test
@Test
public
void
testComplexUnary2
()
throws
Exception
{
public
void
testComplexUnary2
()
throws
Exception
{
x
(
"a
b^-
"
,
"-a^b"
);
x
(
"a
-b^
"
,
"-a^b"
);
}
}
@Test
@Test
...
...
core/src/test/java/io/questdb/griffin/PowerTest.java
0 → 100644
浏览文件 @
6767dfe4
/*******************************************************************************
* ___ _ ____ ____
* / _ \ _ _ ___ ___| |_| _ \| __ )
* | | | | | | |/ _ \/ __| __| | | | _ \
* | |_| | |_| | __/\__ \ |_| |_| | |_) |
* \__\_\\__,_|\___||___/\__|____/|____/
*
* Copyright (c) 2014-2019 Appsicle
* Copyright (c) 2019-2020 QuestDB
*
* Licensed 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.
*
******************************************************************************/
package
io.questdb.griffin
;
import
io.questdb.test.tools.TestUtils
;
import
org.junit.Test
;
public
class
PowerTest
extends
AbstractGriffinTest
{
@Test
public
void
testPowerDouble
()
throws
Exception
{
assertMemoryLeak
(()
->
TestUtils
.
assertSql
(
compiler
,
sqlExecutionContext
,
"select power(10.2, 3)"
,
sink
,
"power\n"
+
"1061.2080000000003\n"
));
}
@Test
public
void
testPowerDoubleLeftNull
()
throws
Exception
{
assertMemoryLeak
(()
->
TestUtils
.
assertSql
(
compiler
,
sqlExecutionContext
,
"select power(NaN, 3)"
,
sink
,
"power\n"
+
"NaN\n"
));
}
@Test
public
void
testPowerDoubleRightNull
()
throws
Exception
{
assertMemoryLeak
(()
->
TestUtils
.
assertSql
(
compiler
,
sqlExecutionContext
,
"select power(1.5, NaN)"
,
sink
,
"power\n"
+
"NaN\n"
));
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录