Example #1
0
 def run_sql(self, line, cell):
     query = cell
     resp = self.querier.run_sql(query)
     result = self.querier.async_wait_for_result(resp)
     resp_table = result['results'][0]['table']
     column_names = resp_table['column_names']
     rows_dict = [dict(zip(column_names, row)) for row in resp_table['rows']]
     table_result = Table.from_object(rows_dict)
     table_result.print_table()
     return table_result
Example #2
0
def dbt_run_sql(context, sql):
    sql_base64 = b64encode(sql.encode('utf-8')).decode('ascii')
    name = hash_value(sql_base64)
    resp = dbt_rcp_request(context,
                           "run_sql",
                           params={
                               "sql": sql_base64,
                               "timeout": 60,
                               "name": name
                           })
    resp_table = resp['result']['results'][0]['table']
    column_names = resp_table['column_names']

    # # behave
    # # we have to convert all cells to str for behave tables to work
    # rows = [[str(x) for x in row] for row in resp_table['rows']]
    # table = Table(column_names, rows=rows)
    # return table

    # agate
    rows_dict = [dict(zip(column_names, row)) for row in resp_table['rows']]
    return Table.from_object(rows_dict)
Example #3
0
def behave2agate(table):
    column_names = table.headings
    rows = table.rows
    rows_dict = [dict(zip(column_names, row)) for row in rows]
    return Table.from_object(rows_dict)