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

Queries involving multiple joins fail #18

Closed
C0urante opened this issue Apr 4, 2017 · 1 comment
Closed

Queries involving multiple joins fail #18

C0urante opened this issue Apr 4, 2017 · 1 comment

Comments

@C0urante
Copy link

C0urante commented Apr 4, 2017

The following test fails with a NullPointerException when added to the KQLParserTest.java class:

  @Test
  public void testMultipleJoins() throws Exception {
    MetaStore tempMetaStore = new MetaStoreImpl();

    for (KQLTopic kqlTopic : metaStore.getAllKQLTopics().values()) {
      tempMetaStore.putTopic(kqlTopic);
    }
    for (StructuredDataSource dataSource : metaStore.getAllStructuredDataSources().values()) {
      tempMetaStore.putSource(dataSource);
    }

    SchemaBuilder schemaBuilder = SchemaBuilder.struct()
        .field("COL0", SchemaBuilder.INT64_SCHEMA)
        .field("COL1", SchemaBuilder.FLOAT64_SCHEMA)
        .field("COL2", SchemaBuilder.STRING_SCHEMA)
        .field("COL3", SchemaBuilder.INT64_SCHEMA);

    KQLTopic
        kqlTopic =
        new KQLTopic("TEST3", "test3", new KQLJsonTopicSerDe());

    KQLStream kqlStream = new KQLStream("TEST3", schemaBuilder, schemaBuilder.field("COL0"),
        kqlTopic);

    tempMetaStore.putTopic(kqlTopic);
    tempMetaStore.putSource(kqlStream);

    String
        queryStr =
        "SELECT t1.col1, t2.col2, t3.col3 FROM "
            + "(test1 t1 LEFT JOIN test2 t2 ON t1.col1 = t2.col1) "
            + "LEFT JOIN test3 t3 ON t1.col1 = t3.col1;";
    Statement statement = kqlParser.buildAST(queryStr, tempMetaStore).get(0);
    Assert.assertTrue("testSimpleQuery fails", statement instanceof Query);
    Query query = (Query) statement;
    Assert.assertTrue("testTripleJoin fails", query.getQueryBody() instanceof QuerySpecification);
  }

The problem appears to be in the DataSourceExtractor.visitAliasedRelation() method, where it is assumed that the relationPrimary component of an aliasedRelation rule is a qualifiedName, when in fact it can also be another relation contained between parentheses, like in (test1 t1 LEFT JOIN test2 t2 ON t1.col1 = t2.col1). The result is that this relationPrimary is then visited as a joinRelation, which causes the visitJoinRelation() method to be called, which then returns null all the way up the call chain back to the original invocation of visitAliasedRelation, which then causes the NPE when the result (assumed to be a Table, actually null) is accessed.

@rmoff
Copy link
Contributor

rmoff commented Sep 14, 2018

Tracking issue for multi-join support: #1891

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants