未验证 提交 a5b8ddd3 编写于 作者: E Eugene Lysiuchenko 提交者: GitHub

fix(sql): fix lt join for equal timestampts (#1321)

上级 7836466a
......@@ -2171,7 +2171,7 @@ public class SqlCompiler implements Closeable {
return compiledQuery.ofRepair();
}
void setFullSatJoins(boolean value) {
void setFullFatJoins(boolean value) {
codeGenerator.setFullFatJoins(value);
}
......
......@@ -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);
}
}
......
......@@ -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);
});
}
}
......@@ -2800,9 +2800,9 @@ public class JoinTest extends AbstractGriffinTest {
System.out.println(sink);
compiler.setFullSatJoins(true);
compiler.setFullFatJoins(true);
assertSql(query, expected);
compiler.setFullSatJoins(false);
compiler.setFullFatJoins(false);
assertSql(query, expected);
}));
}
......@@ -2844,9 +2844,9 @@ public class JoinTest extends AbstractGriffinTest {
sqlExecutionContext
);
compiler.setFullSatJoins(true);
compiler.setFullFatJoins(true);
assertSql(query, expected);
compiler.setFullSatJoins(false);
compiler.setFullFatJoins(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.setFullSatJoins(true);
compiler.setFullFatJoins(true);
assertSql(sql, expected);
compiler.setFullSatJoins(false);
compiler.setFullFatJoins(false);
assertSql(sql, expected);
});
}
......@@ -3843,11 +3843,11 @@ public class JoinTest extends AbstractGriffinTest {
}
private void testFullFat(TestMethod method) throws Exception {
compiler.setFullSatJoins(true);
compiler.setFullFatJoins(true);
try {
method.run();
} finally {
compiler.setFullSatJoins(false);
compiler.setFullFatJoins(false);
}
}
......
......@@ -749,7 +749,7 @@ public class SecurityTest extends AbstractGriffinTest {
" timestamp_sequence(0, 1000000000) ts2" +
" from long_sequence(10)) timestamp(ts2)", sqlExecutionContext);
try {
compiler.setFullSatJoins(true);
compiler.setFullFatJoins(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.setFullSatJoins(false);
compiler.setFullFatJoins(false);
}
});
}
......@@ -787,7 +787,7 @@ public class SecurityTest extends AbstractGriffinTest {
" timestamp_sequence(0, 1000000000) ts2" +
" from long_sequence(10)) timestamp(ts2)", sqlExecutionContext);
try {
compiler.setFullSatJoins(true);
compiler.setFullFatJoins(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.setFullSatJoins(false);
compiler.setFullFatJoins(false);
}
});
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册