Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
jobily
Questdb
提交
955535f3
Q
Questdb
项目概览
jobily
/
Questdb
9 个月 前同步成功
通知
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,体验更适合开发者的 AI 搜索 >>
未验证
提交
955535f3
编写于
8月 15, 2023
作者:
A
Allegra Harris
提交者:
GitHub
8月 15, 2023
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat(core): add more operators ipv4 operators + alter eq ipv4 (#3650)
上级
e0039118
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
168 addition
and
24 deletion
+168
-24
core/src/main/java/io/questdb/griffin/engine/functions/eq/EqIPv4FunctionFactory.java
...db/griffin/engine/functions/eq/EqIPv4FunctionFactory.java
+10
-15
core/src/main/java/io/questdb/griffin/engine/functions/lt/LtIPv4FunctionFactory.java
...db/griffin/engine/functions/lt/LtIPv4FunctionFactory.java
+103
-0
core/src/main/java/module-info.java
core/src/main/java/module-info.java
+1
-0
core/src/main/resources/META-INF/services/io.questdb.griffin.FunctionFactory
...rces/META-INF/services/io.questdb.griffin.FunctionFactory
+1
-0
core/src/test/java/io/questdb/test/griffin/IPv4Test.java
core/src/test/java/io/questdb/test/griffin/IPv4Test.java
+53
-9
未找到文件。
core/src/main/java/io/questdb/griffin/engine/functions/eq/EqIPv4FunctionFactory.java
浏览文件 @
955535f3
...
...
@@ -37,13 +37,12 @@ import io.questdb.std.IntList;
import
io.questdb.std.ObjList
;
import
static
io
.
questdb
.
std
.
Numbers
.
IPv4_NULL
;
import
static
io
.
questdb
.
std
.
Numbers
.
parseIPv4Quiet
;
public
class
EqIPv4FunctionFactory
implements
FunctionFactory
{
@Override
public
String
getSignature
()
{
return
"=(X
S
)"
;
return
"=(X
X
)"
;
}
@Override
...
...
@@ -65,26 +64,22 @@ public class EqIPv4FunctionFactory implements FunctionFactory {
if
(!
a
.
isConstant
()
&&
b
.
isConstant
())
{
return
createHalfConstantFunc
(
b
,
a
,
argPositions
.
get
(
1
));
return
createHalfConstantFunc
(
b
,
a
);
}
else
if
(
a
.
isConstant
()
&&
!
b
.
isConstant
())
{
return
createHalfConstantFunc
(
a
,
b
);
}
return
new
EqIPv4FunctionFactory
.
Func
(
a
,
b
);
}
private
Function
createHalfConstantFunc
(
Function
constFunc
,
Function
varFunc
,
int
constFuncPosition
)
throws
SqlException
{
CharSequence
constValue
=
constFunc
.
getStr
(
null
);
private
Function
createHalfConstantFunc
(
Function
constFunc
,
Function
varFunc
)
{
int
constValue
=
constFunc
.
getIPv4
(
null
);
if
(
constValue
==
null
)
{
return
new
NullCheckFunc
(
varFunc
);
if
(
constValue
==
IPv4_NULL
)
{
return
new
EqIPv4FunctionFactory
.
NullCheckFunc
(
varFunc
);
}
int
constVal
=
parseIPv4Quiet
(
constValue
);
if
(
constVal
==
0
)
{
throw
SqlException
.
$
(
constFuncPosition
,
"not a valid IP address: "
).
put
(
constValue
);
}
return
new
ConstCheckFunc
(
varFunc
,
constVal
);
return
new
EqIPv4FunctionFactory
.
ConstCheckFunc
(
varFunc
,
constValue
);
}
private
static
class
ConstCheckFunc
extends
NegatableBooleanFunction
implements
UnaryFunction
{
...
...
@@ -123,7 +118,7 @@ public class EqIPv4FunctionFactory implements FunctionFactory {
@Override
public
boolean
getBool
(
Record
rec
)
{
return
negated
!=
(
left
.
getIPv4
(
rec
)
==
parseIPv4Quiet
(
right
.
getStr
(
rec
)
));
return
negated
!=
(
left
.
getIPv4
(
rec
)
==
right
.
getIPv4
(
rec
));
}
@Override
...
...
core/src/main/java/io/questdb/griffin/engine/functions/lt/LtIPv4FunctionFactory.java
0 → 100644
浏览文件 @
955535f3
/*******************************************************************************
* ___ _ ____ ____
* / _ \ _ _ ___ ___| |_| _ \| __ )
* | | | | | | |/ _ \/ __| __| | | | _ \
* | |_| | |_| | __/\__ \ |_| |_| | |_) |
* \__\_\\__,_|\___||___/\__|____/|____/
*
* Copyright (c) 2014-2019 Appsicle
* Copyright (c) 2019-2023 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.lt
;
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.PlanSink
;
import
io.questdb.griffin.SqlExecutionContext
;
import
io.questdb.griffin.engine.functions.BinaryFunction
;
import
io.questdb.griffin.engine.functions.NegatableBooleanFunction
;
import
io.questdb.std.IntList
;
import
io.questdb.std.Numbers
;
import
io.questdb.std.ObjList
;
public
class
LtIPv4FunctionFactory
implements
FunctionFactory
{
@Override
public
String
getSignature
()
{
return
"<(XX)"
;
}
@Override
public
boolean
isBoolean
()
{
return
true
;
}
@Override
public
Function
newInstance
(
int
position
,
ObjList
<
Function
>
args
,
IntList
argPositions
,
CairoConfiguration
configuration
,
SqlExecutionContext
sqlExecutionContext
)
{
return
new
LtIPv4FunctionFactory
.
LtIPv4Function
(
args
.
getQuick
(
0
),
args
.
getQuick
(
1
));
}
private
static
class
LtIPv4Function
extends
NegatableBooleanFunction
implements
BinaryFunction
{
private
final
Function
left
;
private
final
Function
right
;
public
LtIPv4Function
(
Function
left
,
Function
right
)
{
this
.
left
=
left
;
this
.
right
=
right
;
}
@Override
public
boolean
getBool
(
Record
rec
)
{
long
left
=
Numbers
.
ipv4ToLong
(
this
.
left
.
getIPv4
(
rec
));
if
(
left
!=
Numbers
.
IPv4_NULL
)
{
long
right
=
Numbers
.
ipv4ToLong
(
this
.
right
.
getIPv4
(
rec
));
if
(
right
!=
Numbers
.
IPv4_NULL
)
{
return
negated
==
(
left
>=
right
);
}
}
return
false
;
}
@Override
public
Function
getLeft
()
{
return
left
;
}
@Override
public
Function
getRight
()
{
return
right
;
}
@Override
public
void
toPlan
(
PlanSink
sink
)
{
sink
.
val
(
left
);
if
(
negated
)
{
sink
.
val
(
">="
);
}
else
{
sink
.
val
(
'<'
);
}
sink
.
val
(
right
);
}
}
}
core/src/main/java/module-info.java
浏览文件 @
955535f3
...
...
@@ -170,6 +170,7 @@ open module io.questdb {
io
.
questdb
.
griffin
.
engine
.
functions
.
lt
.
LtDoubleVVFunctionFactory
,
io
.
questdb
.
griffin
.
engine
.
functions
.
lt
.
LtTimestampFunctionFactory
,
io
.
questdb
.
griffin
.
engine
.
functions
.
lt
.
LtIntFunctionFactory
,
io
.
questdb
.
griffin
.
engine
.
functions
.
lt
.
LtIPv4FunctionFactory
,
io
.
questdb
.
griffin
.
engine
.
functions
.
lt
.
LtCharFunctionFactory
,
io
.
questdb
.
griffin
.
engine
.
functions
.
lt
.
LtStrFunctionFactory
,
io
.
questdb
.
griffin
.
engine
.
functions
.
lt
.
LtLongFunctionFactory
,
...
...
core/src/main/resources/META-INF/services/io.questdb.griffin.FunctionFactory
浏览文件 @
955535f3
...
...
@@ -84,6 +84,7 @@ io.questdb.griffin.engine.functions.conditional.NullIfLongFunctionFactory
io.questdb.griffin.engine.functions.lt.LtDoubleVVFunctionFactory
io.questdb.griffin.engine.functions.lt.LtTimestampFunctionFactory
io.questdb.griffin.engine.functions.lt.LtIntFunctionFactory
io.questdb.griffin.engine.functions.lt.LtIPv4FunctionFactory
io.questdb.griffin.engine.functions.lt.LtCharFunctionFactory
io.questdb.griffin.engine.functions.lt.LtStrFunctionFactory
io.questdb.griffin.engine.functions.lt.LtLongFunctionFactory
...
...
core/src/test/java/io/questdb/test/griffin/IPv4Test.java
浏览文件 @
955535f3
...
...
@@ -1939,7 +1939,7 @@ public class IPv4Test extends AbstractCairoTest {
assertSql
(
"ip\n"
+
"0.0.0.1\n"
,
"select * from test where '0.0.0.1' = ip"
"select * from test where
ipv4
'0.0.0.1' = ip"
);
}
...
...
@@ -1968,7 +1968,7 @@ public class IPv4Test extends AbstractCairoTest {
"0.0.0.2\n"
+
"\n"
+
"\n"
,
"select * from test where ip != '0.0.0.1'"
"select * from test where ip !=
ipv4
'0.0.0.1'"
);
}
...
...
@@ -1997,7 +1997,7 @@ public class IPv4Test extends AbstractCairoTest {
"0.0.0.2\n"
+
"\n"
+
"\n"
,
"select * from test where '0.0.0.1' != ip"
"select * from test where
ipv4
'0.0.0.1' != ip"
);
}
...
...
@@ -5028,7 +5028,7 @@ public class IPv4Test extends AbstractCairoTest {
"0.0.0.1\t814\t1970-01-01T02:36:40.000000Z\n"
+
"0.0.0.1\t511\t1970-01-01T02:41:40.000000Z\n"
+
"0.0.0.1\t25\t1970-01-01T02:43:20.000000Z\n"
,
"select * from test where ip = '0.0.0.1'"
,
"select * from test where ip =
ipv4
'0.0.0.1'"
,
"create table test as "
+
"("
+
" select"
+
...
...
@@ -5169,7 +5169,7 @@ public class IPv4Test extends AbstractCairoTest {
"("
+
" select"
+
" rnd_int(0,9,0)::ipv4 ip1,"
+
" rnd_int(0,9,0)::ipv4
::string
ip2"
+
" rnd_int(0,9,0)::ipv4 ip2"
+
" from long_sequence(1000)"
+
")"
,
null
,
...
...
@@ -5178,10 +5178,53 @@ public class IPv4Test extends AbstractCairoTest {
);
}
@Test
public
void
testLessThanIPv4
()
throws
Exception
{
assertSql
(
"column\n"
+
"false\n"
,
"select ipv4 '34.11.45.3' < ipv4 '22.1.200.89'"
);
}
@Test
public
void
testLessThanEqIPv4
()
throws
Exception
{
assertSql
(
"column\n"
+
"true\n"
,
"select ipv4 '34.11.45.3' <= ipv4 '34.11.45.3'"
);
}
@Test
public
void
testGreaterThanIPv4
()
throws
Exception
{
assertSql
(
"column\n"
+
"true\n"
,
"select ipv4 '34.11.45.3' > ipv4 '22.1.200.89'"
);
}
@Test
public
void
testGreaterThanEqIPv4
()
throws
Exception
{
assertSql
(
"column\n"
+
"true\n"
,
"select ipv4 '34.11.45.3' >= ipv4 '22.1.200.89'"
);
}
@Test
public
void
testGreaterThanEqIPv4Null
()
throws
Exception
{
assertSql
(
"column\n"
+
"false\n"
,
"select ipv4 '34.11.45.3' >= ipv4 '0.0.0.0'"
);
}
@Test
public
void
testGreaterThanEqIPv4Null2
()
throws
Exception
{
assertSql
(
"column\n"
+
"false\n"
,
"select ipv4 '34.11.45.3' >= null"
);
}
@Test
public
void
testGreaterThanEqIPv4BadStr
()
throws
Exception
{
assertSql
(
"column\n"
+
"false\n"
,
"select ipv4 '34.11.45.3' >= ipv4 'apple'"
);
}
@Test
public
void
testWhereInvalidIPv4
()
throws
Exception
{
assert
Exception
(
"select * from test where ip = 'hello'"
,
assert
Query
(
"ip\tbytes\tk\n"
,
"select * from test where ip =
ipv4
'hello'"
,
"create table test as "
+
"("
+
" select"
+
...
...
@@ -5190,8 +5233,9 @@ public class IPv4Test extends AbstractCairoTest {
" timestamp_sequence(0,100000000) k"
+
" from long_sequence(100)"
+
") timestamp(k)"
,
30
,
"not a valid IP address: hello"
"k"
,
true
,
false
);
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录