Skip to content

Commit

Permalink
Throw error if a specific table isn't found (#457)
Browse files Browse the repository at this point in the history
* Throw error if the specific table not found

* fix test
  • Loading branch information
goldmedal authored Feb 7, 2024
1 parent ef7b43c commit aa2dad2
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ public Statement apply(Statement root, SessionContext sessionContext, Analysis a
descriptors.forEach(queryDescriptor -> withQueries.add(getWithQuery(queryDescriptor)));
// If a selected table lacks any required fields, create a dummy with query for it.
analysis.getTables().stream().filter(table -> !tableRequiredFields.containsKey(table.getSchemaTableName().getTableName()))
.filter(table -> accioMDL.isObjectExist(table.getSchemaTableName().getTableName()))
.forEach(dummy -> withQueries.add(getWithQuery(new DummyInfo(dummy.getSchemaTableName().getTableName()))));

Node rewriteWith = new WithRewriter(withQueries).process(root);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ public void testModelOnMetric()
assertThat(result.get(0).size()).isEqualTo(2);
assertThat(result.size()).isEqualTo(14958);

assertThatCode(() -> query(rewrite("select 1 from testModelOnMetric", true)))
assertThatCode(() -> query(rewrite("select 1 from testModelOnMetric", mdl, true)))
.doesNotThrowAnyException();
}

Expand All @@ -304,7 +304,7 @@ public void testMetricOnMetric()
assertThat(result.get(0).size()).isEqualTo(2);
assertThat(result.size()).isEqualTo(7);

assertThatCode(() -> query(rewrite("select 1 from testMetricOnMetric", true)))
assertThatCode(() -> query(rewrite("select 1 from testMetricOnMetric", mdl, true)))
.doesNotThrowAnyException();
}

Expand Down
13 changes: 13 additions & 0 deletions accio-base/src/test/java/io/accio/base/sqlrewrite/TestModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import static java.util.Objects.requireNonNull;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatCode;
import static org.assertj.core.api.Assertions.assertThatThrownBy;

public class TestModel
extends AbstractTestFramework
Expand Down Expand Up @@ -320,6 +321,18 @@ public void testSelectEmpty()
.doesNotThrowAnyException();
}

@Test
public void testSelectNotFound()
{
Manifest manifest = withDefaultCatalogSchema()
.setModels(List.of(customer))
.setRelationships(List.of(ordersCustomer, ordersLineitem))
.build();
AccioMDL mdl = AccioMDL.fromManifest(manifest);
assertThatThrownBy(() -> query(rewrite("SELECT * FROM notfound", mdl, true)))
.hasMessageFindingMatch(".*notfound.*");
}

private void assertQuery(AccioMDL mdl, @Language("SQL") String accioSql, @Language("SQL") String duckDBSql)
{
assertThat(query(rewrite(accioSql, mdl, true))).isEqualTo(query(duckDBSql));
Expand Down

0 comments on commit aa2dad2

Please sign in to comment.