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

test for wrong table #48

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions src/test/java/ai/starlake/transpiler/JSQLColumnResolverTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,35 @@ void testSimpleSchemaProvider() throws JSQLParserException, SQLException {
.isEqualTo(new String[] {res.getTableName(6), res.getColumnName(6)});
}

@Test
void testWithWrongTable() {
JdbcMetaData metaData = new JdbcMetaData("", "")
.addTable("a", new JdbcColumn("col1"), new JdbcColumn("col2"), new JdbcColumn("col3"))
.addTable("b", new JdbcColumn("col1"), new JdbcColumn("col2"), new JdbcColumn("col3"));

//should be exception because bb table is not exist
org.junit.jupiter.api.Assertions.assertThrows(JSQLParserException.class, () -> JSQLColumResolver.getResultSetMetaData("select * from a where a.col1 in (select bb.col1 from bb)", metaData));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

JSQLParserException is very generic and can mean anything.
If you want to make this test meaniningful then please check if Table bb is pointed out and blamed correctly.

}

@Test
void testWithWrongTable1() {
JdbcMetaData metaData = new JdbcMetaData("", "")
.addTable("foo", new JdbcColumn("id"), new JdbcColumn("name"));

//should be exception because foo1 table is not exist
org.junit.jupiter.api.Assertions.assertThrows(JSQLParserException.class, () -> JSQLColumResolver.getResultSetMetaData("select sum(foo1.id) from foo group by foo.name", metaData));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please:

import org.junit.jupiter.api.Assertions
and then call Assertions.assertThrows(...)

org.junit.jupiter.api.Assertions.assertThrows(JSQLParserException.class, () -> JSQLColumResolver.getResultSetMetaData("select avg(foo1.id) from foo group by foo.name", metaData));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Literally the same tests.

}

@Test
void testWithWrongColumn() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will not throw any exception because foo.name1 is not related to any SelectItem and not part of the lineage.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we throw exception if we use "wrong" name of column. But why "wrong" table name should have other behavior

JdbcMetaData metaData = new JdbcMetaData("", "")
.addTable("foo", new JdbcColumn("id"), new JdbcColumn("name"));

//should be exception because name1 column is not exist
org.junit.jupiter.api.Assertions.assertThrows(JSQLParserException.class, () -> JSQLColumResolver.getResultSetMetaData("select count(foo.id) from foo group by foo.name having foo.name1 = 'test'", metaData));
}

@Test
void testSimplerSchemaProvider() throws JSQLParserException, SQLException {
JdbcMetaData metaData = new JdbcMetaData().addTable("a", "col1", "col2", "col3").addTable("b",
Expand Down