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(sql): UnsupportedOperationException on join with constant non-boolean filter expression #3334

Merged
merged 5 commits into from
May 15, 2023
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
7 changes: 5 additions & 2 deletions core/src/main/java/io/questdb/griffin/SqlCodeGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -1695,12 +1695,12 @@ private RecordCursorFactory generateJoins(QueryModel model, SqlExecutionContext
break;
}
}
} catch (Throwable th) {
} catch (Throwable e) {
master = Misc.free(master);
if (releaseSlave) {
Misc.free(slave);
}
throw th;
throw e;
} finally {
executionContext.popTimestampRequiredFlag();
}
Expand Down Expand Up @@ -1747,6 +1747,9 @@ private RecordCursorFactory generateJoins(QueryModel model, SqlExecutionContext
ExpressionNode constFilter = model.getConstWhereClause();
if (constFilter != null) {
Function function = functionParser.parseFunction(constFilter, null, executionContext);
if (!ColumnType.isBoolean(function.getType())) {
throw SqlException.position(constFilter.position).put("boolean expression expected");
}
function.init(null, executionContext);
if (!function.getBool(null)) {
// do not copy metadata here
Expand Down
13 changes: 13 additions & 0 deletions core/src/test/java/io/questdb/test/griffin/JoinTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2359,6 +2359,19 @@ public void testJoinInnerAllTypesFF() throws Exception {
testFullFat(this::testJoinInnerAllTypes);
}

@Test
public void testJoinInnerConstantFilterWithNonBooleanExpressionFails() throws Exception {
assertMemoryLeak(() -> {
compiler.compile("CREATE TABLE IF NOT EXISTS x (ts timestamp, event short) TIMESTAMP(ts);", sqlExecutionContext);

assertFailure(
"SELECT count(*) FROM x AS a INNER JOIN x AS b ON a.event = b.event WHERE now()",
"boolean expression expected",
73
);
});
}

@Test
public void testJoinInnerDifferentColumnNames() throws Exception {
assertMemoryLeak(() -> {
Expand Down