Skip to content

Commit

Permalink
review fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Vladislav Denisov committed Nov 23, 2016
1 parent 04198a1 commit 90b8ab5
Showing 1 changed file with 10 additions and 20 deletions.
30 changes: 10 additions & 20 deletions query_runner/clickhouse.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,9 @@
import logging
from redash.query_runner import *
from redash.utils import JSONEncoder
import requests
logger = logging.getLogger(__name__)

try:
import requests
enabled = True
except ImportError as e:
logger.info(str(e))
enabled = False


class ClickHouse(BaseSQLQueryRunner):
noop_query = "SELECT 1"
Expand All @@ -20,21 +14,17 @@ def configuration_schema(cls):
return {
"type": "object",
"properties": {
"url": {
"type": "string",
"default": "http://127.0.0.1:8123"
},
"user": {
"type": "string",
"default": "default"
},
"password": {
"type": "string"
},
"host": {
"type": "string",
"default": "127.0.0.1"
},
"port": {
"type": "number",
"default": 8123
},
"dbname": {
"type": "string",
"title": "Database Name"
Expand Down Expand Up @@ -72,8 +62,7 @@ def _get_tables(self, schema):
return schema.values()

def _send_query(self, data, stream=False):
url = 'http://{host}:{port}'.format(host=self.configuration['host'], port=self.configuration['port'])
r = requests.post(url, data=data, stream=stream, params={
r = requests.post(self.configuration['url'], data=data, stream=stream, params={
'user': self.configuration['user'], 'password': self.configuration['password'],
'database': self.configuration['dbname']
})
Expand Down Expand Up @@ -103,7 +92,7 @@ def _clickhouse_query(self, query):
return {'columns': columns, 'rows': result['data']}

def run_query(self, query, user):
logger.info("Clickhouse is about to execute query: %s", query)
logger.debug("Clickhouse is about to execute query: %s", query)
if query == "":
json_data = None
error = "Query is empty"
Expand All @@ -112,9 +101,10 @@ def run_query(self, query, user):
q = self._clickhouse_query(query)
data = json.dumps(q, cls=JSONEncoder)
error = None
except Exception as exc:
except Exception as e:
data = None
error = str(exc)
logging.exception(e)
error = str(e)
return data, error

register(ClickHouse)

0 comments on commit 90b8ab5

Please sign in to comment.