Skip to content

Commit

Permalink
Merge pull request #10 from buserbrasil/metabase/v0.50.0
Browse files Browse the repository at this point in the history
upgrade metabase to v0.50.3
  • Loading branch information
schumannc authored Jun 14, 2024
2 parents 5b72c42 + cb639aa commit 3013de0
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 37 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ COPY . /driver
RUN apt-get update && apt-get install -y --no-install-recommends curl && \
rm -rf /var/lib/apt/lists/*

ARG METABASE_VERSION="v0.49.15"
ARG METABASE_VERSION="v0.50.3"

RUN curl -Lo - https://github.com/metabase/metabase/archive/refs/tags/${METABASE_VERSION}.tar.gz | tar -xz && mv metabase-* /metabase

Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

ROOT_DIR:=$(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))
METABASE_VERSION=v0.49.15
METABASE_VERSION=v0.50.3

build:
@echo "build"
Expand Down
2 changes: 1 addition & 1 deletion deps.edn
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@
:aliases
{:dev
{:extra-deps
{com.github.metabase/metabase {:git/tag "v0.49.15", :git/sha "77a08d7710d79f82c52c1d1e3cd3d4edc10bd8406d93eec9988d12158334ecc3"}}}}}
{com.github.metabase/metabase {:git/tag "v0.50.3", :git/sha "def3903f275276e339f2ed99bb37fd2f85652b62f8f3be50cb0e708f1eeaffbc"}}}}}
78 changes: 44 additions & 34 deletions src/metabase/driver/databricks_sql.clj
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
[metabase.driver.sql.query-processor :as sql.qp]
[metabase.driver.sql.util :as sql.u]
[metabase.driver.sql.util.unprepare :as unprepare]
[metabase.mbql.util :as mbql.u]
[metabase.legacy-mbql.util :as mbql.u]
[metabase.query-processor.util :as qp.util])
(:import
(java.sql Connection ResultSet)))
Expand Down Expand Up @@ -80,46 +80,54 @@
[_driver]
2)

(defn- dash-to-underscore [s]
(when s
(str/replace s #"-" "_")))

;; workaround for SPARK-9686 Spark Thrift server doesn't return correct JDBC metadata
(defmethod driver/describe-database :databricks-sql
[_ database]
[driver database]
{:tables
(with-open [conn (jdbc/get-connection (sql-jdbc.conn/db->pooled-connection-spec database))]
(set
(for [{:keys [database tablename], table-namespace :namespace} (jdbc/query {:connection conn} ["show tables"])]
{:name tablename
:schema (or (not-empty database)
(not-empty table-namespace))})))})
(sql-jdbc.execute/do-with-connection-with-options
driver
database
nil
(fn [^Connection conn]
(set
(for [{:keys [database tablename tab_name], table-namespace :namespace} (jdbc/query {:connection conn} ["show tables"])]
{:name (or tablename tab_name) ; column name differs depending on server (SparkSQL, hive, Impala)
:schema (or (not-empty database)
(not-empty table-namespace))}))))})

;; Hive describe table result has commented rows to distinguish partitions
(defn- valid-describe-table-row? [{:keys [col_name data_type]}]
(every? (every-pred (complement str/blank?)
(complement #(str/starts-with? % "#")))
[col_name data_type]))

(defn- dash-to-underscore [s]
(when s
(str/replace s #"-" "_")))

;; workaround for SPARK-9686 Spark Thrift server doesn't return correct JDBC metadata
(defmethod driver/describe-table :databricks-sql
[driver database {table-name :name, schema :schema}]
{:name table-name
:schema schema
:fields
(with-open [conn (jdbc/get-connection (sql-jdbc.conn/db->pooled-connection-spec database))]
(let [results (jdbc/query {:connection conn} [(format
"describe %s"
(sql.u/quote-name driver :table
(dash-to-underscore schema)
(dash-to-underscore table-name)))])]
(set
(for [[idx {col-name :col_name, data-type :data_type, :as result}] (m/indexed results)
:while (valid-describe-table-row? result)]
{:name col-name
:database-type data-type
:base-type (sql-jdbc.sync/database-type->base-type :databricks-sql (keyword data-type))
:database-position idx}))))})
(sql-jdbc.execute/do-with-connection-with-options
driver
database
nil
(fn [^Connection conn]
(let [results (jdbc/query {:connection conn} [(format
"describe %s"
(sql.u/quote-name driver :table
(dash-to-underscore schema)
(dash-to-underscore table-name)))])]
(set
(for [[idx {col-name :col_name, data-type :data_type, :as result}] (m/indexed results)
:when (valid-describe-table-row? result)]
{:name col-name
:database-type data-type
:base-type (sql-jdbc.sync/database-type->base-type :hive-like (keyword data-type))
:database-position idx})))))})

(def ^:dynamic *param-splice-style*
"How we should splice params into SQL (i.e. 'unprepare' the SQL). Either `:friendly` (the default) or `:paranoid`.
Expand All @@ -146,15 +154,16 @@
;; 2. SparkSQL doesn't support session timezones (at least our driver doesn't support it)
;; 3. SparkSQL doesn't support making connections read-only
;; 4. SparkSQL doesn't support setting the default result set holdability
(defmethod sql-jdbc.execute/connection-with-timezone :databricks-sql
[driver database _timezone-id]
(let [conn (.getConnection (sql-jdbc.execute/datasource-with-diagnostic-info! driver database))]
(try
(.setTransactionIsolation conn Connection/TRANSACTION_READ_UNCOMMITTED)
conn
(catch Throwable e
(.close conn)
(throw e)))))
(defmethod sql-jdbc.execute/do-with-connection-with-options :databricks-sql
[driver db-or-id-or-spec options f]
(sql-jdbc.execute/do-with-resolved-connection
driver
db-or-id-or-spec
options
(fn [^Connection conn]
(when-not (sql-jdbc.execute/recursive-connection?)
(.setTransactionIsolation conn Connection/TRANSACTION_READ_UNCOMMITTED))
(f conn))))

;; 1. SparkSQL doesn't support setting holdability type to `CLOSE_CURSORS_AT_COMMIT`
(defmethod sql-jdbc.execute/prepared-statement :databricks-sql
Expand All @@ -180,6 +189,7 @@
:native-parameters true
:nested-queries true
:standard-deviation-aggregations true
:metadata/key-constraints false
:test/jvm-timezone-setting false}]
(defmethod driver/database-supports? [:databricks-sql feature] [_driver _feature _db] supported?))

Expand Down

0 comments on commit 3013de0

Please sign in to comment.