Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(griffin): as of join failed when timestamp was not in select clause #560

Merged
merged 1 commit into from
Aug 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions core/src/main/java/io/questdb/griffin/SqlCodeGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -623,6 +623,7 @@ private RecordCursorFactory generateJoins(QueryModel model, SqlExecutionContext
RecordCursorFactory master = null;
CharSequence masterAlias = null;

executionContext.pushTimestampRequiredFlag(true);
try {
int n = ordered.size();
assert n > 0;
Expand Down Expand Up @@ -816,6 +817,8 @@ private RecordCursorFactory generateJoins(QueryModel model, SqlExecutionContext
} catch (CairoException | SqlException e) {
Misc.free(master);
throw e;
} finally {
executionContext.popTimestampRequiredFlag();
}
}

Expand Down Expand Up @@ -1452,6 +1455,7 @@ private RecordCursorFactory generateSelectChoose(QueryModel model, SqlExecutionC
metadata.isSymbolTableStatic(timestampIndex)
)
);
selectMetadata.setTimestampIndex(selectMetadata.getColumnCount() - 1);
}

return new SelectedRecordCursorFactory(selectMetadata, columnCrossIndex, factory);
Expand Down
17 changes: 17 additions & 0 deletions core/src/test/java/io/questdb/griffin/SqlParserTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2747,6 +2747,23 @@ public void testJoinTimestampPropagation() throws SqlException {
);
}

@Test
public void testJoinTimestampPropagationWhenTimestampNotSelected() throws SqlException {
assertQuery(
"select-distinct id from (select-choose [id] id from ((select-choose [a.id id] a.created ts_stop, a.id id, b.created ts_start, b.id id1 from (select [id, created] from (select-choose [id] id, created, event, timestamp from ((select-choose [id, created] id, created, event, timestamp from (select [id, created, event] from telemetry_users timestamp (timestamp) where event = 101 and id != '0x05ab1e873d165b00000005743f2c17') order by created) _xQdbA7) timestamp (created)) a lt join select [id, created] from (select-choose [id] id, created, event, timestamp from ((select-choose [id, created] id, created, event, timestamp from (select [id, created, event] from telemetry_users timestamp (timestamp) where event = 100) order by created) _xQdbA4) timestamp (created)) b on b.id = a.id post-join-where a.created - b.created > 10000000000)) _xQdbA1))",
"with \n" +
" starts as ((telemetry_users where event = 100 order by created) timestamp(created)),\n" +
" stops as ((telemetry_users where event = 101 order by created) timestamp(created))\n" +
"\n" +
"select distinct id from (select a.created ts_stop, a.id, b.created ts_start, b.id from stops a lt join starts b on (id)) where id <> '0x05ab1e873d165b00000005743f2c17' and ts_stop - ts_start > 10000000000\n",
modelOf("telemetry_users")
.col("id", ColumnType.LONG256)
.col("created", ColumnType.TIMESTAMP)
.col("event", ColumnType.SHORT)
.timestamp()
);
}

@Test
public void testJoinTriangle() throws Exception {
assertQuery(
Expand Down