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

Core: Make sqlFor case insensitive for dialect check #9311

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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion core/src/main/java/org/apache/iceberg/view/BaseView.java
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public SQLViewRepresentation sqlFor(String dialect) {
for (ViewRepresentation representation : currentVersion().representations()) {
if (representation instanceof SQLViewRepresentation) {
SQLViewRepresentation sqlViewRepresentation = (SQLViewRepresentation) representation;
if (sqlViewRepresentation.dialect().equals(dialect)) {
if (sqlViewRepresentation.dialect().equalsIgnoreCase(dialect)) {
return sqlViewRepresentation;
} else if (closest == null) {
closest = sqlViewRepresentation;
Expand Down
22 changes: 22 additions & 0 deletions core/src/test/java/org/apache/iceberg/view/ViewCatalogTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -1693,6 +1693,28 @@ public void testSqlForMultipleDialects() {
assertThat(view.sqlFor("unknown-dialect").sql()).isEqualTo("select * from ns.tbl");
}

@Test
public void testSqlForCaseInsensitive() {
TableIdentifier identifier = TableIdentifier.of("ns", "view");

if (requiresNamespaceCreate()) {
catalog().createNamespace(identifier.namespace());
}

View view =
catalog()
.buildView(identifier)
.withSchema(SCHEMA)
.withDefaultNamespace(identifier.namespace())
.withDefaultCatalog(catalog().name())
.withQuery("spark", "select * from ns.tbl")
.withQuery("trino", "select * from ns.tbl using X")
.create();

assertThat(view.sqlFor("SPARK").sql()).isEqualTo("select * from ns.tbl");
assertThat(view.sqlFor("TRINO").sql()).isEqualTo("select * from ns.tbl using X");
}

@Test
public void testSqlForInvalidArguments() {
TableIdentifier identifier = TableIdentifier.of("ns", "view");
Expand Down