Ejemplo n.º 1
0
 def _execute_presto_raw_sql_query_with_description(self,
                                                    schema,
                                                    sql,
                                                    bind_params=None,
                                                    log_ref=None,
                                                    attempts_left=0):
     """Execute a single presto query and return cur.fetchall and cur.description"""
     try:
         t1 = time.time()
         presto_conn = kpdb.connect(schema=schema)
         presto_cur = presto_conn.cursor()
         presto_cur.execute(sql, bind_params)
         results = presto_cur.fetchall()
         description = presto_cur.description
         t2 = time.time()
         if log_ref:
             msg = f"{log_ref} for {schema} \n\twith params {bind_params} \n\tcompleted in {t2 - t1} seconds."
         else:
             msg = f"Trino query for {schema} \n\twith params {bind_params} \n\tcompleted in {t2 - t1} seconds."
         LOG.info(msg)
         return results, description
     except Exception as ex:
         if attempts_left == 0:
             msg = f"Failing SQL {sql} \n\t and bind_params {bind_params}"
             LOG.error(msg)
         raise ex
Ejemplo n.º 2
0
 def _execute_presto_multipart_sql_query(
         self,
         schema,
         sql,
         bind_params=None,
         preprocessor=JinjaSql().prepare_query):
     """Execute multiple related SQL queries in Presto."""
     presto_conn = kpdb.connect(schema=self.schema)
     return kpdb.executescript(presto_conn,
                               sql,
                               params=bind_params,
                               preprocessor=preprocessor)
Ejemplo n.º 3
0
 def _execute_presto_raw_sql_query(self, schema, sql, bind_params=None):
     """Execute a single presto query"""
     presto_conn = kpdb.connect(schema=schema)
     presto_cur = presto_conn.cursor()
     presto_cur.execute(sql, bind_params)
     return presto_cur.fetchall()