Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def run_presto_query(presto_sql, hostname, port=8081):
if presto_sql != "" and presto_sql is not None:
cursor = pyhive.presto.connect(hostname, port).cursor()
cursor.execute(presto_sql)
else:
raise Exception("Invalid Presto query: '%s'" % presto_sql)
return cursor.fetchall()
def run_presto_query(presto_sql, hostname, port=8081):
if presto_sql != "" and presto_sql is not None:
cursor = pyhive.presto.connect(hostname, port).cursor()
cursor.execute(presto_sql)
else:
raise Exception("Invalid Presto query: '%s'" % presto_sql)
return cursor.fetchall()
def run_query(self, query, user):
connection = presto.connect(
host=self.configuration.get("host", ""),
port=self.configuration.get("port", 8080),
protocol=self.configuration.get("protocol", "http"),
username=self.configuration.get("username", "redash"),
password=(self.configuration.get("password") or None),
catalog=self.configuration.get("catalog", "hive"),
schema=self.configuration.get("schema", "default"),
)
cursor = connection.cursor()
try:
cursor.execute(query)
column_tuples = [
(i[0], PRESTO_TYPES_MAPPING.get(i[1], None)) for i in cursor.description
]
def run_query(self, query, user):
connection = presto.connect(
host=self.configuration.get('host', ''),
port=self.configuration.get('port', 8080),
username=self.configuration.get('username', 'redash'),
catalog=self.configuration.get('catalog', 'hive'),
schema=self.configuration.get('schema', 'default'))
cursor = connection.cursor()
try:
cursor.execute(query)
column_tuples = [(i[0], PRESTO_TYPES_MAPPING.get(i[1], None)) for i in cursor.description]
columns = self.fetch_columns(column_tuples)
rows = [dict(zip(([c['name'] for c in columns]), r)) for i, r in enumerate(cursor.fetchall())]
data = {'columns': columns, 'rows': rows}
json_data = json.dumps(data, cls=JSONEncoder)