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

Do trivial identity for passthrough of symbols for nested field column instead...

Do trivial identity for passthrough of symbols for nested field column instead of default processing (#23136)

Should whack both #23026 and #23027.

Previous (default) behavior of the reducible query that gets the limited contents of the JSON to break out the nested field columns is to lowercase identifiers. This is root cause of #23026 and #23027.

But we want the proper case of those identifiers in order to be modifying the query correctly when we query the JSON. So we set the reducible query to just pass through the identifiers instead of default behavior.
parent a73f3faf
No related merge requests found
......@@ -39,7 +39,11 @@
(driver/register! :postgres, :parent :sql-jdbc)
(defmethod driver/database-supports? [:postgres :nested-field-columns] [_ _ database] (get-in database [:details :json-unfolding]))
(defmethod driver/database-supports? [:postgres :nested-field-columns] [_ _ database]
(let [json-setting (get-in database [:details :json-unfolding])
;; If not set at all, default to true, actually
setting-nil? (nil? json-setting)]
(or json-setting setting-nil?)))
;;; +----------------------------------------------------------------------------------------------------------------+
;;; | metabase.driver impls |
......
......@@ -347,11 +347,12 @@
(if (nil? (seq 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)
table-identifier (apply hx/identifier :table table-identifier-info)
quote-type (case driver :postgres :ansi :mysql :mysql)
sql-args (hsql/format {:select json-field-names
:from [table-identifier]
:limit nested-field-sample-limit} {:quoting :ansi})
query (jdbc/reducible-query spec sql-args)
:limit nested-field-sample-limit} :quoting quote-type)
query (jdbc/reducible-query spec sql-args {:identifiers identity})
field-types (transduce describe-json-xform describe-json-rf query)
fields (field-types->fields field-types)]
(if (> (count fields) max-nested-field-columns)
......
......@@ -276,6 +276,15 @@
;;; ----------------------------------------- Tests for exotic column types ------------------------------------------
(deftest json-query-support-test
(let [default-db {:details {}}
json-unfold-db {:details {:json-unfolding true}}
no-json-unfold-db {:details {:json-unfolding false}}]
(testing "JSON database support options behave as they're supposed to"
(is (= true (driver/database-supports? :postgres :nested-field-columns default-db)))
(is (= true (driver/database-supports? :postgres :nested-field-columns json-unfold-db)))
(is (= false (driver/database-supports? :postgres :nested-field-columns no-json-unfold-db))))))
(deftest ^:parallel json-query-test
(let [boop-identifier (hx/with-type-info (hx/identifier :field "boop" "bleh -> meh") {})]
(testing "Transforming MBQL query with JSON in it to postgres query works"
......@@ -404,6 +413,29 @@
database
{:schema "bobdobbs" :name "describe_json_table"}))))))))
(deftest describe-funky-name-table-nested-field-columns-test
(mt/test-driver :postgres
(testing "sync goes and still works with funky schema and table names, including caps and special chars (#23026, #23027)"
(drop-if-exists-and-create-db! "describe-json-funky-names-test")
(let [details (mt/dbdef->connection-details :postgres :db {:database-name "describe-json-funky-names-test"
:json-unfolding true})
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 \"AAAH_#\";"
"CREATE TABLE \"AAAH_#\".\"dESCribe_json_table_%\" (trivial_json JSONB NOT NULL);"
"INSERT INTO \"AAAH_#\".\"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 "AAAH_#" :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