Skip to content

LT/ASOF JOIN with timestamp in ON clause crashes with AssertionError instead of returning proper error #6637

@jerrinot

Description

@jerrinot

To reproduce

Description:
When using LT JOIN or ASOF JOIN with the designated timestamp column included in the ON clause, QuestDB might crash with an AssertionError instead of returning a proper SQLException.

Reproducer:

@Test
    public void testLtJoinWithTimestampInOnClauseCrash() throws Exception {
        assertMemoryLeak(() -> {
            execute("CREATE TABLE t1 (ts TIMESTAMP, i INT, s SYMBOL, val INT) timestamp(ts) partition by DAY");
            execute("CREATE TABLE t2 (ts TIMESTAMP, i INT, s SYMBOL INDEX, val INT) timestamp(ts) partition by DAY");

            execute("INSERT INTO t1 VALUES ('2024-01-01T10:00:00.000000Z', 1, 'A', 10)");
            execute("INSERT INTO t2 VALUES ('2024-01-01T10:00:00.000000Z', 2, 'A', 20)");

            try {
                // SAMPLE BY makes the slave factory return false for recordCursorSupportsRandomAccess()
                // which triggers the full fat join code path without needing setFullFatJoins(true)
                assertQueryNoLeakCheck(
                        "", // expected - we don't care, expecting exception
                        "SELECT t1.ts, sub.isum FROM t1 LT JOIN (" +
                                "  SELECT ts, sum(i) as isum, s FROM t2 SAMPLE BY 1us ALIGN TO CALENDAR" +
                                ") sub ON (t1.s = sub.s) AND (t1.ts = sub.ts)",
                        null,
                        false,
                        sqlExecutionContext
                );
                Assert.fail("Query should have thrown SQLException, not succeeded");
            } catch (SqlException e) {
                // Expected behavior - proper error message about timestamp in join key
                Assert.assertTrue("Expected error about timestamp in join key, got: " + e.getMessage(),
                        e.getMessage().contains("timestamp"));
            } catch (AssertionError e) {
                // This is the BUG - AssertionError is thrown instead of SQLException
                Assert.fail("Query threw AssertionError instead of proper SQLException: " + e.getMessage());
            }
        });
    }

Using a timestamp as a key in LT/ASOF JOINs make little sense, IMHO it's acceptable ot throw an SQLException. But AssertionError is not acceptable at all.

QuestDB version:

8.3.0

Metadata

Metadata

Assignees

Labels

BugIncorrect or unexpected behaviorGood first issueA great place to get familiar with the codebaseHelp wantedAssistance or additional information is wanted

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions