Skip to content
Snippets Groups Projects
Unverified Commit d943eac3 authored by Howon Lee's avatar Howon Lee Committed by GitHub
Browse files

Fully specify identifier in Postgres JSON describe nested field column query (#22448) (#22523)


Previously identifier isn't fully specified (with schema and table) in nested field column description in syncing. Now it is!

Co-authored-by: default avatarNoah Moss <32746338+noahmoss@users.noreply.github.com>

Co-authored-by: default avatarNoah Moss <32746338+noahmoss@users.noreply.github.com>
parent 8f5e9f9f
No related branches found
No related tags found
No related merge requests found
......@@ -330,16 +330,16 @@
"Default implementation of `describe-nested-field-columns` for SQL JDBC drivers. Goes and queries the table if there are JSON columns for the nested contents."
[driver spec table]
(with-open [conn (jdbc/get-connection spec)]
(let [_map-inner (fn [f xs] (map #(into {}
(for [[k v] %]
[k (f v)])) xs))
table-fields (describe-table-fields driver conn table)
json-fields (filter #(= (:semantic-type %) :type/SerializedJSON) table-fields)]
(let [table-identifier-info [(:schema table) (:name table)]
table-fields (describe-table-fields driver conn table)
json-fields (filter #(= (:semantic-type %) :type/SerializedJSON) table-fields)]
(if (nil? (seq json-fields))
#{}
(let [json-field-names (mapv (comp keyword :name) json-fields)
(let [json-field-names (mapv #(apply hx/identifier :field (into table-identifier-info [(:name %)])) json-fields)
table-identifier (apply hx/identifier :field table-identifier-info)
sql-args (hsql/format {:select json-field-names
:from [(keyword (:name table))]
:from [table-identifier]
:limit nested-field-sample-limit} {:quoting :ansi})
query (jdbc/reducible-query spec sql-args)
field-types (transduce describe-json-xform describe-json-rf query)
......
......@@ -379,6 +379,28 @@
database
{:name "describe_json_table"}))))))))
(deftest describe-nested-field-columns-identifier-test
(mt/test-driver :postgres
(testing "sync goes and runs with identifier if there is a schema other than default public one"
(drop-if-exists-and-create-db! "describe-json-with-schema-test")
(let [details (mt/dbdef->connection-details :postgres :db {:database-name "describe-json-with-schema-test"})
spec (sql-jdbc.conn/connection-details->spec :postgres details)]
(jdbc/with-db-connection [conn (sql-jdbc.conn/connection-details->spec :postgres details)]
(jdbc/execute! spec [(str "CREATE SCHEMA bobdobbs;"
"CREATE TABLE bobdobbs.describe_json_table (trivial_json JSONB NOT NULL);"
"INSERT INTO bobdobbs.describe_json_table (trivial_json) VALUES ('{\"a\": 1}');")]))
(mt/with-temp Database [database {:engine :postgres, :details details}]
(is (= #{{:name "trivial_json → a",
:database-type "integer",
:base-type :type/Integer,
:database-position 0,
:visibility-type :normal,
:nfc-path [:trivial_json "a"]}}
(sql-jdbc.sync/describe-nested-field-columns
:postgres
database
{:schema "bobdobbs" :name "describe_json_table"}))))))))
(deftest describe-big-nested-field-columns-test
(mt/test-driver :postgres
(testing "blank out if huge. blank out instead of silently limiting"
......
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