Created
April 11, 2018 18:41
-
-
Save cpcloud/511137aa20c3ef728e2542619871d0be to your computer and use it in GitHub Desktop.
Simple BigQuery shell using ibis
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
import ibis | |
import click | |
from prompt_toolkit import prompt | |
from prompt_toolkit.layout.lexers import PygmentsLexer | |
from pygments.lexers.sql import PostgresLexer | |
@click.command() | |
@click.argument('project') | |
@click.argument('dataset') | |
def main(project, dataset): | |
lexer = PygmentsLexer(PostgresLexer) | |
con = ibis.bigquery.connect(project, dataset) | |
while True: | |
query = prompt('bqsh> ', lexer=lexer) | |
try: | |
cursor = con.raw_sql(query) | |
result = pd.DataFrame(cursor.fetchall(), columns=cursor.columns) | |
except Exception as e: | |
print(e) | |
else: | |
print(result) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment