Skip to content

Commit 412c829

Browse files
New Query Runner: Arango query runner (#5124)
Co-authored-by: Hugo Gresse <[email protected]>
1 parent e2bad61 commit 412c829

File tree

4 files changed

+92
-1
lines changed

4 files changed

+92
-1
lines changed
96.9 KB
Loading

redash/query_runner/arango.py

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
import logging
2+
3+
from redash.query_runner import *
4+
from redash.utils import json_dumps
5+
6+
logger = logging.getLogger(__name__)
7+
8+
try:
9+
from arango import ArangoClient
10+
11+
enabled = True
12+
except ImportError:
13+
enabled = False
14+
15+
16+
_TYPE_MAPPINGS = {
17+
"boolean": TYPE_BOOLEAN,
18+
"number": TYPE_FLOAT,
19+
"string": TYPE_STRING,
20+
"array": TYPE_STRING,
21+
"object": TYPE_STRING,
22+
}
23+
24+
25+
class Arango(BaseQueryRunner):
26+
noop_query = "RETURN {'id': 1}"
27+
28+
@classmethod
29+
def name(cls):
30+
return "ArangoDB"
31+
32+
@classmethod
33+
def configuration_schema(cls):
34+
return {
35+
"type": "object",
36+
"properties": {
37+
"user": {"type": "string"},
38+
"password": {"type": "string"},
39+
"host": {"type": "string", "default": "127.0.0.1"},
40+
"port": {"type": "number", "default": 8529},
41+
"dbname": {"type": "string", "title": "Database Name"},
42+
"timeout": {"type": "number", "default": 0.0, "title": "AQL Timeout in seconds (0 = no timeout)"},
43+
},
44+
"order": ["host", "port", "user", "password", "dbname"],
45+
"required": ["host", "user", "password", "dbname"],
46+
"secret": ["password"],
47+
}
48+
49+
@classmethod
50+
def enabled(cls):
51+
try:
52+
import arango
53+
except ImportError:
54+
return False
55+
56+
return True
57+
58+
@classmethod
59+
def type(cls):
60+
return "arangodb"
61+
62+
def run_query(self, query, user):
63+
client = ArangoClient(hosts='{}:{}'.format(self.configuration["host"],
64+
self.configuration.get("port", 8529)))
65+
db = client.db(self.configuration["dbname"],
66+
username=self.configuration["user"],
67+
password=self.configuration["password"])
68+
69+
try:
70+
cursor = db.aql.execute(query, max_runtime=self.configuration.get("timeout", 0.0))
71+
result = [i for i in cursor]
72+
column_tuples = [
73+
(i, TYPE_STRING) for i in result[0].keys()
74+
]
75+
columns = self.fetch_columns(column_tuples)
76+
data = {
77+
"columns": columns,
78+
"rows": result,
79+
}
80+
81+
json_data = json_dumps(data, ignore_nan=True)
82+
error = None
83+
except Exception:
84+
raise
85+
86+
return json_data, error
87+
88+
89+
register(Arango)

redash/settings/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,8 @@ def email_server_is_configured():
387387
"redash.query_runner.sparql_endpoint",
388388
"redash.query_runner.excel",
389389
"redash.query_runner.csv",
390-
"redash.query_runner.firebolt"
390+
"redash.query_runner.firebolt",
391+
"redash.query_runner.arango"
391392
]
392393

393394
enabled_query_runners = array_from_string(

requirements_all_ds.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,4 @@ xlrd==2.0.1
4242
openpyxl==3.0.7
4343
firebolt-sdk
4444
pandas==1.3.4
45+
python-arango==6.1.0

0 commit comments

Comments
 (0)