Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Spark-SQL -Hiveserver2 interface does not show tables #3328

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 31 additions & 10 deletions apps/beeswax/src/beeswax/server/dbms.py
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,14 @@ def get_tables(self, database='default', table_names='*', table_types=None):
return tables


def create_result_entry(self, name, entry_type, comment=''):
return {
'name': name,
'type': entry_type,
'comment': comment
}


def _get_tables_via_sparksql(self, database, table_names='*'):
hql = "SHOW TABLES IN %s" % database
if table_names != '*':
Expand All @@ -458,19 +466,32 @@ def _get_tables_via_sparksql(self, database, table_names='*'):
handle = self.execute_and_wait(query, timeout_sec=timeout)

if handle:
result = self.fetch(handle, rows=5000)
result_table = list(self.fetch(handle, rows=5000).rows())
self.close(handle)
else:
result_table = []

# We get back: database | tableName | isTemporary
return [{
'name': row[1],
'type': 'VIEW' if row[2] else 'TABLE',
'comment': ''
}
for row in result.rows()
]
hql = "SHOW VIEWS IN %s" % database
if table_names != '*':
identifier = self.to_matching_wildcard(table_names)
hql += " LIKE '%s'" % (identifier)

query = hql_query(hql)
timeout = SERVER_CONN_TIMEOUT.get()

handle = self.execute_and_wait(query, timeout_sec=timeout)

if handle:
result_view = list(self.fetch(handle, rows=5000).rows())
self.close(handle)
else:
return []
result_view = []

filtered_tables = [table for table in result_table if table not in result_view]
table_entries = [self.create_result_entry(name=row[0], entry_type='TABLE') for row in filtered_tables]
view_entries = [self.create_result_entry(name=row[0], entry_type='VIEW') for row in result_view]

return table_entries + view_entries


def get_table(self, database, table_name):
Expand Down
Loading