def main(): history = FileHistory(os.path.expanduser("~/.pydruid_history")) try: url = sys.argv[1] except IndexError: url = "http://localhost:8082/druid/v2/sql/" kwargs = get_connection_kwargs(url) connection = connect(**kwargs) cursor = connection.cursor() words = get_autocomplete(connection) sql_completer = WordCompleter(words, ignore_case=True) while True: try: query = prompt( "> ", lexer=SqlLexer, completer=sql_completer, style=DocumentStyle, history=history, on_abort=AbortAction.RETRY, ) except EOFError: break # Control-D pressed. # run query query = query.strip("; ") if query: # shortcuts if query.lower() in ("bye", "exit", "quit"): break for pattern, repl in replacements.items(): query = re.sub(pattern, repl, query) try: result = cursor.execute(query) except Exception as e: print(e) continue headers = [t[0] for t in cursor.description or []] print(tabulate(result, headers=headers)) print("GoodBye!")
def main(): history = FileHistory(os.path.expanduser('~/.pydruid_history')) try: url = sys.argv[1] except IndexError: url = 'http://localhost:8082/druid/v2/sql/' kwargs = get_connection_kwargs(url) connection = connect(**kwargs) cursor = connection.cursor() words = get_autocomplete(connection) sql_completer = WordCompleter(words, ignore_case=True) while True: try: query = prompt( '> ', lexer=SqlLexer, completer=sql_completer, style=DocumentStyle, history=history, on_abort=AbortAction.RETRY) except EOFError: break # Control-D pressed. # run query query = query.strip('; ') if query: # shortcuts if query.lower() in ('bye', 'exit', 'quit'): break for pattern, repl in replacements.items(): query = re.sub(pattern, repl, query) try: result = cursor.execute(query) except Exception as e: print(e) continue headers = [t[0] for t in cursor.description or []] print(tabulate(result, headers=headers)) print('GoodBye!')
def main(): history = FileHistory(os.path.expanduser('~/.pydruid_history')) try: url = sys.argv[1] except IndexError: url = 'http://localhost:8082/druid/v2/sql/' kwargs = get_connection_kwargs(url) connection = connect(**kwargs) cursor = connection.cursor() words = get_autocomplete(connection) sql_completer = WordCompleter(words, ignore_case=True) while True: try: query = prompt('> ', lexer=SqlLexer, completer=sql_completer, style=DocumentStyle, history=history, on_abort=AbortAction.RETRY) except EOFError: break # Control-D pressed. # run query if query.strip(): try: result = cursor.execute(query.rstrip(';')) except Exception as e: print(e) continue headers = [t[0] for t in cursor.description] print(tabulate(result, headers=headers)) print('GoodBye!')