def _get_sample_data(db, database, table, column, is_async=False, cluster=None, operation=None): if operation == 'hello': table_obj = None else: table_obj = db.get_table(database, table) if table_obj.is_impala_only and db.client.query_server[ 'server_name'] != 'impala': # Kudu table, now Hive should support it though query_server = get_query_server_config('impala', connector=cluster) db = dbms.get(db.client.user, query_server, cluster=cluster) sample_data = db.get_sample(database, table_obj, column, generate_sql_only=is_async, operation=operation) response = {'status': -1} if sample_data: response['status'] = 0 if is_async: notebook = make_notebook(name=_( 'Table sample for `%(database)s`.`%(table)s`.`%(column)s`') % { 'database': database, 'table': table, 'column': column }, editor_type=_get_servername(db), statement=sample_data, status='ready-execute', skip_historify=True, is_task=False, compute=cluster if cluster else None) response['result'] = notebook.execute( request=MockedDjangoRequest(user=db.client.user), batch=False) if table_obj.is_impala_only: response['result']['type'] = 'impala' else: sample = escape_rows(sample_data.rows(), nulls_only=True) if column: sample = set([row[0] for row in sample]) sample = [[item] for item in sorted(list(sample))] response['headers'] = sample_data.cols() response['full_headers'] = sample_data.full_cols() response['rows'] = sample else: response['message'] = _('Failed to get sample data.') return response
def _get_sample_data(db, database, table, column, async=False, cluster=None, operation=None): table_obj = db.get_table(database, table) if table_obj.is_impala_only and db.client.query_server['server_name'] != 'impala': query_server = get_query_server_config('impala', cluster=cluster) db = dbms.get(db.client.user, query_server, cluster=cluster) sample_data = db.get_sample(database, table_obj, column, generate_sql_only=async, operation=operation) response = {'status': -1} if sample_data: response['status'] = 0 if async: notebook = make_notebook( name=_('Table sample for `%(database)s`.`%(table)s`.`%(column)s`') % {'database': database, 'table': table, 'column': column}, editor_type=_get_servername(db), statement=sample_data, status='ready-execute', skip_historify=True, is_task=False, compute=cluster if cluster else None ) response['result'] = notebook.execute(request=MockedDjangoRequest(user=db.client.user), batch=False) if table_obj.is_impala_only: response['result']['type'] = 'impala' else: sample = escape_rows(sample_data.rows(), nulls_only=True) if column: sample = set([row[0] for row in sample]) sample = [[item] for item in sorted(list(sample))]
def _get_sample_data(db, database, table, column, async=False, cluster=None, operation=None): table_obj = db.get_table(database, table) if table_obj.is_impala_only and db.client.query_server['server_name'] != 'impala': query_server = get_query_server_config('impala', cluster=cluster) db = dbms.get(db.client.user, query_server, cluster=cluster) sample_data = db.get_sample(database, table_obj, column, generate_sql_only=async, operation=operation) response = {'status': -1} if sample_data: response['status'] = 0 if async: notebook = make_notebook( name=_('Table sample for `%(database)s`.`%(table)s`.`%(column)s`') % {'database': database, 'table': table, 'column': column}, editor_type=_get_servername(db), statement=sample_data, status='ready-execute', skip_historify=True, is_task=False, compute=cluster if cluster else None ) response['result'] = notebook.execute(request=MockedDjangoRequest(user=db.client.user), batch=False) if table_obj.is_impala_only: response['result']['type'] = 'impala' else: sample = escape_rows(sample_data.rows(), nulls_only=True) if column: sample = set([row[0] for row in sample]) sample = [[item] for item in sorted(list(sample))]