Skip to content

Commit

Permalink
Merge pull request #1059 from getredash/fix_dql
Browse files Browse the repository at this point in the history
Fix: DynamoDB having issues when setting host
  • Loading branch information
arikfr committed May 18, 2016
2 parents b5a4a6b + 31aee1b commit 701035f
Showing 1 changed file with 23 additions and 15 deletions.
38 changes: 23 additions & 15 deletions redash/query_runner/dynamodb_sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,32 +39,28 @@ def configuration_schema(cls):
"properties": {
"region": {
"type": "string",
"default": "us-west-1"
"default": "us-east-1"
},
"host": {
"type": "string",
"default": "127.0.0.1"
"default": "Use for non standard endpoints."
},
"port": {
"type": "number",
"default": 8000
"default": 80
},
"access_key": {
"type": "string",
"default": "anything"

},
"secret_key": {
"type": "string",
"default": "anything"

},
"is_secure": {
"type": "boolean",
"default": False,
}
},
"required": ["host"],
"required": ["access_key", "secret_key"],
"secret": ["secret_key"]
}

Expand All @@ -83,11 +79,22 @@ def name(cls):
def __init__(self, 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):

try:
engine = FragmentEngine()
engine.connect(**self.configuration.to_dict())
engine, _ = self._connect()

for table in engine.describe_all():
schema[table.name] = {'name': table.name, 'columns': table.attrs.keys()}
Expand All @@ -97,11 +104,9 @@ def _get_tables(self, schema):
raise sys.exc_info()[1], None, sys.exc_info()[2]

def run_query(self, query):

connection = None
try:
engine = FragmentEngine()
connection = engine.connect(**self.configuration.to_dict())
engine, connection = self._connect()

res_dict = engine.execute(query if str(query).endswith(';') else str(query)+';')

Expand All @@ -121,12 +126,15 @@ def run_query(self, query):
data = {'columns': columns, 'rows': rows}
json_data = json.dumps(data, cls=JSONEncoder)
error = None
except (SyntaxError, RuntimeError) as e:
error = e.message
json_data = None
except KeyboardInterrupt:
connection.cancel()
if connection:
connection.cancel()
error = "Query cancelled by user."
json_data = None
except Exception as e:
logging.exception(e)
raise sys.exc_info()[1], None, sys.exc_info()[2]

return json_data, error
Expand Down

0 comments on commit 701035f

Please sign in to comment.