Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
jobily
Questdb
提交
a5b8ddd3
Q
Questdb
项目概览
jobily
/
Questdb
10 个月 前同步成功
通知
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 搜索 >>
未验证
提交
a5b8ddd3
编写于
9月 14, 2021
作者:
E
Eugene Lysiuchenko
提交者:
GitHub
9月 14, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix(sql): fix lt join for equal timestampts (#1321)
上级
7836466a
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
125 addition
and
93 deletion
+125
-93
core/src/main/java/io/questdb/griffin/SqlCompiler.java
core/src/main/java/io/questdb/griffin/SqlCompiler.java
+1
-1
core/src/main/java/io/questdb/griffin/engine/join/LtJoinNoKeyRecordCursorFactory.java
...b/griffin/engine/join/LtJoinNoKeyRecordCursorFactory.java
+1
-1
core/src/test/java/io/questdb/griffin/AsOfJoinTest.java
core/src/test/java/io/questdb/griffin/AsOfJoinTest.java
+111
-79
core/src/test/java/io/questdb/griffin/JoinTest.java
core/src/test/java/io/questdb/griffin/JoinTest.java
+8
-8
core/src/test/java/io/questdb/griffin/SecurityTest.java
core/src/test/java/io/questdb/griffin/SecurityTest.java
+4
-4
未找到文件。
core/src/main/java/io/questdb/griffin/SqlCompiler.java
浏览文件 @
a5b8ddd3
...
...
@@ -2171,7 +2171,7 @@ public class SqlCompiler implements Closeable {
return
compiledQuery
.
ofRepair
();
}
void
setFull
S
atJoins
(
boolean
value
)
{
void
setFull
F
atJoins
(
boolean
value
)
{
codeGenerator
.
setFullFatJoins
(
value
);
}
...
...
core/src/main/java/io/questdb/griffin/engine/join/LtJoinNoKeyRecordCursorFactory.java
浏览文件 @
a5b8ddd3
...
...
@@ -130,7 +130,7 @@ public class LtJoinNoKeyRecordCursorFactory extends AbstractRecordCursorFactory
long
slaveTimestamp
=
this
.
slaveTimestamp
;
positionSlaveRecB
();
// check where this record falls
if
(
slaveTimestamp
<
masterTimestamp
)
{
if
(
slaveTimestamp
<
=
masterTimestamp
)
{
overScrollSlave
(
masterTimestamp
,
slaveTimestamp
);
}
}
...
...
core/src/test/java/io/questdb/griffin/AsOfJoinTest.java
浏览文件 @
a5b8ddd3
...
...
@@ -307,7 +307,6 @@ public class AsOfJoinTest extends AbstractGriffinTest {
@Test
public
void
testLtJoinFullFat
()
throws
Exception
{
compiler
.
setFullSatJoins
(
true
);
assertMemoryLeak
(()
->
{
final
String
query
=
"select x.i, x.sym, x.amt, price, x.timestamp, y.timestamp from x lt join y on y.sym2 = x.sym"
;
...
...
@@ -322,84 +321,89 @@ public class AsOfJoinTest extends AbstractGriffinTest {
"8\tibm\t23.905\t0.9540000000000001\t2018-01-01T01:36:00.000000Z\t2018-01-01T00:56:00.000000Z\n"
+
"9\tgoogl\t67.786\t0.198\t2018-01-01T01:48:00.000000Z\t2018-01-01T01:00:00.000000Z\n"
+
"10\tgoogl\t38.54\t0.198\t2018-01-01T02:00:00.000000Z\t2018-01-01T01:00:00.000000Z\n"
;
compiler
.
compile
(
"create table x as ("
+
"select"
+
" cast(x as int) i,"
+
" rnd_symbol('msft','ibm', 'googl') sym,"
+
" round(rnd_double(0)*100, 3) amt,"
+
" to_timestamp('2018-01', 'yyyy-MM') + x * 720000000 timestamp"
+
" from long_sequence(10)"
+
") timestamp (timestamp)"
,
sqlExecutionContext
);
compiler
.
compile
(
"create table y as ("
+
"select cast(x as int) i,"
+
" rnd_symbol('msft','ibm', 'googl') sym2,"
+
" round(rnd_double(0), 3) price,"
+
" to_timestamp('2018-01', 'yyyy-MM') + x * 120000000 timestamp"
+
" from long_sequence(30)"
+
") timestamp(timestamp)"
,
sqlExecutionContext
);
assertQueryAndCache
(
expected
,
query
,
"timestamp"
,
true
);
compiler
.
compile
(
"insert into x select * from ("
+
"select"
+
" cast(x + 10 as int) i,"
+
" rnd_symbol('msft','ibm', 'googl') sym,"
+
" round(rnd_double(0)*100, 3) amt,"
+
" to_timestamp('2018-01', 'yyyy-MM') + (x + 10) * 720000000 timestamp"
+
" from long_sequence(10)"
+
") timestamp(timestamp)"
,
sqlExecutionContext
);
compiler
.
compile
(
"insert into y select * from ("
+
"select"
+
" cast(x + 30 as int) i,"
+
" rnd_symbol('msft','ibm', 'googl') sym2,"
+
" round(rnd_double(0), 3) price,"
+
" to_timestamp('2018-01', 'yyyy-MM') + (x + 30) * 120000000 timestamp"
+
" from long_sequence(30)"
+
") timestamp(timestamp)"
,
sqlExecutionContext
);
assertQuery
(
"i\tsym\tamt\tprice\ttimestamp\ttimestamp1\n"
+
"1\tmsft\t22.463\tNaN\t2018-01-01T00:12:00.000000Z\t\n"
+
"2\tgoogl\t29.92\t0.423\t2018-01-01T00:24:00.000000Z\t2018-01-01T00:16:00.000000Z\n"
+
"3\tmsft\t65.086\t0.456\t2018-01-01T00:36:00.000000Z\t2018-01-01T00:32:00.000000Z\n"
+
"4\tibm\t98.563\t0.405\t2018-01-01T00:48:00.000000Z\t2018-01-01T00:34:00.000000Z\n"
+
"5\tmsft\t50.938\t0.545\t2018-01-01T01:00:00.000000Z\t2018-01-01T00:46:00.000000Z\n"
+
"6\tibm\t76.11\t0.427\t2018-01-01T01:12:00.000000Z\t2018-01-01T01:10:00.000000Z\n"
+
"7\tmsft\t55.992000000000004\t0.226\t2018-01-01T01:24:00.000000Z\t2018-01-01T01:16:00.000000Z\n"
+
"8\tibm\t23.905\t0.029\t2018-01-01T01:36:00.000000Z\t2018-01-01T01:34:00.000000Z\n"
+
"9\tgoogl\t67.786\t0.076\t2018-01-01T01:48:00.000000Z\t2018-01-01T01:46:00.000000Z\n"
+
"10\tgoogl\t38.54\t0.339\t2018-01-01T02:00:00.000000Z\t2018-01-01T01:58:00.000000Z\n"
+
"11\tmsft\t68.069\t0.051000000000000004\t2018-01-01T02:12:00.000000Z\t2018-01-01T01:50:00.000000Z\n"
+
"12\tmsft\t24.008\t0.051000000000000004\t2018-01-01T02:24:00.000000Z\t2018-01-01T01:50:00.000000Z\n"
+
"13\tgoogl\t94.559\t0.6900000000000001\t2018-01-01T02:36:00.000000Z\t2018-01-01T02:00:00.000000Z\n"
+
"14\tibm\t62.474000000000004\t0.068\t2018-01-01T02:48:00.000000Z\t2018-01-01T01:40:00.000000Z\n"
+
"15\tmsft\t39.017\t0.051000000000000004\t2018-01-01T03:00:00.000000Z\t2018-01-01T01:50:00.000000Z\n"
+
"16\tgoogl\t10.643\t0.6900000000000001\t2018-01-01T03:12:00.000000Z\t2018-01-01T02:00:00.000000Z\n"
+
"17\tmsft\t7.246\t0.051000000000000004\t2018-01-01T03:24:00.000000Z\t2018-01-01T01:50:00.000000Z\n"
+
"18\tmsft\t36.798\t0.051000000000000004\t2018-01-01T03:36:00.000000Z\t2018-01-01T01:50:00.000000Z\n"
+
"19\tmsft\t66.98\t0.051000000000000004\t2018-01-01T03:48:00.000000Z\t2018-01-01T01:50:00.000000Z\n"
+
"20\tgoogl\t26.369\t0.6900000000000001\t2018-01-01T04:00:00.000000Z\t2018-01-01T02:00:00.000000Z\n"
,
query
,
"timestamp"
,
false
,
true
);
try
{
compiler
.
setFullFatJoins
(
true
);
compiler
.
compile
(
"create table x as ("
+
"select"
+
" cast(x as int) i,"
+
" rnd_symbol('msft','ibm', 'googl') sym,"
+
" round(rnd_double(0)*100, 3) amt,"
+
" to_timestamp('2018-01', 'yyyy-MM') + x * 720000000 timestamp"
+
" from long_sequence(10)"
+
") timestamp (timestamp)"
,
sqlExecutionContext
);
compiler
.
compile
(
"create table y as ("
+
"select cast(x as int) i,"
+
" rnd_symbol('msft','ibm', 'googl') sym2,"
+
" round(rnd_double(0), 3) price,"
+
" to_timestamp('2018-01', 'yyyy-MM') + x * 120000000 timestamp"
+
" from long_sequence(30)"
+
") timestamp(timestamp)"
,
sqlExecutionContext
);
assertQueryAndCache
(
expected
,
query
,
"timestamp"
,
true
);
compiler
.
compile
(
"insert into x select * from ("
+
"select"
+
" cast(x + 10 as int) i,"
+
" rnd_symbol('msft','ibm', 'googl') sym,"
+
" round(rnd_double(0)*100, 3) amt,"
+
" to_timestamp('2018-01', 'yyyy-MM') + (x + 10) * 720000000 timestamp"
+
" from long_sequence(10)"
+
") timestamp(timestamp)"
,
sqlExecutionContext
);
compiler
.
compile
(
"insert into y select * from ("
+
"select"
+
" cast(x + 30 as int) i,"
+
" rnd_symbol('msft','ibm', 'googl') sym2,"
+
" round(rnd_double(0), 3) price,"
+
" to_timestamp('2018-01', 'yyyy-MM') + (x + 30) * 120000000 timestamp"
+
" from long_sequence(30)"
+
") timestamp(timestamp)"
,
sqlExecutionContext
);
assertQuery
(
"i\tsym\tamt\tprice\ttimestamp\ttimestamp1\n"
+
"1\tmsft\t22.463\tNaN\t2018-01-01T00:12:00.000000Z\t\n"
+
"2\tgoogl\t29.92\t0.423\t2018-01-01T00:24:00.000000Z\t2018-01-01T00:16:00.000000Z\n"
+
"3\tmsft\t65.086\t0.456\t2018-01-01T00:36:00.000000Z\t2018-01-01T00:32:00.000000Z\n"
+
"4\tibm\t98.563\t0.405\t2018-01-01T00:48:00.000000Z\t2018-01-01T00:34:00.000000Z\n"
+
"5\tmsft\t50.938\t0.545\t2018-01-01T01:00:00.000000Z\t2018-01-01T00:46:00.000000Z\n"
+
"6\tibm\t76.11\t0.427\t2018-01-01T01:12:00.000000Z\t2018-01-01T01:10:00.000000Z\n"
+
"7\tmsft\t55.992000000000004\t0.226\t2018-01-01T01:24:00.000000Z\t2018-01-01T01:16:00.000000Z\n"
+
"8\tibm\t23.905\t0.029\t2018-01-01T01:36:00.000000Z\t2018-01-01T01:34:00.000000Z\n"
+
"9\tgoogl\t67.786\t0.076\t2018-01-01T01:48:00.000000Z\t2018-01-01T01:46:00.000000Z\n"
+
"10\tgoogl\t38.54\t0.339\t2018-01-01T02:00:00.000000Z\t2018-01-01T01:58:00.000000Z\n"
+
"11\tmsft\t68.069\t0.051000000000000004\t2018-01-01T02:12:00.000000Z\t2018-01-01T01:50:00.000000Z\n"
+
"12\tmsft\t24.008\t0.051000000000000004\t2018-01-01T02:24:00.000000Z\t2018-01-01T01:50:00.000000Z\n"
+
"13\tgoogl\t94.559\t0.6900000000000001\t2018-01-01T02:36:00.000000Z\t2018-01-01T02:00:00.000000Z\n"
+
"14\tibm\t62.474000000000004\t0.068\t2018-01-01T02:48:00.000000Z\t2018-01-01T01:40:00.000000Z\n"
+
"15\tmsft\t39.017\t0.051000000000000004\t2018-01-01T03:00:00.000000Z\t2018-01-01T01:50:00.000000Z\n"
+
"16\tgoogl\t10.643\t0.6900000000000001\t2018-01-01T03:12:00.000000Z\t2018-01-01T02:00:00.000000Z\n"
+
"17\tmsft\t7.246\t0.051000000000000004\t2018-01-01T03:24:00.000000Z\t2018-01-01T01:50:00.000000Z\n"
+
"18\tmsft\t36.798\t0.051000000000000004\t2018-01-01T03:36:00.000000Z\t2018-01-01T01:50:00.000000Z\n"
+
"19\tmsft\t66.98\t0.051000000000000004\t2018-01-01T03:48:00.000000Z\t2018-01-01T01:50:00.000000Z\n"
+
"20\tgoogl\t26.369\t0.6900000000000001\t2018-01-01T04:00:00.000000Z\t2018-01-01T02:00:00.000000Z\n"
,
query
,
"timestamp"
,
false
,
true
);
}
finally
{
compiler
.
setFullFatJoins
(
false
);
}
});
}
...
...
@@ -637,5 +641,33 @@ public class AsOfJoinTest extends AbstractGriffinTest {
printSqlResult
(
ex
,
query
,
null
,
false
,
false
);
});
}
@Test
public
void
testLessThenJoinForEqTimestamps
()
throws
Exception
{
assertMemoryLeak
(()
->
{
compiler
.
compile
(
"create table tank(ts timestamp, SequenceNumber int) timestamp(ts)"
,
sqlExecutionContext
);
executeInsert
(
"insert into tank values('2021-07-26T02:36:02.566000Z',1)"
);
executeInsert
(
"insert into tank values('2021-07-26T02:36:03.094000Z',2)"
);
executeInsert
(
"insert into tank values('2021-07-26T02:36:03.097000Z',3)"
);
executeInsert
(
"insert into tank values('2021-07-26T02:36:03.097000Z',4)"
);
executeInsert
(
"insert into tank values('2021-07-26T02:36:03.097000Z',5)"
);
executeInsert
(
"insert into tank values('2021-07-26T02:36:03.097000Z',6)"
);
executeInsert
(
"insert into tank values('2021-07-26T02:36:03.098000Z',7)"
);
executeInsert
(
"insert into tank values('2021-07-26T02:36:03.098000Z',8)"
);
String
expected
=
"ts\tcolumn\n"
+
"2021-07-26T02:36:02.566000Z\tNaN\n"
+
"2021-07-26T02:36:03.094000Z\t1\n"
+
"2021-07-26T02:36:03.097000Z\t1\n"
+
"2021-07-26T02:36:03.097000Z\t1\n"
+
"2021-07-26T02:36:03.097000Z\t1\n"
+
"2021-07-26T02:36:03.097000Z\t1\n"
+
"2021-07-26T02:36:03.098000Z\t1\n"
+
"2021-07-26T02:36:03.098000Z\t1\n"
;
String
query
=
"select w1.ts ts, w1.SequenceNumber - w2.SequenceNumber from tank w1 lt join tank w2"
;
printSqlResult
(
expected
,
query
,
"ts"
,
false
,
true
);
});
}
}
core/src/test/java/io/questdb/griffin/JoinTest.java
浏览文件 @
a5b8ddd3
...
...
@@ -2800,9 +2800,9 @@ public class JoinTest extends AbstractGriffinTest {
System
.
out
.
println
(
sink
);
compiler
.
setFull
S
atJoins
(
true
);
compiler
.
setFull
F
atJoins
(
true
);
assertSql
(
query
,
expected
);
compiler
.
setFull
S
atJoins
(
false
);
compiler
.
setFull
F
atJoins
(
false
);
assertSql
(
query
,
expected
);
}));
}
...
...
@@ -2844,9 +2844,9 @@ public class JoinTest extends AbstractGriffinTest {
sqlExecutionContext
);
compiler
.
setFull
S
atJoins
(
true
);
compiler
.
setFull
F
atJoins
(
true
);
assertSql
(
query
,
expected
);
compiler
.
setFull
S
atJoins
(
false
);
compiler
.
setFull
F
atJoins
(
false
);
assertSql
(
query
,
expected
);
}));
}
...
...
@@ -3777,9 +3777,9 @@ public class JoinTest extends AbstractGriffinTest {
"g2 as (select distinct * from t2)"
+
"select * from g1 lt join g2 on g1.geo4 = g2.geo4"
;
compiler
.
setFull
S
atJoins
(
true
);
compiler
.
setFull
F
atJoins
(
true
);
assertSql
(
sql
,
expected
);
compiler
.
setFull
S
atJoins
(
false
);
compiler
.
setFull
F
atJoins
(
false
);
assertSql
(
sql
,
expected
);
});
}
...
...
@@ -3843,11 +3843,11 @@ public class JoinTest extends AbstractGriffinTest {
}
private
void
testFullFat
(
TestMethod
method
)
throws
Exception
{
compiler
.
setFull
S
atJoins
(
true
);
compiler
.
setFull
F
atJoins
(
true
);
try
{
method
.
run
();
}
finally
{
compiler
.
setFull
S
atJoins
(
false
);
compiler
.
setFull
F
atJoins
(
false
);
}
}
...
...
core/src/test/java/io/questdb/griffin/SecurityTest.java
浏览文件 @
a5b8ddd3
...
...
@@ -749,7 +749,7 @@ public class SecurityTest extends AbstractGriffinTest {
" timestamp_sequence(0, 1000000000) ts2"
+
" from long_sequence(10)) timestamp(ts2)"
,
sqlExecutionContext
);
try
{
compiler
.
setFull
S
atJoins
(
true
);
compiler
.
setFull
F
atJoins
(
true
);
assertQuery
(
"sym1\tsym2\nVTJW\tFJG\nVTJW\tULO\n"
,
"select sym1, sym2 from tb1 inner join tb2 on tb2.ts2=tb1.ts1 where d1 < 0.3"
,
...
...
@@ -767,7 +767,7 @@ public class SecurityTest extends AbstractGriffinTest {
Assert
.
assertTrue
(
ex
.
toString
().
contains
(
"limit of 2 resizes exceeded"
));
}
}
finally
{
compiler
.
setFull
S
atJoins
(
false
);
compiler
.
setFull
F
atJoins
(
false
);
}
});
}
...
...
@@ -787,7 +787,7 @@ public class SecurityTest extends AbstractGriffinTest {
" timestamp_sequence(0, 1000000000) ts2"
+
" from long_sequence(10)) timestamp(ts2)"
,
sqlExecutionContext
);
try
{
compiler
.
setFull
S
atJoins
(
true
);
compiler
.
setFull
F
atJoins
(
true
);
assertQuery
(
"sym1\tsym2\nVTJW\tFJG\nVTJW\tULO\n"
,
"select sym1, sym2 from tb1 outer join tb2 on tb2.ts2=tb1.ts1 where d1 < 0.3"
,
...
...
@@ -805,7 +805,7 @@ public class SecurityTest extends AbstractGriffinTest {
Assert
.
assertTrue
(
ex
.
toString
().
contains
(
"limit of 2 resizes exceeded"
));
}
}
finally
{
compiler
.
setFull
S
atJoins
(
false
);
compiler
.
setFull
F
atJoins
(
false
);
}
});
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录