Skip to content
Snippets Groups Projects
Commit c3229371 authored by Sameer Al-Sakran's avatar Sameer Al-Sakran Committed by GitHub
Browse files

Merge pull request #3875 from metabase/crate-master

Crate master
parents 7056208f d83a14f6
No related branches found
No related tags found
No related merge requests found
......@@ -10,7 +10,7 @@ Metabase is the easy, open source way for everyone in your company to ask questi
[![NPM Dependencies Status](https://david-dm.org/metabase/metabase.svg)](https://david-dm.org/metabase/metabase)
[![Issue Stats](http://issuestats.com/github/metabase/metabase/badge/pr)](http://issuestats.com/github/metabase/metabase)
[![Issue Stats](http://issuestats.com/github/metabase/metabase/badge/issue)](http://issuestats.com/github/metabase/metabase)
# Features
- 5 minute [setup](http://www.metabase.com/docs/latest/setting-up-metabase) (We're not kidding)
- Let anyone on your team [ask questions](http://www.metabase.com/docs/latest/users-guide/03-asking-questions) without knowing SQL
......@@ -34,7 +34,7 @@ For more information check out [metabase.com](http://www.metabase.com)
- Google BigQuery
- SQLite
- H2
- Crate
- CrateDB
- Oracle
- Vertica
......
......@@ -64,6 +64,7 @@ install-crate() {
sudo apt-get install -y crate
# ulimit setting refused Crate service to start on CircleCI container - so comment it
sudo sed -i '/MAX_LOCKED_MEMORY/s/^/#/' /etc/init/crate.conf
echo "psql.port: 5200" | sudo tee -a /etc/crate/crate.yml
sudo service crate restart
}
......
......@@ -14,12 +14,12 @@ Now you’ll see a list of your databases. To connect another database to Metaba
* [Google BigQuery](databases/bigquery.md)
* H2
* MongoDB (version 3.0 or higher)
* MySQL (version 4.1 or higher)
* MySQL (version 4.1 or higher, as well as MariaDB)
* Postgres
* SQLite
* SQL Server
* Druid
* Crate
* Driud
* [CrateDB](databases/cratedb.md)
* [Oracle](databases/oracle.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:
* Amazon Redshift
* BigQuery
* Crate (version 0.55 or higher)
* CrateDB (version 0.57 or higher)
* Druid
* H2
* MongoDB (version 3.0 or higher)
......@@ -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?
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
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)
......@@ -68,8 +68,7 @@
[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 !!!
[postgresql "9.3-1102.jdbc41"] ; Postgres driver
[io.crate/crate-jdbc "1.13.1"] ; Crate JDBC driver
[io.crate/crate-client "0.56.0"] ; Crate Java client (used by Crate JDBC)
[io.crate/crate-jdbc "2.1.1"] ; Crate JDBC driver
[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-json "0.4.0"] ; Ring middleware for reading/writing JSON automatically
......
......@@ -3,8 +3,7 @@
[clojure.set :as set]
[honeysql.core :as hsql]
[metabase.driver :as driver]
(metabase.driver.crate [query-processor :as qp]
[util :as crate-util])
[metabase.driver.crate.util :as crate-util]
[metabase.driver.generic-sql :as sql]
[metabase.util :as u]))
......@@ -44,16 +43,15 @@
(defn- crate-spec
[{:keys [hosts]
:or {hosts "//localhost:4300"}
:as opts}]
(merge {:classname "io.crate.client.jdbc.CrateDriver" ; must be in classpath
:subprotocol "crate"
:subname (str hosts)}
:subname (str "//" hosts "/")}
(dissoc opts :hosts)))
(defn- can-connect? [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]
(hsql/call :char_length field-key))
......@@ -70,14 +68,13 @@
:date-interval crate-util/date-interval
:details-fields (constantly [{:name "hosts"
:display-name "Hosts"
:default "//localhost:4300"}])
:default "localhost:5432"}])
:features (comp (u/rpartial set/difference #{:foreign-keys}) sql/features)})
sql/ISQLDriver
(merge (sql/ISQLDriverDefaultsMixin)
{:connection-details->spec (u/drop-first-arg crate-spec)
:column->base-type (u/drop-first-arg column->base-type)
:string-length-fn (u/drop-first-arg string-length-fn)
:apply-filter qp/apply-filter
:date crate-util/date
:unix-timestamp->timestamp crate-util/unix-timestamp->timestamp
: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 @@
(insert! rows))))
(def ^:private database->connection-details
(constantly {:host "localhost"
:port 4300}))
(constantly {:hosts "localhost:5200"}))
(extend CrateDriver
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