Skip to content

Commit 0b86c76

Browse files
hantmacarikfr
andauthored
Fix/databend params (#5937)
* fix: databend params * add databend logo * fix log * fix log * Update redash/query_runner/databend.py Co-authored-by: Arik Fraimovich <[email protected]> --------- Co-authored-by: Arik Fraimovich <[email protected]>
1 parent 35b2430 commit 0b86c76

File tree

3 files changed

+37
-10
lines changed

3 files changed

+37
-10
lines changed
3.23 KB
Loading

redash/query_runner/databend.py

Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ def configuration_schema(cls):
2020
"type": "object",
2121
"properties": {
2222
"host": {"type": "string", "default": "localhost"},
23-
"port": {"type": "int", "default": 8000},
23+
"port": {"type": "string", "default": "8000"},
2424
"username": {"type": "string"},
2525
"password": {"type": "string", "default": ""},
2626
"database": {"type": "string"},
27-
"secure": {"type": "string", "default": False},
27+
"secure": {"type": "boolean", "default": False},
2828
},
2929
"order": ["username", "password", "host", "port", "database"],
3030
"required": ["username", "database"],
@@ -37,7 +37,7 @@ def name(cls):
3737

3838
@classmethod
3939
def type(cls):
40-
return "Databend"
40+
return "databend"
4141

4242
@classmethod
4343
def enabled(cls):
@@ -61,12 +61,12 @@ def _define_column_type(column_type):
6161
return TYPE_STRING
6262

6363
def run_query(self, query, user):
64-
host = (self.configuration.get("host") or "localhost"),
65-
port = (self.configuration.get("port") or 8000),
66-
username = (self.configuration.get("username") or None),
67-
password = (self.configuration.get("password") or None),
68-
database = (self.configuration.get("database") or None),
69-
secure = (self.configuration.get("secure") or False),
64+
host = self.configuration.get("host") or "localhost"
65+
port = self.configuration.get("port") or "8000"
66+
username = self.configuration.get("username") or "root"
67+
password = self.configuration.get("password") or ""
68+
database = self.configuration.get("database") or "default"
69+
secure = self.configuration.get("secure") or False
7070
connection = connector.connect(f"databend://{username}:{password}@{host}:{port}/{database}?secure={secure}")
7171
cursor = connection.cursor()
7272

@@ -87,6 +87,33 @@ def run_query(self, query, user):
8787

8888
return json_data, error
8989

90+
def get_schema(self, get_stats=False):
91+
query = """
92+
SELECT TABLE_SCHEMA,
93+
TABLE_NAME,
94+
COLUMN_NAME
95+
FROM INFORMATION_SCHEMA.COLUMNS
96+
WHERE TABLE_SCHEMA NOT IN ('information_schema', 'system')
97+
"""
98+
99+
results, error = self.run_query(query, None)
100+
101+
if error is not None:
102+
self._handle_run_query_error(error)
103+
104+
schema = {}
105+
results = json_loads(results)
106+
107+
for row in results["rows"]:
108+
table_name = "{}.{}".format(row["table_schema"], row["table_name"])
109+
110+
if table_name not in schema:
111+
schema[table_name] = {"name": table_name, "columns": []}
112+
113+
schema[table_name]["columns"].append(row["column_name"])
114+
115+
return list(schema.values())
116+
90117
def _get_tables(self):
91118
query = """
92119
SELECT TABLE_SCHEMA,

requirements_all_ds.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ cmem-cmempy==21.2.3
4141
xlrd==2.0.1
4242
openpyxl==3.0.7
4343
firebolt-sdk
44-
databend-sqlalchemy
44+
databend-sqlalchemy==0.2.4
4545
pandas==1.3.4
4646
nzpy>=1.15
4747
nzalchemy

0 commit comments

Comments
 (0)