Skip to content
Snippets Groups Projects
Commit 25e24b0f authored by Allen Gilliland's avatar Allen Gilliland
Browse files

Merge pull request #2242 from metabase/fix-nullpointer

Fix nullpointer
parents 8493ce7b f350ea1b
No related branches found
No related tags found
No related merge requests found
(ns metabase.driver.mongo
"MongoDB Driver."
(:require [clojure.set :as set]
[clojure.tools.logging :as log]
(monger [collection :as mc]
[command :as cmd]
[conversion :as conv]
......@@ -118,16 +119,19 @@
(defn- describe-table [table]
(with-mongo-connection [^com.mongodb.DB conn (table/database table)]
;; TODO: ideally this would take the LAST set of rows added to the table so we could ensure this data changes on reruns
(let [parsed-rows (->> (mc/find-maps conn (:name table))
(take driver/max-sync-lazy-seq-results)
(reduce
(fn [field-defs row]
(loop [[k & more-keys] (keys row)
fields field-defs]
(if-not k
fields
(recur more-keys (update fields k (partial update-field-attrs (k row)))))))
{}))]
(let [parsed-rows (try
(->> (mc/find-maps conn (:name table))
(take driver/max-sync-lazy-seq-results)
(reduce
(fn [field-defs row]
(loop [[k & more-keys] (keys row)
fields field-defs]
(if-not k
fields
(recur more-keys (update fields k (partial update-field-attrs (k row)))))))
{}))
(catch Throwable t
(log/error (format "Error introspecting collection: %s" (:name table)) t)))]
{:name (:name table)
:fields (set (for [field (keys parsed-rows)]
(describe-table-field field (field parsed-rows))))})))
......
......@@ -365,8 +365,9 @@
(when-let [^java.net.URL url (try (java.net.URL. string)
(catch java.net.MalformedURLException _
nil))]
(and (re-matches #"^https?$" (.getProtocol url)) ; these are both automatically downcased
(re-matches #"^.+\..{2,}$" (.getAuthority url))))))) ; this is the part like 'google.com'. Make sure it contains at least one period and 2+ letter TLD
(when (and (.getProtocol url) (.getAuthority url))
(and (re-matches #"^https?$" (.getProtocol url)) ; these are both automatically downcased
(re-matches #"^.+\..{2,}$" (.getAuthority url)))))))) ; this is the part like 'google.com'. Make sure it contains at least one period and 2+ letter TLD
(def ^:private ^:const host-up-timeout
"Timeout (in ms) for checking if a host is available with `host-up?` and `host-port-up?`."
......
......@@ -113,7 +113,7 @@
(expect false (is-url? "http://metabasecom")) ; no period / TLD
(expect false (is-url? "http://.com")) ; no domain
(expect false (is-url? "http://google.")) ; no TLD
(expect false (is-url? "http:/")) ; nil .getAuthority needs to be handled or NullPointerException
;;; ## tests for RPARTIAL
......
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