Skip to content

Commit

Permalink
Core: Make sqlFor case insensitive for dialect check (apache#9311)
Browse files Browse the repository at this point in the history
  • Loading branch information
amogh-jahagirdar authored and devangjhabakh committed Apr 22, 2024
1 parent b7c513c commit 24d5857
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
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

0 comments on commit 24d5857

Please sign in to comment.