Skip to content
Snippets Groups Projects
Commit 18e7c3c0 authored by Sameer Al-Sakran's avatar Sameer Al-Sakran
Browse files

Merge branch 'master' of https://github.com/crate/metabase into crate-master

parents ab2357e8 4edea959
No related branches found
No related tags found
No related merge requests found
...@@ -34,7 +34,7 @@ For more information check out [metabase.com](http://www.metabase.com) ...@@ -34,7 +34,7 @@ For more information check out [metabase.com](http://www.metabase.com)
- Google BigQuery - Google BigQuery
- SQLite - SQLite
- H2 - H2
- Crate - CrateDB
- Oracle - Oracle
- Vertica - Vertica
......
...@@ -59,11 +59,13 @@ node-6() { ...@@ -59,11 +59,13 @@ node-6() {
install-crate() { install-crate() {
sudo add-apt-repository ppa:crate/stable -y sudo add-apt-repository ppa:crate/testing -y
sudo apt-get update sudo apt-get update
sudo apt-get install -y crate sudo apt-get install -y crate=0.57.3-1~trusty
# ulimit setting refused Crate service to start on CircleCI container - so comment it # ulimit setting refused Crate service to start on CircleCI container - so comment it
sudo sed -i '/MAX_LOCKED_MEMORY/s/^/#/' /etc/init/crate.conf sudo sed -i '/MAX_LOCKED_MEMORY/s/^/#/' /etc/init/crate.conf
echo "psql.port: 5200" | sudo tee -a /etc/crate/crate.yml
echo "psql.enabled: true" | sudo tee -a /etc/crate/crate.yml
sudo service crate restart sudo service crate restart
} }
......
...@@ -18,8 +18,13 @@ Now you’ll see a list of your databases. To connect another database to Metaba ...@@ -18,8 +18,13 @@ Now you’ll see a list of your databases. To connect another database to Metaba
* Postgres * Postgres
* SQLite * SQLite
* SQL Server * SQL Server
<<<<<<< HEAD
* Druid * Druid
* Crate * Crate
=======
* Driud
* [CrateDB](databases/cratedb.md)
>>>>>>> 4edea959ea604ffafd2f3970dc86bf1c6d8b68af
* [Oracle](databases/oracle.md) * [Oracle](databases/oracle.md)
* [Vertica](databases/vertica.md) * [Vertica](databases/vertica.md)
......
## Working with CrateDB in Metabase
Starting in v0.18.0 Metabase provides a driver for connecting to CrateDB directly and executing queries against any datasets you have. CrateDB uses the PostgreSQL Wire Protocol (since CrateDB v0.57), which makes it easy to use many PostgreSQL compatible tools and libraries directly with CrateDB. Therefore the CrateDB driver for Metabase provides and uses the PostgreSQL driver under the hood to connect to its data source. The below sections provide information on how to get connected to CrateDB.
### Connecting to a CrateDB Dataset
1. Make sure you have CrateDB [installed](https://crate.io/docs/reference/en/latest/installation.html), up and running.
2. Setup a connection by providing a **Name** and a **Host**. CrateDB supports having a connection pool of multiple hosts. This can be achieved by providing a comma-separated list of multiple `<host>:<psql-port>` pairs.
```
host1.example.com:5432,host2.example.com:5432
```
3. Click the `Save` button. Done.
Metabase will now begin inspecting your CrateDB Dataset and finding any tables and fields to build up a sense for the schema. Give it a little bit of time to do its work and then you're all set to start querying.
\ No newline at end of file
...@@ -39,7 +39,7 @@ Metabase currently supports: ...@@ -39,7 +39,7 @@ Metabase currently supports:
* Amazon Redshift * Amazon Redshift
* BigQuery * BigQuery
* Crate (version 0.55 or higher) * CrateDB (version 0.57 or higher)
* Druid * Druid
* H2 * H2
* MongoDB (version 3.0 or higher) * MongoDB (version 3.0 or higher)
...@@ -80,4 +80,4 @@ We are experimenting with offering paid support to a limited number of companies ...@@ -80,4 +80,4 @@ We are experimenting with offering paid support to a limited number of companies
### Can I embed charts or dashboards in another application? ### Can I embed charts or dashboards in another application?
Not yet. We're working on it however, and you should expect it in the near future. (Late summer/early fall 2016). Keep tabs on it at the main [tracking issue](https://github.com/metabase/metabase/issues/1380) Not yet. We're working on it however, and you should expect it in the near future. (Late summer/early fall 2016). Keep tabs on it at the main [tracking issue](https://github.com/metabase/metabase/issues/1380)
\ No newline at end of file
...@@ -68,8 +68,7 @@ ...@@ -68,8 +68,7 @@
[org.yaml/snakeyaml "1.17"] ; YAML parser (required by liquibase) [org.yaml/snakeyaml "1.17"] ; YAML parser (required by liquibase)
[org.xerial/sqlite-jdbc "3.8.11.2"] ; SQLite driver !!! DO NOT UPGRADE THIS UNTIL UPSTREAM BUG IS FIXED -- SEE https://github.com/metabase/metabase/issues/3753 !!! [org.xerial/sqlite-jdbc "3.8.11.2"] ; SQLite driver !!! DO NOT UPGRADE THIS UNTIL UPSTREAM BUG IS FIXED -- SEE https://github.com/metabase/metabase/issues/3753 !!!
[postgresql "9.3-1102.jdbc41"] ; Postgres driver [postgresql "9.3-1102.jdbc41"] ; Postgres driver
[io.crate/crate-jdbc "1.13.1"] ; Crate JDBC driver [io.crate/crate-jdbc "2.1.1"] ; Crate JDBC driver
[io.crate/crate-client "0.56.0"] ; Crate Java client (used by Crate JDBC)
[prismatic/schema "1.1.3"] ; Data schema declaration and validation library [prismatic/schema "1.1.3"] ; Data schema declaration and validation library
[ring/ring-jetty-adapter "1.5.0"] ; Ring adapter using Jetty webserver (used to run a Ring server for unit tests) [ring/ring-jetty-adapter "1.5.0"] ; Ring adapter using Jetty webserver (used to run a Ring server for unit tests)
[ring/ring-json "0.4.0"] ; Ring middleware for reading/writing JSON automatically [ring/ring-json "0.4.0"] ; Ring middleware for reading/writing JSON automatically
......
...@@ -3,8 +3,7 @@ ...@@ -3,8 +3,7 @@
[clojure.set :as set] [clojure.set :as set]
[honeysql.core :as hsql] [honeysql.core :as hsql]
[metabase.driver :as driver] [metabase.driver :as driver]
(metabase.driver.crate [query-processor :as qp] [metabase.driver.crate.util :as crate-util]
[util :as crate-util])
[metabase.driver.generic-sql :as sql] [metabase.driver.generic-sql :as sql]
[metabase.util :as u])) [metabase.util :as u]))
...@@ -44,16 +43,15 @@ ...@@ -44,16 +43,15 @@
(defn- crate-spec (defn- crate-spec
[{:keys [hosts] [{:keys [hosts]
:or {hosts "//localhost:4300"}
:as opts}] :as opts}]
(merge {:classname "io.crate.client.jdbc.CrateDriver" ; must be in classpath (merge {:classname "io.crate.client.jdbc.CrateDriver" ; must be in classpath
:subprotocol "crate" :subprotocol "crate"
:subname (str hosts)} :subname (str "//" hosts "/")}
(dissoc opts :hosts))) (dissoc opts :hosts)))
(defn- can-connect? [details] (defn- can-connect? [details]
(let [connection-spec (crate-spec details)] (let [connection-spec (crate-spec details)]
(= 1 (first (vals (first (jdbc/query connection-spec ["select 1 from sys.cluster"]))))))) (= 1 (first (vals (first (jdbc/query connection-spec ["select 1"])))))))
(defn- string-length-fn [field-key] (defn- string-length-fn [field-key]
(hsql/call :char_length field-key)) (hsql/call :char_length field-key))
...@@ -70,14 +68,13 @@ ...@@ -70,14 +68,13 @@
:date-interval crate-util/date-interval :date-interval crate-util/date-interval
:details-fields (constantly [{:name "hosts" :details-fields (constantly [{:name "hosts"
:display-name "Hosts" :display-name "Hosts"
:default "//localhost:4300"}]) :default "localhost:5432"}])
:features (comp (u/rpartial set/difference #{:foreign-keys}) sql/features)}) :features (comp (u/rpartial set/difference #{:foreign-keys}) sql/features)})
sql/ISQLDriver sql/ISQLDriver
(merge (sql/ISQLDriverDefaultsMixin) (merge (sql/ISQLDriverDefaultsMixin)
{:connection-details->spec (u/drop-first-arg crate-spec) {:connection-details->spec (u/drop-first-arg crate-spec)
:column->base-type (u/drop-first-arg column->base-type) :column->base-type (u/drop-first-arg column->base-type)
:string-length-fn (u/drop-first-arg string-length-fn) :string-length-fn (u/drop-first-arg string-length-fn)
:apply-filter qp/apply-filter
:date crate-util/date :date crate-util/date
:unix-timestamp->timestamp crate-util/unix-timestamp->timestamp :unix-timestamp->timestamp crate-util/unix-timestamp->timestamp
:current-datetime-fn (constantly now)})) :current-datetime-fn (constantly now)}))
......
(ns metabase.driver.crate.query-processor
(:require [honeysql.helpers :as h]
[metabase.driver.generic-sql.query-processor :as qp]
[metabase.query-processor.interface :as i]))
(defn- rewrite-between
"Rewrite [:between <field> <min> <max>] -> [:and [:>= <field> <min>] [:<= <field> <max>]]"
[clause]
(i/strict-map->CompoundFilter {:compound-type :and
:subclauses [(i/strict-map->ComparisonFilter {:filter-type :>=
:field (:field clause)
:value (:min-val clause)})
(i/strict-map->ComparisonFilter {:filter-type :<=
:field (:field clause)
:value (:max-val clause)})]}))
(defn- filter-clause->predicate
"resolve filters recursively"
[{:keys [compound-type filter-type subclause subclauses], :as clause}]
(case compound-type
:and (apply vector :and (map filter-clause->predicate subclauses))
:or (apply vector :or (map filter-clause->predicate subclauses))
:not [:not (filter-clause->predicate subclause)]
nil (qp/filter-clause->predicate (if (= filter-type :between)
(rewrite-between clause)
clause))))
(defn apply-filter
"Apply custom generic SQL filter. This is the place to perform query rewrites."
[_ honeysql-form {clause :filter}]
(h/where honeysql-form (filter-clause->predicate clause)))
...@@ -51,8 +51,7 @@ ...@@ -51,8 +51,7 @@
(insert! rows)))) (insert! rows))))
(def ^:private database->connection-details (def ^:private database->connection-details
(constantly {:host "localhost" (constantly {:hosts "localhost:5200"}))
:port 4300}))
(extend CrateDriver (extend CrateDriver
generic/IGenericSQLDatasetLoader generic/IGenericSQLDatasetLoader
......
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