Skip to content

Commit

Permalink
Added support for JDBC, added sample jar for Hazelcast
Browse files Browse the repository at this point in the history
  • Loading branch information
devops-42 committed Apr 6, 2024
1 parent 15e6583 commit a6104a5
Show file tree
Hide file tree
Showing 11 changed files with 551 additions and 425 deletions.
7 changes: 6 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ RUN apt-get update && \
xmlsec1 \
# Additional packages required for data sources:
libssl-dev \
# for JDBC \
openjdk-17-jdk \
default-libmysqlclient-dev \
freetds-dev \
libsasl2-dev \
Expand All @@ -61,6 +63,7 @@ RUN apt-get update && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*

ENV JAVA_HOME=/usr/lib/jvm/java-17-openjdk-arm64

ARG TARGETPLATFORM
ARG databricks_odbc_driver_url=https://databricks-bi-artifacts.s3.us-east-2.amazonaws.com/simbaspark-drivers/odbc/2.6.26/SimbaSparkODBC-2.6.26.1045-Debian-64bit.zip
Expand Down Expand Up @@ -96,7 +99,9 @@ RUN /etc/poetry/bin/poetry install --only $install_groups $POETRY_OPTIONS

COPY --chown=redash . /app
COPY --from=frontend-builder --chown=redash /frontend/client/dist /app/client/dist
RUN chown redash /app
ADD https://github.com/hazelcast/hazelcast-jdbc/releases/download/v5.4.0-BETA-2/hazelcast-jdbc-5.4.0-BETA-2.jar /jdbc/hazelcast-jdbc.jar

RUN chown redash /app /jdbc/*
USER redash

ENTRYPOINT ["/app/bin/docker-entrypoint"]
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ Redash supports more than 35 SQL and NoSQL [data sources](https://redash.io/help
- InfluxDB
- InfluxDBv2
- IBM Netezza Performance Server
- JDBC
- JIRA (JQL)
- JSON
- Apache Kylin
Expand Down
Binary file added client/app/assets/images/jdbc.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
888 changes: 464 additions & 424 deletions poetry.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ databend-py = "0.4.6"
databend-sqlalchemy = "0.2.4"
google-api-python-client = "1.7.11"
gspread = "5.11.2"
JayDeBeApi = "1.2.3"
impyla = "0.16.0"
influxdb = "5.2.3"
influxdb-client = "1.38.0"
Expand Down
74 changes: 74 additions & 0 deletions redash/query_runner/jdbc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import jaydebeapi as jdbc

from redash.query_runner import (
TYPE_BOOLEAN,
TYPE_INTEGER,
TYPE_STRING,
BaseSQLQueryRunner,
register,
)

TYPES_MAP = {1: TYPE_STRING, 2: TYPE_INTEGER, 3: TYPE_BOOLEAN}


class JDBC(BaseSQLQueryRunner):
noop_query = "SELECT 1"

@classmethod
def type(cls):
return "jdbc"

@classmethod
def name(cls):
return "JDBC"

@classmethod
def configuration_schema(cls):
return {
"type": "object",
"properties": {
"driver": {"type": "string", "title": "Driver class", "default": "com.hazelcast.jdbc.Driver"},
"url": {"type": "string", "default": "hazelcast-headful:5701"},
"properties": {"type": "string", "default": ""},
"user": {"type": "string", "default": "user"},
"password": {"type": "string", "default": "mysupersonicsecret"},
"jars": {"type": "string", "default": "/jdbc/hazelcast-jdbc.jar"},
},
"order": ["driver", "url", "properties", "user", "password", "jars"],
"required": ["driver", "url", "jars"],
}

def run_query(self, query, user):
jdbc_class = self.configuration.get("driver") or None
jars = self.configuration.get("jars") or None
jdbc_url = self.configuration.get("url")

Check warning on line 44 in redash/query_runner/jdbc.py

View check run for this annotation

Codecov / codecov/patch

redash/query_runner/jdbc.py#L42-L44

Added lines #L42 - L44 were not covered by tests

# Add properties (if any)
if self.configuration.get("properties"):
jdbc_url += "/?" + (self.configuration.get("properties"))

Check warning on line 48 in redash/query_runner/jdbc.py

View check run for this annotation

Codecov / codecov/patch

redash/query_runner/jdbc.py#L48

Added line #L48 was not covered by tests

driver_args = {

Check warning on line 50 in redash/query_runner/jdbc.py

View check run for this annotation

Codecov / codecov/patch

redash/query_runner/jdbc.py#L50

Added line #L50 was not covered by tests
"user": (self.configuration.get("user") or None),
"password": (self.configuration.get("password") or None),
}

connection = jdbc.connect(jclassname=jdbc_class, url=jdbc_url, driver_args=driver_args, jars=jars)

Check warning on line 55 in redash/query_runner/jdbc.py

View check run for this annotation

Codecov / codecov/patch

redash/query_runner/jdbc.py#L55

Added line #L55 was not covered by tests

cursor = connection.cursor()
try:
cursor.execute(query)
results = cursor.fetchall()

Check warning on line 60 in redash/query_runner/jdbc.py

View check run for this annotation

Codecov / codecov/patch

redash/query_runner/jdbc.py#L57-L60

Added lines #L57 - L60 were not covered by tests

columns = self.fetch_columns([(i[0], TYPES_MAP.get(i[1], None)) for i in cursor.description])

rows = [dict(zip((column["name"] for column in columns), row)) for row in results]

data = {"columns": columns, "rows": rows}
error = None

Check warning on line 67 in redash/query_runner/jdbc.py

View check run for this annotation

Codecov / codecov/patch

redash/query_runner/jdbc.py#L66-L67

Added lines #L66 - L67 were not covered by tests
finally:
connection.close()

Check warning on line 69 in redash/query_runner/jdbc.py

View check run for this annotation

Codecov / codecov/patch

redash/query_runner/jdbc.py#L69

Added line #L69 was not covered by tests

return data, error

Check warning on line 71 in redash/query_runner/jdbc.py

View check run for this annotation

Codecov / codecov/patch

redash/query_runner/jdbc.py#L71

Added line #L71 was not covered by tests


register(JDBC)
1 change: 1 addition & 0 deletions redash/serializers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
classes we have. This will ensure cleaner code and better
separation of concerns.
"""

from flask_login import current_user
from funcy import project
from rq.job import JobStatus
Expand Down
1 change: 1 addition & 0 deletions redash/settings/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,7 @@ def email_server_is_configured():
"redash.query_runner.oracle",
"redash.query_runner.e6data",
"redash.query_runner.risingwave",
"redash.query_runner.jdbc",
]

enabled_query_runners = array_from_string(
Expand Down
1 change: 1 addition & 0 deletions tests/query_runner/test_athena.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Some test cases around the Glue catalog.
"""

from unittest import TestCase

import botocore
Expand Down
1 change: 1 addition & 0 deletions tests/query_runner/test_json_ds.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Some test cases for JSON api runner
"""

from unittest import TestCase
from urllib.parse import urlencode, urljoin

Expand Down
1 change: 1 addition & 0 deletions tests/query_runner/test_trino.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Some test cases for Trino.
"""

from unittest import TestCase
from unittest.mock import patch

Expand Down

0 comments on commit a6104a5

Please sign in to comment.