mirror of
https://github.com/getredash/redash.git
synced 2025-12-19 17:37:19 -05:00
Merge pull request #1059 from getredash/fix_dql
Fix: DynamoDB having issues when setting host
This commit is contained in:
@@ -39,32 +39,28 @@ class DynamoDBSQL(BaseSQLQueryRunner):
|
|||||||
"properties": {
|
"properties": {
|
||||||
"region": {
|
"region": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"default": "us-west-1"
|
"default": "us-east-1"
|
||||||
},
|
},
|
||||||
"host": {
|
"host": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"default": "127.0.0.1"
|
"default": "Use for non standard endpoints."
|
||||||
},
|
},
|
||||||
"port": {
|
"port": {
|
||||||
"type": "number",
|
"type": "number",
|
||||||
"default": 8000
|
"default": 80
|
||||||
},
|
},
|
||||||
"access_key": {
|
"access_key": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"default": "anything"
|
|
||||||
|
|
||||||
},
|
},
|
||||||
"secret_key": {
|
"secret_key": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"default": "anything"
|
|
||||||
|
|
||||||
},
|
},
|
||||||
"is_secure": {
|
"is_secure": {
|
||||||
"type": "boolean",
|
"type": "boolean",
|
||||||
"default": False,
|
"default": False,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"required": ["host"],
|
"required": ["access_key", "secret_key"],
|
||||||
"secret": ["secret_key"]
|
"secret": ["secret_key"]
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -83,11 +79,22 @@ class DynamoDBSQL(BaseSQLQueryRunner):
|
|||||||
def __init__(self, configuration):
|
def __init__(self, configuration):
|
||||||
super(DynamoDBSQL, self).__init__(configuration)
|
super(DynamoDBSQL, self).__init__(configuration)
|
||||||
|
|
||||||
|
def _connect(self):
|
||||||
|
engine = FragmentEngine()
|
||||||
|
config = self.configuration.to_dict()
|
||||||
|
|
||||||
|
if not config.get('region'):
|
||||||
|
config['region'] = 'us-east-1'
|
||||||
|
|
||||||
|
if config.get('host') == '':
|
||||||
|
config['host'] = None
|
||||||
|
|
||||||
|
return engine, engine.connect(**config)
|
||||||
|
|
||||||
def _get_tables(self, schema):
|
def _get_tables(self, schema):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
engine = FragmentEngine()
|
engine, _ = self._connect()
|
||||||
engine.connect(**self.configuration.to_dict())
|
|
||||||
|
|
||||||
for table in engine.describe_all():
|
for table in engine.describe_all():
|
||||||
schema[table.name] = {'name': table.name, 'columns': table.attrs.keys()}
|
schema[table.name] = {'name': table.name, 'columns': table.attrs.keys()}
|
||||||
@@ -97,11 +104,9 @@ class DynamoDBSQL(BaseSQLQueryRunner):
|
|||||||
raise sys.exc_info()[1], None, sys.exc_info()[2]
|
raise sys.exc_info()[1], None, sys.exc_info()[2]
|
||||||
|
|
||||||
def run_query(self, query):
|
def run_query(self, query):
|
||||||
|
|
||||||
connection = None
|
connection = None
|
||||||
try:
|
try:
|
||||||
engine = FragmentEngine()
|
engine, connection = self._connect()
|
||||||
connection = engine.connect(**self.configuration.to_dict())
|
|
||||||
|
|
||||||
res_dict = engine.execute(query if str(query).endswith(';') else str(query)+';')
|
res_dict = engine.execute(query if str(query).endswith(';') else str(query)+';')
|
||||||
|
|
||||||
@@ -121,12 +126,15 @@ class DynamoDBSQL(BaseSQLQueryRunner):
|
|||||||
data = {'columns': columns, 'rows': rows}
|
data = {'columns': columns, 'rows': rows}
|
||||||
json_data = json.dumps(data, cls=JSONEncoder)
|
json_data = json.dumps(data, cls=JSONEncoder)
|
||||||
error = None
|
error = None
|
||||||
|
except (SyntaxError, RuntimeError) as e:
|
||||||
|
error = e.message
|
||||||
|
json_data = None
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
connection.cancel()
|
if connection:
|
||||||
|
connection.cancel()
|
||||||
error = "Query cancelled by user."
|
error = "Query cancelled by user."
|
||||||
json_data = None
|
json_data = None
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logging.exception(e)
|
|
||||||
raise sys.exc_info()[1], None, sys.exc_info()[2]
|
raise sys.exc_info()[1], None, sys.exc_info()[2]
|
||||||
|
|
||||||
return json_data, error
|
return json_data, error
|
||||||
|
|||||||
Reference in New Issue
Block a user