Merge pull request #918 from getredash/query_runners_improvements

Several improvements to query runners:
This commit is contained in:
Arik Fraimovich
2016-03-13 15:44:04 +02:00
5 changed files with 43 additions and 8 deletions

View File

@@ -13,7 +13,7 @@ from redash.handlers.base import BaseResource, get_object_or_404
class DataSourceTypeListAPI(BaseResource):
@require_admin
def get(self):
return [q.to_dict() for q in query_runners.values()]
return [q.to_dict() for q in sorted(query_runners.values(), key=lambda q: q.name())]
api.add_org_resource(DataSourceTypeListAPI, '/api/data_sources/types', endpoint='data_source_types')

View File

@@ -55,6 +55,10 @@ class SqlServer(BaseSQLQueryRunner):
def enabled(cls):
return enabled
@classmethod
def name(cls):
return "Microsoft SQL Server"
@classmethod
def type(cls):
return "mssql"

View File

@@ -28,16 +28,16 @@ types_map = {
}
def _wait(conn):
def _wait(conn, timeout=None):
while 1:
try:
state = conn.poll()
if state == psycopg2.extensions.POLL_OK:
break
elif state == psycopg2.extensions.POLL_WRITE:
select.select([], [conn.fileno()], [])
select.select([], [conn.fileno()], [], timeout)
elif state == psycopg2.extensions.POLL_READ:
select.select([conn.fileno()], [], [])
select.select([conn.fileno()], [], [], timeout)
else:
raise psycopg2.OperationalError("poll() returned %s" % state)
except select.error:
@@ -115,7 +115,7 @@ class PostgreSQL(BaseSQLQueryRunner):
def run_query(self, query):
connection = psycopg2.connect(self.connection_string, async=True)
_wait(connection)
_wait(connection, timeout=10)
cursor = connection.cursor()
@@ -152,4 +152,37 @@ class PostgreSQL(BaseSQLQueryRunner):
return json_data, error
class Redshift(PostgreSQL):
@classmethod
def type(cls):
return "redshift"
@classmethod
def configuration_schema(cls):
return {
"type": "object",
"properties": {
"user": {
"type": "string"
},
"password": {
"type": "string"
},
"host": {
"type": "string"
},
"port": {
"type": "number"
},
"dbname": {
"type": "string",
"title": "Database Name"
}
},
"required": ["dbname", "user", "password", "host", "port"],
"secret": ["password"]
}
register(PostgreSQL)
register(Redshift)

View File

@@ -131,7 +131,6 @@ default_query_runners = [
'redash.query_runner.google_spreadsheets',
'redash.query_runner.graphite',
'redash.query_runner.mongodb',
'redash.query_runner.mql',
'redash.query_runner.mysql',
'redash.query_runner.pg',
'redash.query_runner.url',
@@ -142,7 +141,6 @@ default_query_runners = [
'redash.query_runner.impala_ds',
'redash.query_runner.vertica',
'redash.query_runner.treasuredata',
'redash.query_runner.oracle',
'redash.query_runner.sqlite',
'redash.query_runner.mssql',
]

View File

@@ -5,7 +5,7 @@ influxdb==2.7.1
MySQL-python==1.2.5
oauth2client==1.2
pyhive==0.1.5
pymongo==2.7.2
pymongo==3.2.1
pyOpenSSL==0.14
vertica-python==0.5.1
td-client==0.4.1