From 24d58579188b774a1c1e1f8bed13e3cf2bbf3a17 Mon Sep 17 00:00:00 2001 From: Amogh Jahagirdar Date: Sat, 16 Dec 2023 10:03:53 -0800 Subject: [PATCH] Core: Make sqlFor case insensitive for dialect check (#9311) --- .../org/apache/iceberg/view/BaseView.java | 2 +- .../apache/iceberg/view/ViewCatalogTests.java | 22 +++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/org/apache/iceberg/view/BaseView.java b/core/src/main/java/org/apache/iceberg/view/BaseView.java index 57d35c9ffc54..d30fc6535098 100644 --- a/core/src/main/java/org/apache/iceberg/view/BaseView.java +++ b/core/src/main/java/org/apache/iceberg/view/BaseView.java @@ -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; diff --git a/core/src/test/java/org/apache/iceberg/view/ViewCatalogTests.java b/core/src/test/java/org/apache/iceberg/view/ViewCatalogTests.java index 795e3aa2ef86..58727e4588ff 100644 --- a/core/src/test/java/org/apache/iceberg/view/ViewCatalogTests.java +++ b/core/src/test/java/org/apache/iceberg/view/ViewCatalogTests.java @@ -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");