Skip to content
Snippets Groups Projects
Commit 6ad38af6 authored by Michael Beer's avatar Michael Beer Committed by Christian Haudum
Browse files

code cleanup

parent 280745a6
No related branches found
No related tags found
No related merge requests found
......@@ -10,7 +10,8 @@
(:import (clojure.lang Named)))
(defn- column->base-type
"Map of Crate column types -> Field base types"
"Map of Crate column types -> Field base types
Crate data types -> https://crate.io/docs/reference/sql/data_types.html"
[_ column-type]
({:integer :IntegerField
:string :TextField
......
(ns metabase.driver.crate.native
(:require [clojure.java.jdbc :as jdbc]
[metabase.driver :as driver]
[metabase.models.database :refer [Database]]
[metabase.db :refer [sel]]
[metabase.driver.generic-sql :as sql]
[clojure.tools.logging :as log]
[metabase.util :as u]))
(defn- value->base-type
"Attempt to match a value we get back from the DB with the corresponding base-type`."
[v]
(driver/class->base-type (type v)))
[metabase.util :as u]
[metabase.driver.generic-sql.native :as n]))
(defn process-and-run
"Process and run a native (raw SQL) QUERY."
......@@ -20,15 +15,6 @@
(jdbc/with-db-connection [t-conn db-conn]
(let [^java.sql.Connection jdbc-connection (:connection t-conn)]
(try
;; Set the timezone if applicable
(when-let [timezone (driver/report-timezone)]
(when (and (seq timezone)
(contains? (driver/features driver) :set-timezone))
(log/debug (u/format-color 'green "%s" (sql/set-timezone-sql driver)))
(try (jdbc/db-do-prepared t-conn (sql/set-timezone-sql driver) [timezone])
(catch Throwable e
(log/error (u/format-color 'red "Failed to set timezone: %s" (.getMessage e)))))))
;; Now run the query itself
(log/debug (u/format-color 'green "%s" sql))
(let [[columns & [first-row :as rows]] (jdbc/query t-conn sql, :as-arrays? true)]
......@@ -36,7 +22,7 @@
:columns columns
:cols (for [[column first-value] (partition 2 (interleave columns first-row))]
{:name column
:base_type (value->base-type first-value)})})))))
:base_type (n/value->base-type first-value)})})))))
(catch java.sql.SQLException e
(let [^String message (or (->> (.getMessage e) ; error message comes back like 'Column "ZID" not found; SQL statement: ... [error-code]' sometimes
(re-find #"^(.*);") ; the user already knows the SQL, and error code is meaningless
......
......@@ -4,8 +4,7 @@
[korma.core :as k]
[clj-time.core :as t]
[clj-time.coerce :as c]
[clj-time.format :as f]
[metabase.util :as u])
[clj-time.format :as f])
(:import (java.sql Timestamp)))
(defn unix-timestamp->timestamp [_ expr seconds-or-milliseconds]
......
......@@ -8,7 +8,7 @@
[metabase.models.database :refer [Database]]
[metabase.util :as u]))
(defn- value->base-type
(defn value->base-type
"Attempt to match a value we get back from the DB with the corresponding base-type`."
[v]
(driver/class->base-type (type v)))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment