Skip to content

The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:

Handle nulls in arrays (#62756)

Riley Thompsonef1273e815cb
diff --git a/src/metabase/driver/sql_jdbc/execute.clj b/src/metabase/driver/sql_jdbc/execute.clj
index 96f239f9d03..57e5494177b 100644
--- a/src/metabase/driver/sql_jdbc/execute.clj
+++ b/src/metabase/driver/sql_jdbc/execute.clj
@@ -623,7 +623,7 @@
(defn- arrays->vectors
[obj]
- (if (.isArray (class obj))
+ (if (some-> obj class .isArray)
(mapv arrays->vectors obj)
obj))
diff --git a/test/metabase/driver/postgres_test.clj b/test/metabase/driver/postgres_test.clj
index 0061fd86863..9ea687fefeb 100644
--- a/test/metabase/driver/postgres_test.clj
+++ b/test/metabase/driver/postgres_test.clj
@@ -1806,3 +1806,19 @@
(finally
(jdbc/execute! conn "DROP SCHEMA IF EXISTS sync_test_schema CASCADE")
(jdbc/execute! conn "DROP USER IF EXISTS sync_writable_test_user"))))))))
+
+(deftest ^:parallel null-array-query-test
+ (testing "queries with nulls in arrays should be returned in a readable format"
+ (mt/test-driver :postgres
+ (is (= [[[nil]
+ [nil nil]
+ [1 nil 3]
+ [[nil]]
+ [[nil] [nil]]
+ [[1 nil] [nil 2]]]]
+ (->> (mt/native-query {:query "select array[null], array[null, null],
+ array[1, null, 3], array[array[null]],
+ array[array[null], array[null]],
+ array[array[1, null], array[null, 2]]"})
+ mt/process-query
+ mt/rows))))))