From 38de7956a6531856d3e0b093c643aec402f0a42a Mon Sep 17 00:00:00 2001 From: Victor Vieux Date: Tue, 27 Feb 2024 20:28:43 -0800 Subject: [PATCH 1/6] Add alternative hostname support to snowflake --- .../snowflake/resources/metabase-plugin.yaml | 6 ++++++ .../snowflake/src/metabase/driver/snowflake.clj | 7 +++++++ .../test/metabase/driver/snowflake_test.clj | 15 ++++++++++++--- 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/modules/drivers/snowflake/resources/metabase-plugin.yaml b/modules/drivers/snowflake/resources/metabase-plugin.yaml index 9d2397c25d16f..5de031fae8a2d 100644 --- a/modules/drivers/snowflake/resources/metabase-plugin.yaml +++ b/modules/drivers/snowflake/resources/metabase-plugin.yaml @@ -48,6 +48,12 @@ driver: type: boolean visible-if: advanced-options: true + - name: alternative-hostname + display-name: Set alternative hostname (instead of .snowflakecomputing.com) + default: "" + type: string + visible-if: + advanced-options: true - default-advanced-options init: - step: load-namespace diff --git a/modules/drivers/snowflake/src/metabase/driver/snowflake.clj b/modules/drivers/snowflake/src/metabase/driver/snowflake.clj index c4ae98690e89c..41b57fa9f0e62 100644 --- a/modules/drivers/snowflake/src/metabase/driver/snowflake.clj +++ b/modules/drivers/snowflake/src/metabase/driver/snowflake.clj @@ -151,6 +151,13 @@ ;; see https://github.com/metabase/metabase/issues/27856 (cond-> (:quote-db-name details) (update :db quote-name)) + ;; see https://github.com/metabase/metabase/issues/22133 + (update :subname (fn [existing-subname] + (if-let [alt-hostname (:alternative-hostname details)] + (if (not (empty? alt-hostname)) + (str "//" alt-hostname "/") + existing-subname) + existing-subname))) ;; see https://github.com/metabase/metabase/issues/9511 (update :warehouse upcase-not-nil) (update :schema upcase-not-nil) diff --git a/modules/drivers/snowflake/test/metabase/driver/snowflake_test.clj b/modules/drivers/snowflake/test/metabase/driver/snowflake_test.clj index da1fb5eced74f..8463cc93fac82 100644 --- a/modules/drivers/snowflake/test/metabase/driver/snowflake_test.clj +++ b/modules/drivers/snowflake/test/metabase/driver/snowflake_test.clj @@ -78,6 +78,7 @@ :private-key-options "uploaded" :private-key-source nil :port nil + :subname "//ls10467.us-east-2.aws.snowflakecomputing.com/" :advanced-options true :private-key-id 1 :schema-filters-type "all" @@ -87,13 +88,21 @@ :engine :snowflake :private-key-creator-id 3 :user "SNOWFLAKE_DEVELOPER" - :private-key-created-at "2024-01-05T19:10:30.861839Z"}] - (testing "Database name is quoted iff quoting is requested (#27856)" + :private-key-created-at "2024-01-05T19:10:30.861839Z" + :alternative-hostname ""}] + (testing "Database name is quoted if quoting is requested (#27856)" (are [quote? result] (=? {:db result} (let [details (assoc details :quote-db-name quote?)] (sql-jdbc.conn/connection-details->spec :snowflake details))) true "\"v3_sample-dataset\"" - false "v3_sample-dataset")))) + false "v3_sample-dataset")) + (testing "Subname is replaced if alternative is provided (#22133)" + (are [alternative? result] (=? {:subname result} + (let [details (assoc details :alternative-hostname alternative?)] + (sql-jdbc.conn/connection-details->spec :snowflake details))) + nil "//ls10467.us-east-2.aws.snowflakecomputing.com/" + "" "//ls10467.us-east-2.aws.snowflakecomputing.com/" + "snowflake.example.com" "//snowflake.example.com/")))) (deftest ^:parallel ddl-statements-test (testing "make sure we didn't break the code that is used to generate DDL statements when we add new test datasets" From c5d1ccc38bdca8b65eeea2a22dfc21c27d6134b0 Mon Sep 17 00:00:00 2001 From: Victor Vieux Date: Thu, 14 Mar 2024 01:37:22 -0700 Subject: [PATCH 2/6] move hostname support out of additional details --- ...DatabaseAccountNameSectionField.styled.tsx | 15 +++++++++ .../DatabaseAccountNameSectionField.tsx | 32 +++++++++++++++++++ .../DatabaseAccountNameSectionField/index.ts | 2 ++ frontend/src/metabase/databases/constants.tsx | 4 +++ .../snowflake/resources/metabase-plugin.yaml | 15 +++++---- .../src/metabase/driver/snowflake.clj | 17 +++++----- .../test/metabase/driver/snowflake_test.clj | 24 ++++++++------ 7 files changed, 85 insertions(+), 24 deletions(-) create mode 100644 frontend/src/metabase/databases/components/DatabaseAccountNameSectionField/DatabaseAccountNameSectionField.styled.tsx create mode 100644 frontend/src/metabase/databases/components/DatabaseAccountNameSectionField/DatabaseAccountNameSectionField.tsx create mode 100644 frontend/src/metabase/databases/components/DatabaseAccountNameSectionField/index.ts diff --git a/frontend/src/metabase/databases/components/DatabaseAccountNameSectionField/DatabaseAccountNameSectionField.styled.tsx b/frontend/src/metabase/databases/components/DatabaseAccountNameSectionField/DatabaseAccountNameSectionField.styled.tsx new file mode 100644 index 0000000000000..671c58493d174 --- /dev/null +++ b/frontend/src/metabase/databases/components/DatabaseAccountNameSectionField/DatabaseAccountNameSectionField.styled.tsx @@ -0,0 +1,15 @@ +import styled from "@emotion/styled"; + +import Button from "metabase/core/components/Button"; +import { color } from "metabase/lib/colors"; + +export const SectionButton = styled(Button)` + color: ${color("brand")}; + padding: 0; + border: none; + border-radius: 0; + + &:hover { + background-color: transparent; + } +`; diff --git a/frontend/src/metabase/databases/components/DatabaseAccountNameSectionField/DatabaseAccountNameSectionField.tsx b/frontend/src/metabase/databases/components/DatabaseAccountNameSectionField/DatabaseAccountNameSectionField.tsx new file mode 100644 index 0000000000000..4a1935a972018 --- /dev/null +++ b/frontend/src/metabase/databases/components/DatabaseAccountNameSectionField/DatabaseAccountNameSectionField.tsx @@ -0,0 +1,32 @@ +import { useField } from "formik"; +import { useCallback } from "react"; +import { t } from "ttag"; + +import FormField from "metabase/core/components/FormField"; + +import { SectionButton } from "./DatabaseAccountNameSectionField.styled"; + +export interface DatabaseAccountNameSectionFieldProps { + name: string; +} + +const DatabaseAccountNameSectionField = ({ + name, +}: DatabaseAccountNameSectionFieldProps): JSX.Element => { + const [{ value }, , { setValue }] = useField(name); + + const handleClick = useCallback(() => { + setValue(!value); + }, [value, setValue]); + + return ( + + + {value ? t`Use hostname` : t`Use account name`} + + + ); +}; + +// eslint-disable-next-line import/no-default-export -- deprecated usage +export default DatabaseAccountNameSectionField; diff --git a/frontend/src/metabase/databases/components/DatabaseAccountNameSectionField/index.ts b/frontend/src/metabase/databases/components/DatabaseAccountNameSectionField/index.ts new file mode 100644 index 0000000000000..960c79c3177e6 --- /dev/null +++ b/frontend/src/metabase/databases/components/DatabaseAccountNameSectionField/index.ts @@ -0,0 +1,2 @@ +// eslint-disable-next-line import/no-default-export -- deprecated usage +export { default } from "./DatabaseAccountNameSectionField"; diff --git a/frontend/src/metabase/databases/constants.tsx b/frontend/src/metabase/databases/constants.tsx index cae32e030d7ad..265597973d4b4 100644 --- a/frontend/src/metabase/databases/constants.tsx +++ b/frontend/src/metabase/databases/constants.tsx @@ -6,6 +6,7 @@ import DatabaseAuthCodeDescription from "./components/DatabaseAuthCodeDescriptio import DatabaseCacheScheduleField from "./components/DatabaseCacheScheduleField"; import DatabaseClientIdDescription from "./components/DatabaseClientIdDescription"; import DatabaseConnectionSectionField from "./components/DatabaseConnectionSectionField"; +import DatabaseAccountNameSectionField from "./components/DatabaseAccountNameSectionField"; import DatabaseScheduleToggleField from "./components/DatabaseScheduleToggleField"; import DatabaseSshDescription from "./components/DatabaseSshDescription"; import DatabaseSslKeyDescription from "./components/DatabaseSslKeyDescription"; @@ -104,6 +105,9 @@ export const FIELD_OVERRIDES: Record = { "use-conn-uri": { type: DatabaseConnectionSectionField, }, + "use-account-name": { + type: DatabaseAccountNameSectionField, + }, "let-user-control-scheduling": { type: DatabaseScheduleToggleField, }, diff --git a/modules/drivers/snowflake/resources/metabase-plugin.yaml b/modules/drivers/snowflake/resources/metabase-plugin.yaml index 5de031fae8a2d..b8521a63e8f54 100644 --- a/modules/drivers/snowflake/resources/metabase-plugin.yaml +++ b/modules/drivers/snowflake/resources/metabase-plugin.yaml @@ -8,11 +8,20 @@ driver: lazy-load: true parent: sql-jdbc connection-properties: + - name: use-account-name + type: section + default: true + - merge: + - host + - visible-if: + use-account-name: false - name: account display-name: Account name helper-text: Enter your Account ID with the region that your Snowflake cluster is running on e.g. "xxxxxxxx.us-east-2.aws". Some regions don't have this suffix. placeholder: xxxxxxxx.us-east-2.aws required: true + visible-if: + use-account-name: true - user - password - name: private-key @@ -48,12 +57,6 @@ driver: type: boolean visible-if: advanced-options: true - - name: alternative-hostname - display-name: Set alternative hostname (instead of .snowflakecomputing.com) - default: "" - type: string - visible-if: - advanced-options: true - default-advanced-options init: - step: load-namespace diff --git a/modules/drivers/snowflake/src/metabase/driver/snowflake.clj b/modules/drivers/snowflake/src/metabase/driver/snowflake.clj index 41b57fa9f0e62..4ebda7905fc55 100644 --- a/modules/drivers/snowflake/src/metabase/driver/snowflake.clj +++ b/modules/drivers/snowflake/src/metabase/driver/snowflake.clj @@ -123,7 +123,7 @@ (str "\"" (str/replace raw-name "\"" "\"\"") "\""))) (defmethod sql-jdbc.conn/connection-details->spec :snowflake - [_ {:keys [account additional-options], :as details}] + [_ {:keys [account additional-options host use-account-name], :as details}] (when (get "week_start" (sql-jdbc.common/additional-options->map additional-options :url)) (log/warn (trs "You should not set WEEK_START in Snowflake connection options; this might lead to incorrect results. Set the Start of Week Setting instead."))) (let [upcase-not-nil (fn [s] (when s (u/upper-case-en s)))] @@ -131,7 +131,13 @@ ;; https://support.snowflake.net/s/question/0D50Z00008WTOMCSA5/ (-> (merge {:classname "net.snowflake.client.jdbc.SnowflakeDriver" :subprotocol "snowflake" - :subname (str "//" account ".snowflakecomputing.com/") + ;; see https://github.com/metabase/metabase/issues/22133 + :subname (let [base-url (if (and (not use-account-name) (string? host) (not (empty? host))) + (if-not (= (last host) \/) + (str host "/") + host) + (str account ".snowflakecomputing.com/"))] + (str "//" base-url )) :client_metadata_request_use_connection_ctx true :ssl true ;; keep open connections open indefinitely instead of closing them. See #9674 and @@ -151,13 +157,6 @@ ;; see https://github.com/metabase/metabase/issues/27856 (cond-> (:quote-db-name details) (update :db quote-name)) - ;; see https://github.com/metabase/metabase/issues/22133 - (update :subname (fn [existing-subname] - (if-let [alt-hostname (:alternative-hostname details)] - (if (not (empty? alt-hostname)) - (str "//" alt-hostname "/") - existing-subname) - existing-subname))) ;; see https://github.com/metabase/metabase/issues/9511 (update :warehouse upcase-not-nil) (update :schema upcase-not-nil) diff --git a/modules/drivers/snowflake/test/metabase/driver/snowflake_test.clj b/modules/drivers/snowflake/test/metabase/driver/snowflake_test.clj index 8463cc93fac82..48e8a084e46ce 100644 --- a/modules/drivers/snowflake/test/metabase/driver/snowflake_test.clj +++ b/modules/drivers/snowflake/test/metabase/driver/snowflake_test.clj @@ -78,7 +78,6 @@ :private-key-options "uploaded" :private-key-source nil :port nil - :subname "//ls10467.us-east-2.aws.snowflakecomputing.com/" :advanced-options true :private-key-id 1 :schema-filters-type "all" @@ -89,20 +88,27 @@ :private-key-creator-id 3 :user "SNOWFLAKE_DEVELOPER" :private-key-created-at "2024-01-05T19:10:30.861839Z" - :alternative-hostname ""}] + :host ""}] (testing "Database name is quoted if quoting is requested (#27856)" (are [quote? result] (=? {:db result} (let [details (assoc details :quote-db-name quote?)] (sql-jdbc.conn/connection-details->spec :snowflake details))) true "\"v3_sample-dataset\"" false "v3_sample-dataset")) - (testing "Subname is replaced if alternative is provided (#22133)" - (are [alternative? result] (=? {:subname result} - (let [details (assoc details :alternative-hostname alternative?)] - (sql-jdbc.conn/connection-details->spec :snowflake details))) - nil "//ls10467.us-east-2.aws.snowflakecomputing.com/" - "" "//ls10467.us-east-2.aws.snowflakecomputing.com/" - "snowflake.example.com" "//snowflake.example.com/")))) + (testing "Subname is replaced if hostname is provided (#22133)" + (are [use-account-name alternative-host expected-subname] (=? expected-subname + (:subname (let [details (-> details + (assoc :host alternative-host) + (assoc :use-account-name use-account-name))] + (sql-jdbc.conn/connection-details->spec :snowflake details)))) + false nil "//ls10467.us-east-2.aws.snowflakecomputing.com/" + false "" "//ls10467.us-east-2.aws.snowflakecomputing.com/" + false "snowflake.example.com/" "//snowflake.example.com/" + false "snowflake.example.com" "//snowflake.example.com/" + true nil "//ls10467.us-east-2.aws.snowflakecomputing.com/" + true "" "//ls10467.us-east-2.aws.snowflakecomputing.com/" + true "snowflake.example.com/" "//ls10467.us-east-2.aws.snowflakecomputing.com/" + true "snowflake.example.com" "//ls10467.us-east-2.aws.snowflakecomputing.com/")))) (deftest ^:parallel ddl-statements-test (testing "make sure we didn't break the code that is used to generate DDL statements when we add new test datasets" From 295c342888ee1ee1b061f97506d1d6468658e62c Mon Sep 17 00:00:00 2001 From: Victor Vieux Date: Thu, 14 Mar 2024 16:24:08 -0700 Subject: [PATCH 3/6] Update modules/drivers/snowflake/src/metabase/driver/snowflake.clj Co-authored-by: metamben <103100869+metamben@users.noreply.github.com> --- modules/drivers/snowflake/src/metabase/driver/snowflake.clj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/drivers/snowflake/src/metabase/driver/snowflake.clj b/modules/drivers/snowflake/src/metabase/driver/snowflake.clj index 4ebda7905fc55..62001151a6c0e 100644 --- a/modules/drivers/snowflake/src/metabase/driver/snowflake.clj +++ b/modules/drivers/snowflake/src/metabase/driver/snowflake.clj @@ -132,7 +132,7 @@ (-> (merge {:classname "net.snowflake.client.jdbc.SnowflakeDriver" :subprotocol "snowflake" ;; see https://github.com/metabase/metabase/issues/22133 - :subname (let [base-url (if (and (not use-account-name) (string? host) (not (empty? host))) + :subname (let [base-url (if (and (not use-account-name) (string? host) (not (str/blank? host))) (if-not (= (last host) \/) (str host "/") host) From 1b60173c7e39b1bac7659f74bf1c3e632e85b16f Mon Sep 17 00:00:00 2001 From: Victor Vieux Date: Thu, 14 Mar 2024 16:24:22 -0700 Subject: [PATCH 4/6] Update modules/drivers/snowflake/src/metabase/driver/snowflake.clj Co-authored-by: metamben <103100869+metamben@users.noreply.github.com> --- modules/drivers/snowflake/src/metabase/driver/snowflake.clj | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/modules/drivers/snowflake/src/metabase/driver/snowflake.clj b/modules/drivers/snowflake/src/metabase/driver/snowflake.clj index 62001151a6c0e..cafba69a95f76 100644 --- a/modules/drivers/snowflake/src/metabase/driver/snowflake.clj +++ b/modules/drivers/snowflake/src/metabase/driver/snowflake.clj @@ -133,9 +133,8 @@ :subprotocol "snowflake" ;; see https://github.com/metabase/metabase/issues/22133 :subname (let [base-url (if (and (not use-account-name) (string? host) (not (str/blank? host))) - (if-not (= (last host) \/) - (str host "/") - host) + (cond-> host + (not= (last host) \/) (str "/")) (str account ".snowflakecomputing.com/"))] (str "//" base-url )) :client_metadata_request_use_connection_ctx true From 52be655291b55d03b1fa3942d536f4f1e381eab6 Mon Sep 17 00:00:00 2001 From: Victor Vieux Date: Thu, 14 Mar 2024 16:24:33 -0700 Subject: [PATCH 5/6] Update modules/drivers/snowflake/test/metabase/driver/snowflake_test.clj Co-authored-by: metamben <103100869+metamben@users.noreply.github.com> --- .../drivers/snowflake/test/metabase/driver/snowflake_test.clj | 1 + 1 file changed, 1 insertion(+) diff --git a/modules/drivers/snowflake/test/metabase/driver/snowflake_test.clj b/modules/drivers/snowflake/test/metabase/driver/snowflake_test.clj index 48e8a084e46ce..0be78ac561dc9 100644 --- a/modules/drivers/snowflake/test/metabase/driver/snowflake_test.clj +++ b/modules/drivers/snowflake/test/metabase/driver/snowflake_test.clj @@ -103,6 +103,7 @@ (sql-jdbc.conn/connection-details->spec :snowflake details)))) false nil "//ls10467.us-east-2.aws.snowflakecomputing.com/" false "" "//ls10467.us-east-2.aws.snowflakecomputing.com/" + false " " "//ls10467.us-east-2.aws.snowflakecomputing.com/" false "snowflake.example.com/" "//snowflake.example.com/" false "snowflake.example.com" "//snowflake.example.com/" true nil "//ls10467.us-east-2.aws.snowflakecomputing.com/" From 8cacb06c74f85ab34cb2f2e484428ed4b75ae9fc Mon Sep 17 00:00:00 2001 From: Victor Vieux Date: Thu, 14 Mar 2024 16:52:07 -0700 Subject: [PATCH 6/6] opt-in --- .../DatabaseHostameSectionField.styled.tsx} | 0 .../DatabaseHostameSectionField.tsx} | 10 +++++----- .../index.ts | 2 +- frontend/src/metabase/databases/constants.tsx | 6 +++--- .../snowflake/resources/metabase-plugin.yaml | 8 ++++---- .../src/metabase/driver/snowflake.clj | 4 ++-- .../test/metabase/driver/snowflake_test.clj | 18 +++++++++--------- 7 files changed, 24 insertions(+), 24 deletions(-) rename frontend/src/metabase/databases/components/{DatabaseAccountNameSectionField/DatabaseAccountNameSectionField.styled.tsx => DatabaseHostnameSectionField/DatabaseHostameSectionField.styled.tsx} (100%) rename frontend/src/metabase/databases/components/{DatabaseAccountNameSectionField/DatabaseAccountNameSectionField.tsx => DatabaseHostnameSectionField/DatabaseHostameSectionField.tsx} (68%) rename frontend/src/metabase/databases/components/{DatabaseAccountNameSectionField => DatabaseHostnameSectionField}/index.ts (54%) diff --git a/frontend/src/metabase/databases/components/DatabaseAccountNameSectionField/DatabaseAccountNameSectionField.styled.tsx b/frontend/src/metabase/databases/components/DatabaseHostnameSectionField/DatabaseHostameSectionField.styled.tsx similarity index 100% rename from frontend/src/metabase/databases/components/DatabaseAccountNameSectionField/DatabaseAccountNameSectionField.styled.tsx rename to frontend/src/metabase/databases/components/DatabaseHostnameSectionField/DatabaseHostameSectionField.styled.tsx diff --git a/frontend/src/metabase/databases/components/DatabaseAccountNameSectionField/DatabaseAccountNameSectionField.tsx b/frontend/src/metabase/databases/components/DatabaseHostnameSectionField/DatabaseHostameSectionField.tsx similarity index 68% rename from frontend/src/metabase/databases/components/DatabaseAccountNameSectionField/DatabaseAccountNameSectionField.tsx rename to frontend/src/metabase/databases/components/DatabaseHostnameSectionField/DatabaseHostameSectionField.tsx index 4a1935a972018..9b5a1b131541d 100644 --- a/frontend/src/metabase/databases/components/DatabaseAccountNameSectionField/DatabaseAccountNameSectionField.tsx +++ b/frontend/src/metabase/databases/components/DatabaseHostnameSectionField/DatabaseHostameSectionField.tsx @@ -4,15 +4,15 @@ import { t } from "ttag"; import FormField from "metabase/core/components/FormField"; -import { SectionButton } from "./DatabaseAccountNameSectionField.styled"; +import { SectionButton } from "./DatabaseHostameSectionField.styled"; -export interface DatabaseAccountNameSectionFieldProps { +export interface DatabaseHostnameSectionFieldProps { name: string; } -const DatabaseAccountNameSectionField = ({ +const DatabaseHostnameSectionField = ({ name, -}: DatabaseAccountNameSectionFieldProps): JSX.Element => { +}: DatabaseHostnameSectionFieldProps): JSX.Element => { const [{ value }, , { setValue }] = useField(name); const handleClick = useCallback(() => { @@ -29,4 +29,4 @@ const DatabaseAccountNameSectionField = ({ }; // eslint-disable-next-line import/no-default-export -- deprecated usage -export default DatabaseAccountNameSectionField; +export default DatabaseHostnameSectionField; diff --git a/frontend/src/metabase/databases/components/DatabaseAccountNameSectionField/index.ts b/frontend/src/metabase/databases/components/DatabaseHostnameSectionField/index.ts similarity index 54% rename from frontend/src/metabase/databases/components/DatabaseAccountNameSectionField/index.ts rename to frontend/src/metabase/databases/components/DatabaseHostnameSectionField/index.ts index 960c79c3177e6..d926659b9e2aa 100644 --- a/frontend/src/metabase/databases/components/DatabaseAccountNameSectionField/index.ts +++ b/frontend/src/metabase/databases/components/DatabaseHostnameSectionField/index.ts @@ -1,2 +1,2 @@ // eslint-disable-next-line import/no-default-export -- deprecated usage -export { default } from "./DatabaseAccountNameSectionField"; +export { default } from "./DatabaseHostameSectionField"; diff --git a/frontend/src/metabase/databases/constants.tsx b/frontend/src/metabase/databases/constants.tsx index 265597973d4b4..8082e466b07a5 100644 --- a/frontend/src/metabase/databases/constants.tsx +++ b/frontend/src/metabase/databases/constants.tsx @@ -6,7 +6,7 @@ import DatabaseAuthCodeDescription from "./components/DatabaseAuthCodeDescriptio import DatabaseCacheScheduleField from "./components/DatabaseCacheScheduleField"; import DatabaseClientIdDescription from "./components/DatabaseClientIdDescription"; import DatabaseConnectionSectionField from "./components/DatabaseConnectionSectionField"; -import DatabaseAccountNameSectionField from "./components/DatabaseAccountNameSectionField"; +import DatabaseHostnameSectionField from "./components/DatabaseHostnameSectionField"; import DatabaseScheduleToggleField from "./components/DatabaseScheduleToggleField"; import DatabaseSshDescription from "./components/DatabaseSshDescription"; import DatabaseSslKeyDescription from "./components/DatabaseSslKeyDescription"; @@ -105,8 +105,8 @@ export const FIELD_OVERRIDES: Record = { "use-conn-uri": { type: DatabaseConnectionSectionField, }, - "use-account-name": { - type: DatabaseAccountNameSectionField, + "use-hostname": { + type: DatabaseHostnameSectionField, }, "let-user-control-scheduling": { type: DatabaseScheduleToggleField, diff --git a/modules/drivers/snowflake/resources/metabase-plugin.yaml b/modules/drivers/snowflake/resources/metabase-plugin.yaml index b8521a63e8f54..02daf68d2bdb4 100644 --- a/modules/drivers/snowflake/resources/metabase-plugin.yaml +++ b/modules/drivers/snowflake/resources/metabase-plugin.yaml @@ -8,20 +8,20 @@ driver: lazy-load: true parent: sql-jdbc connection-properties: - - name: use-account-name + - name: use-hostname type: section - default: true + default: false - merge: - host - visible-if: - use-account-name: false + use-hostname: true - name: account display-name: Account name helper-text: Enter your Account ID with the region that your Snowflake cluster is running on e.g. "xxxxxxxx.us-east-2.aws". Some regions don't have this suffix. placeholder: xxxxxxxx.us-east-2.aws required: true visible-if: - use-account-name: true + use-hostname: false - user - password - name: private-key diff --git a/modules/drivers/snowflake/src/metabase/driver/snowflake.clj b/modules/drivers/snowflake/src/metabase/driver/snowflake.clj index cafba69a95f76..6bd20e190ff13 100644 --- a/modules/drivers/snowflake/src/metabase/driver/snowflake.clj +++ b/modules/drivers/snowflake/src/metabase/driver/snowflake.clj @@ -123,7 +123,7 @@ (str "\"" (str/replace raw-name "\"" "\"\"") "\""))) (defmethod sql-jdbc.conn/connection-details->spec :snowflake - [_ {:keys [account additional-options host use-account-name], :as details}] + [_ {:keys [account additional-options host use-hostname], :as details}] (when (get "week_start" (sql-jdbc.common/additional-options->map additional-options :url)) (log/warn (trs "You should not set WEEK_START in Snowflake connection options; this might lead to incorrect results. Set the Start of Week Setting instead."))) (let [upcase-not-nil (fn [s] (when s (u/upper-case-en s)))] @@ -132,7 +132,7 @@ (-> (merge {:classname "net.snowflake.client.jdbc.SnowflakeDriver" :subprotocol "snowflake" ;; see https://github.com/metabase/metabase/issues/22133 - :subname (let [base-url (if (and (not use-account-name) (string? host) (not (str/blank? host))) + :subname (let [base-url (if (and use-hostname (string? host) (not (str/blank? host))) (cond-> host (not= (last host) \/) (str "/")) (str account ".snowflakecomputing.com/"))] diff --git a/modules/drivers/snowflake/test/metabase/driver/snowflake_test.clj b/modules/drivers/snowflake/test/metabase/driver/snowflake_test.clj index 0be78ac561dc9..ad1fe53acc535 100644 --- a/modules/drivers/snowflake/test/metabase/driver/snowflake_test.clj +++ b/modules/drivers/snowflake/test/metabase/driver/snowflake_test.clj @@ -96,20 +96,20 @@ true "\"v3_sample-dataset\"" false "v3_sample-dataset")) (testing "Subname is replaced if hostname is provided (#22133)" - (are [use-account-name alternative-host expected-subname] (=? expected-subname + (are [use-hostname alternative-host expected-subname] (=? expected-subname (:subname (let [details (-> details (assoc :host alternative-host) - (assoc :use-account-name use-account-name))] + (assoc :use-hostname use-hostname))] (sql-jdbc.conn/connection-details->spec :snowflake details)))) - false nil "//ls10467.us-east-2.aws.snowflakecomputing.com/" - false "" "//ls10467.us-east-2.aws.snowflakecomputing.com/" - false " " "//ls10467.us-east-2.aws.snowflakecomputing.com/" - false "snowflake.example.com/" "//snowflake.example.com/" - false "snowflake.example.com" "//snowflake.example.com/" true nil "//ls10467.us-east-2.aws.snowflakecomputing.com/" true "" "//ls10467.us-east-2.aws.snowflakecomputing.com/" - true "snowflake.example.com/" "//ls10467.us-east-2.aws.snowflakecomputing.com/" - true "snowflake.example.com" "//ls10467.us-east-2.aws.snowflakecomputing.com/")))) + true " " "//ls10467.us-east-2.aws.snowflakecomputing.com/" + true "snowflake.example.com/" "//snowflake.example.com/" + true "snowflake.example.com" "//snowflake.example.com/" + false nil "//ls10467.us-east-2.aws.snowflakecomputing.com/" + false "" "//ls10467.us-east-2.aws.snowflakecomputing.com/" + false "snowflake.example.com/" "//ls10467.us-east-2.aws.snowflakecomputing.com/" + false "snowflake.example.com" "//ls10467.us-east-2.aws.snowflakecomputing.com/")))) (deftest ^:parallel ddl-statements-test (testing "make sure we didn't break the code that is used to generate DDL statements when we add new test datasets"