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 89110fc
Show file tree
Hide file tree
Showing 7 changed files with 549 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
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
76 changes: 76 additions & 0 deletions redash/query_runner/jdbc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
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"))

driver_args= { "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)

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/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

0 comments on commit 89110fc

Please sign in to comment.