Skip to content
Snippets Groups Projects
Unverified Commit 1f9b6206 authored by github-automation-metabase's avatar github-automation-metabase Committed by GitHub
Browse files

fix: add UserAgentEntry to databricks connection (#49361) (#49432)


* fix: add UserAgentEntry to databricks connection

Fixes: #49350

* Add test

* Fix formatting

Co-authored-by: default avatarCase Nelson <case@metabase.com>
parent ceeb71df
No related branches found
No related tags found
No related merge requests found
......@@ -3,6 +3,7 @@
[clojure.string :as str]
[honey.sql :as sql]
[java-time.api :as t]
[metabase.config :as config]
[metabase.driver :as driver]
[metabase.driver.hive-like :as driver.hive-like]
[metabase.driver.sql-jdbc.connection :as sql-jdbc.conn]
......@@ -205,6 +206,7 @@
:HttpPath http-path
:uid "token"
:pwd token
:UserAgentEntry (format "Metabase/%s" (:tag config/mb-version-info))
:UseNativeQuery 1}
;; Following is used just for tests. See the [[metabase.driver.sql-jdbc.connection-test/perturb-db-details]]
;; and test that is using the function.
......
(ns ^:mb/driver-tests metabase.driver.databricks-test
(:require
[clojure.java.jdbc :as jdbc]
[clojure.test :refer :all]
[java-time.api :as t]
[metabase.config :as config]
[metabase.driver :as driver]
[metabase.driver.databricks :as databricks]
[metabase.driver.sql-jdbc.connection :as sql-jdbc.conn]
......@@ -242,6 +244,17 @@
(deftest additional-options-test
(mt/test-driver
:databricks
(testing "Connections with UserAgentEntry"
(sql-jdbc.conn/with-connection-spec-for-testing-connection
[spec [:databricks (:details (mt/db))]]
(is (= [{:a 1}] (jdbc/query spec ["select 1 as a"]))))
(with-redefs [config/mb-version-info {:tag "invalid agent"}]
(sql-jdbc.conn/with-connection-spec-for-testing-connection
[spec [:databricks (:details (mt/db))]]
(is (thrown-with-msg?
Exception
#"Incorrect format for User-Agent entry"
(jdbc/query spec ["select 1 as a"]))))))
(testing "Additional options are added to :subname key of generated spec"
(is (re-find #";IgnoreTransactions=0$"
(->> {:http-path "p/a/t/h",
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment