Skip to content
Snippets Groups Projects
Unverified Commit f2455669 authored by Cam Saul's avatar Cam Saul
Browse files

Revert code accidentally removed in #5794

parent 4c41b0a6
Branches
Tags
No related merge requests found
......@@ -50,6 +50,7 @@
(.getId profile))))
(defn- describe-database [database]
;; Include a `_metabase_metadata` table in the list of Tables so we can provide custom metadata. See below.
{:tables (set (for [table-id (cons "_metabase_metadata" (profile-ids database))]
{:name table-id
:schema nil}))})
......@@ -115,6 +116,39 @@
:fields (describe-columns database)})
;;; ----------------------------------------------- _metabase_metadata -----------------------------------------------
;; The following is provided so we can specify custom display_names for Tables and Fields since there's not yet a way
;; to do it directly in `describe-database` or `describe-table`. Just fake results for the Table in `table-rows-seq`
;; (rows in `_metabase_metadata` are just property -> value, e.g. `<table>.display_name` -> `<display-name>`.)
(defn- property+profile->display-name
"Format a table name for a GA property and GA profile"
[^Webproperty property, ^Profile profile]
(let [property-name (s/replace (.getName property) #"^https?://" "")
profile-name (s/replace (.getName profile) #"^https?://" "")]
;; don't include the profile if it's the same as property-name or is the default "All Web Site Data"
(if (or (.contains property-name profile-name)
(= profile-name "All Web Site Data"))
property-name
(str property-name " (" profile-name ")"))))
(defn- table-rows-seq [database table]
;; this method is only supposed to be called for _metabase_metadata, make sure that's the case
{:pre [(= (:name table) "_metabase_metadata")]}
;; now build a giant sequence of all the things we want to set
(apply concat
;; set display_name for all the tables
(for [[^Webproperty property, ^Profile profile] (properties+profiles database)]
(cons {:keypath (str (.getId profile) ".display_name")
:value (property+profile->display-name property profile)}
;; set display_name and description for each column for this table
(apply concat (for [^Column column (columns database)]
[{:keypath (str (.getId profile) \. (.getId column) ".display_name")
:value (column-attribute column :uiName)}
{:keypath (str (.getId profile) \. (.getId column) ".description")
:value (column-attribute column :description)}]))))))
;;; -------------------------------------------------- can-connect? --------------------------------------------------
......@@ -217,7 +251,8 @@
:required true}])
:execute-query (u/drop-first-arg (partial qp/execute-query do-query))
:process-query-in-context (u/drop-first-arg process-query-in-context)
:mbql->native (u/drop-first-arg qp/mbql->native)}))
:mbql->native (u/drop-first-arg qp/mbql->native)
:table-rows-seq (u/drop-first-arg table-rows-seq)}))
(defn -init-driver
"Register the Google Analytics driver"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment