diff --git a/src/metabase/driver/crate.clj b/src/metabase/driver/crate.clj index 89ee9509f849094429f8e1bab4869631aa72c4f2..55082daf911962089bfc19d9a3e481c7ff75aa36 100644 --- a/src/metabase/driver/crate.clj +++ b/src/metabase/driver/crate.clj @@ -60,17 +60,17 @@ (defn- describe-table-fields [database, driver, {:keys [schema name]}] (let [columns (jdbc/query - (sql/db->jdbc-connection-spec database) - [(format "select column_name, data_type as type_name + (sql/db->jdbc-connection-spec database) + [(format "select column_name, data_type as type_name from information_schema.columns where table_name like '%s' and table_schema like '%s' and data_type != 'object_array'" name schema)])] ; clojure jdbc can't handle fields of type "object_array" atm (set (for [{:keys [column_name type_name]} columns] - (merge {:name column_name - :custom {:column-type type_name} - :base-type (or (column->base-type (keyword type_name)) - (do (log/warn (format "Don't know how to map column type '%s' to a Field base_type, falling back to :type/*." type_name)) - :type/*))}))))) + {:name column_name + :custom {:column-type type_name} + :base-type (or (column->base-type (keyword type_name)) + (do (log/warn (format "Don't know how to map column type '%s' to a Field base_type, falling back to :type/*." type_name)) + :type/*))})))) (defn- add-table-pks [^DatabaseMetaData metadata, table] diff --git a/src/metabase/util/honeysql_extensions.clj b/src/metabase/util/honeysql_extensions.clj index fa95415f6346e958dc0fdda2cb6318c0423d0fb8..70bfe6de28eaa0af1de1aae991c085fa5f54f685 100644 --- a/src/metabase/util/honeysql_extensions.clj +++ b/src/metabase/util/honeysql_extensions.clj @@ -21,8 +21,10 @@ (intern 'honeysql.format 'quote-fns (assoc quote-fns :h2 (comp s/upper-case ansi-quote-fn)))) + +;; `:crate` quote style that correctly quotes nested column identifiers (defn- str-insert - "Insert c in string s at index i." + "Insert C in string S at index I." [s c i] (str c (subs s 0 i) c (subs s i))) @@ -33,10 +35,10 @@ (str \" s \") (str-insert s "\"" idx)))) -;; `:crate` quote style that correctly quotes nested column identifiers -(let [quote-fns @(resolve 'honeysql.format/quote-fns)] - (->> (assoc quote-fns :crate crate-column-identifier) - (intern 'honeysql.format 'quote-fns))) +(let [quote-fns @(resolve 'honeysql.format/quote-fns)] + (intern 'honeysql.format 'quote-fns + (assoc quote-fns :crate crate-column-identifier))) + ;; register the `extract` function with HoneySQL ;; (hsql/format (hsql/call :extract :a :b)) -> "extract(a from b)"