Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for JDBC, added sample jar for Hazelcast #6854

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 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,9 @@ RUN apt-get update && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*

# The debian package doesn't provide an architecture independent JAVA_HOME
RUN find /usr/lib/jvm/ -maxdepth 1 -type d | grep java-17 | xargs -I{} ln -s {} /usr/lib/jvm/java_home
ENV JAVA_HOME=/usr/lib/jvm/java_home

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 +101,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/hazelcast-jdbc.jar
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
77 changes: 77 additions & 0 deletions redash/query_runner/jdbc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
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")

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

if self.configuration.get("user") or self.configuration.get("password"):
driver_args = {
"user": (self.configuration.get("user") or None),
"password": (self.configuration.get("password") or None),
}
else:
driver_args = None

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

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

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
finally:
connection.close()

return data, error


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
Loading