Skip to content
This repository has been archived by the owner on Apr 11, 2024. It is now read-only.

Commit

Permalink
Upgrade Metabase up to v1.44.6. Fixed some build issues. Allowed SQL …
Browse files Browse the repository at this point in the history
…modify queries (does't returns any results).
  • Loading branch information
AlexR2D2 committed Nov 23, 2022
1 parent 8a9c6b4 commit 86e805e
Show file tree
Hide file tree
Showing 8 changed files with 74 additions and 41 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@
duckdb-driver.iml
.lein-repl-history
.cpcache
.clj-kondo
.lsp
9 changes: 5 additions & 4 deletions README.md
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,11 @@ This will build a file called `target/duckdb.metabase-driver.jar`; copy this to

### Build in dev container using Visual Studio Code

Install the VSCode 'Remote - Containers' extension. Start the Docker engine. Open the project in the VSCode. You will be asked if you want to re-open the project in a dev container. Reopen the project in the container. Wait until it started. Start new VSCode terminal and build plugin the same way:
Install the VSCode 'Remote - Containers' extension. Start the Docker engine. Open the project in the VSCode. You will be asked if you want to re-open the project in a dev container. Reopen the project in the container. Wait until it started. Start new VSCode terminal and build plugin:

1. modify :paths in deps.edn, make them absolute
2. `vscode ➜ /workspaces/metabase_duckdb_driver (main ✗) $ clojure -X:build :project-dir "\"$(pwd)\""`
1. check the versions you need of Metabase and DuckDB in the `build_docker_image.sh` and `deps.edn`
2. modify :paths in deps.edn, make them absolute
3. `vscode ➜ /workspaces/metabase_duckdb_driver (main ✗) $ clojure -X:build :project-dir "\"$(pwd)\""`

## Configuring

Expand All @@ -102,7 +103,7 @@ ORDER BY averageRating * numVotes DESC
Unfortunately, DuckDB plugin does't work in the default Alpine based Metabase docker container due to some glibc problems. But it works in the Ubuntu based Metabase docker image. There is Ubuntu based image build script in the docker folder of this project. So, please, run Docker daemon in you host and:

```bash
./build_image.sh
./build_docker_image.sh
```

After a while, it will build the `metabase_duckdb` Ubuntu based image of Metabase with DuckDB plugin. Just run container of this image exposing 3000 port.
31 changes: 31 additions & 0 deletions build_docker_image.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# DOC
#
# This script builds docker image of Metabase based on Ubuntu. DuckDB pluging is included.
#
# The docker/metabase/bin/docker folder contains a bit modified files from the Metabase source.
#

# Common
CUR=$PWD

# Metabase
MB_VSN=v1.44.6
MB_GIT_URL=https://github.com/metabase/metabase.git
MB_SRC_FOLDER=docker/metabase/source
MB_IMAGE_NAME=ubuntu_metabase
MB_DUCKDB_IMAGE_NAME=metabase_duckdb

# Clone metabase source code
if [ ! -d "$MB_SRC_FOLDER/$MB_VSN" ] ; then
git clone --depth 1 --branch $MB_VSN $MB_GIT_URL $MB_SRC_FOLDER/$MB_VSN
fi

# Copy ubuntu based docker files/sh script into source code of Metabase
yes | cp -rf docker/metabase/Dockerfile $MB_SRC_FOLDER/$MB_VSN
yes | cp -rf docker/metabase/bin/docker/* $MB_SRC_FOLDER/$MB_VSN/bin/docker

# Build the Metabase Ubuntu based docker image
cd $MB_SRC_FOLDER/$MB_VSN && docker build -t $MB_IMAGE_NAME -f Dockerfile . && cd $CUR

# Build the Metabase image with DuckDB plugin
docker build -t $MB_DUCKDB_IMAGE_NAME -f docker/Dockerfile .
24 changes: 0 additions & 24 deletions build_image.sh

This file was deleted.

8 changes: 4 additions & 4 deletions deps.edn
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
; replace also the version in metabase-plugin.yaml
metabase/metabase-core {
:git/url "https://github.com/metabase/metabase.git"
:git/tag "v1.44.3"
:git/sha "7d50282"
:git/tag "v1.44.6"
:git/sha "5c6ae21"
}
metabase/build-drivers {
:git/url "https://github.com/metabase/metabase.git"
:git/tag "v1.44.3"
:git/sha "7d50282"
:git/tag "v1.44.6"
:git/sha "5c6ae21"
:deps/root "bin/build-drivers"
}
org.duckdb/duckdb_jdbc {:mvn/version "0.5.1"}
Expand Down
12 changes: 8 additions & 4 deletions docker/metabase/bin/docker/Dockerfile
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,16 @@ RUN apt-get update && \
/opt/java/openjdk/bin/keytool -noprompt -import -trustcacerts -alias azure-cert -file /app/certs/DigiCertGlobalRootG2.crt.pem -keystore /etc/ssl/certs/java/cacerts -keypass changeit -storepass changeit && \
mkdir -p /plugins && chmod a+rwx /plugins

# add Metabase script and uberjar
COPY --from=builder /home/circleci/target/uberjar/metabase.jar /app/
COPY bin/docker/run_metabase.sh /app/
# add Metabase jar & add our run script to the image
COPY ./metabase.jar ./run_metabase.sh /app/

# expose our default runtime port
EXPOSE 3000

# if you have an H2 database that you want to initialize the new Metabase
# instance with, mount it in the container as a volume that will match the
# pattern /app/initial*.db:
# $ docker run ... -v $PWD/metabase.db.mv.db:/app/initial.db.mv.db ...

# run it
ENTRYPOINT ["/app/run_metabase.sh"]
ENTRYPOINT ["/app/run_metabase.sh"]
2 changes: 1 addition & 1 deletion resources/metabase-plugin.yaml
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
info:
name: Metabase DuckDB Driver
version: 1.0.0-SNAPSHOT-0.1.2
version: 1.0.0-SNAPSHOT-0.1.3
description: Allows Metabase to connect to DuckDB databases.
contact-info:
name: Alexander Golubov
Expand Down
27 changes: 23 additions & 4 deletions src/metabase/driver/duckdb.clj
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
[metabase.driver.sql-jdbc.connection :as sql-jdbc.conn]
[metabase.driver.sql-jdbc.execute :as sql-jdbc.execute]
[metabase.driver.sql-jdbc.sync :as sql-jdbc.sync])
(:import [java.sql ResultSet Types]))
(:import [java.sql Statement ResultSet ResultSetMetaData Types]))

(driver/register! :duckdb, :parent :sql-jdbc)

Expand All @@ -14,9 +14,8 @@
(let [conn_details (merge
{:classname "org.duckdb.DuckDBDriver"
:subprotocol "duckdb"
:subname (or database_file "")
:read_only true}
(dissoc details :database_file))]
:subname (or database_file "")}
(dissoc details :database_file :port :engine))]
conn_details))

(def ^:private database-type->base-type
Expand Down Expand Up @@ -82,6 +81,26 @@
(fn []
(let [sqlTime (.getObject rs i java.sql.Time)] (.toLocalTime sqlTime))))

(defn empty-rs [_] ;
(reify
ResultSet
(getMetaData [_]
(reify
ResultSetMetaData
(getColumnCount [_] 1)
(getColumnLabel [_ _idx] "WARNING")
(getColumnTypeName [_ _] "CHAR")
(getColumnType [_ _] Types/CHAR)))
(next [_] false)
(close [_])))

;; override native execute-statement! to make queries that does't returns ResultSet
(defmethod sql-jdbc.execute/execute-statement! :sql-jdbc
[_driver ^Statement stmt ^String sql]
(if (.execute stmt sql)
(.getResultSet stmt)
(empty-rs [])))

(defmethod driver/describe-database :duckdb
[_ database]
{:tables
Expand Down

0 comments on commit 86e805e

Please sign in to comment.