The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:
TypeScript analyticsbibusiness-intelligencebusinessintelligenceclojuredashboarddatadata-analysisdata-visualizationdatabasemetabasemysqlpostgrespostgresqlreportingslacksql-editorvisualization
External PR: db-tables as multimethod to enable driver implementation (#78842)
Riley Thompsonbed8a61829e1
diff --git a/docs/developers-guide/driver-changelog.md b/docs/developers-guide/driver-changelog.mdindex e3b2a6e621e..34a9d618713 100644--- a/docs/developers-guide/driver-changelog.md+++ b/docs/developers-guide/driver-changelog.md@@ -61,11 +61,14 @@ title: Driver interface changelog- `metabase.driver/compile-create-index` `[driver schema table structured]` -- compiles a `:standalone` index intothe DDL statement(s) that create it.-- `metabase.driver-api.core/aggregation-name` is now deprecated, as it operates on legacy MBQL; use- `metabase.driver-api.core/mbql-5-aggregation-name` going forward.+ - `metabase.driver.sql-jdbc.sync.interface/db-tables` is now a multimethod for retrieving JDBC metadata+ tables. SQL JDBC drivers can override this method to customize which database objects are discovered during sync.-- The method signature for `metabase.driver/substitute-native-parameters-in-stage-method`, introduced in 63, has- changed; please update your implementations accordingly.+ - `metabase.driver-api.core/aggregation-name` is now deprecated, as it operates on legacy MBQL; use+ `metabase.driver-api.core/mbql-5-aggregation-name` going forward.++ - The method signature for `metabase.driver/substitute-native-parameters-in-stage-method`, introduced in 63, has+ changed; please update your implementations accordingly.## Metabase 0.63.0diff --git a/modules/drivers/snowflake/src/metabase/driver/snowflake.clj b/modules/drivers/snowflake/src/metabase/driver/snowflake.cljindex fe78f21bc82..d76659d7ea8 100644--- a/modules/drivers/snowflake/src/metabase/driver/snowflake.clj+++ b/modules/drivers/snowflake/src/metabase/driver/snowflake.clj@@ -822,7 +822,7 @@;; See [[metabase.driver.snowflake/describe-database-default-schema-test]] and;; https://metaboat.slack.com/archives/C04DN5VRQM6/p1706220295862639?thread_ts=1706156558.940489&cid=C04DN5VRQM6;; for more info.- (vec (sql-jdbc.describe-database/db-tables driver (.getMetaData conn) "%" db-name)))}))))))+ (vec (sql-jdbc.sync.interface/db-tables driver (.getMetaData conn) "%" db-name)))}))))))(defn- fallback-fields-metadata"When JDBC DatabaseMetaData.getColumns() fails (e.g. due to unsupported column types like UUID),diff --git a/src/metabase/driver/sql_jdbc/sync/describe_database.clj b/src/metabase/driver/sql_jdbc/sync/describe_database.cljindex 05eeb5ad38d..25ac8da4152 100644--- a/src/metabase/driver/sql_jdbc/sync/describe_database.clj+++ b/src/metabase/driver/sql_jdbc/sync/describe_database.clj@@ -145,9 +145,7 @@remarks)):type ttype})))))-(defn db-tables- "Fetch a JDBC Metadata ResultSet of tables in the DB, optionally limited to ones belonging to a given- schema. Returns a reducible sequence of results."+(defmethod sql-jdbc.sync.interface/db-tables :sql-jdbc[driver ^DatabaseMetaData metadata ^String schema-or-nil ^String db-name-or-nil];; seems like some JDBC drivers like Snowflake are dumb and still narrow the search results by the current session;; schema if you pass in `nil` for `schema-or-nil`, which means not to narrow results at all... For Snowflake, I fixed@@ -158,6 +156,11 @@["TABLE" "PARTITIONED TABLE" "VIEW" "FOREIGN TABLE" "MATERIALIZED VIEW""EXTERNAL TABLE" "DYNAMIC_TABLE"]))+(defn db-tables+ "Compatibility wrapper for drivers calling `sql-jdbc.describe-database/db-tables` directly."+ [driver ^DatabaseMetaData metadata ^String schema-or-nil ^String db-name-or-nil]+ (sql-jdbc.sync.interface/db-tables driver metadata schema-or-nil db-name-or-nil))+(defn- build-privilege-map"Build a nested map of schema -> table -> set of permissions from current user table privileges.There are 2 permissions:@@ -260,7 +263,7 @@(-> table(dissoc :type)(assoc :is_writable (privilege-fn table :write))))))- (db-tables driver metadata schema db-name-or-nil))))+ (sql-jdbc.sync.interface/db-tables driver metadata schema db-name-or-nil))))syncable-schemas)))(defmethod sql-jdbc.sync.interface/active-tables :sql-jdbc@@ -284,7 +287,7 @@(-> table(dissoc :type)(assoc :is_writable (privilege-fn table :write))))))- (db-tables driver (.getMetaData conn) nil db-name-or-nil))))+ (sql-jdbc.sync.interface/db-tables driver (.getMetaData conn) nil db-name-or-nil))))(defn db-or-id-or-spec->database"Get database instance from `db-or-id-or-spec`."diff --git a/src/metabase/driver/sql_jdbc/sync/interface.clj b/src/metabase/driver/sql_jdbc/sync/interface.cljindex b26ad2b8be1..d42a8940735 100644--- a/src/metabase/driver/sql_jdbc/sync/interface.clj+++ b/src/metabase/driver/sql_jdbc/sync/interface.clj@@ -148,6 +148,14 @@driver/dispatch-on-initialized-driver:hierarchy #'driver/hierarchy)+(defmulti db-tables+ "Fetch a JDBC Metadata ResultSet of tables in the DB, optionally limited to ones belonging to a given+ schema. Returns a reducible sequence of results."+ {:added "0.64.0"+ :arglists '([driver metadata schema-or-nil db-name-or-nil])}+ driver/dispatch-on-initialized-driver+ :hierarchy #'driver/hierarchy)+;; used for compatibility with drivers only implementing alter-columns-sql;; remove when alter-columns-sql is deleted (v0.57+)#_{:clj-kondo/ignore [:deprecated-var]}