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

Make describe method work on other people's tables #15

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
17 changes: 14 additions & 3 deletions desdb/desdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,13 @@ def describe(self, table, fmt='pretty', comments=False, show=False):
"""
# separate queries because the fgetmetadata is a slow
# function call
dots = table.count('.')
if dots==0:
owner=self.username
elif dots==1:
owner, table = table.split('.')
else:
raise ValueError("Invalid table name")
if not comments:
q="""
SELECT
Expand All @@ -208,9 +215,11 @@ def describe(self, table, fmt='pretty', comments=False, show=False):
CAST(data_precision as VARCHAR(9)) as precision,
CAST(data_scale as VARCHAR(5)) as scale
FROM
table(fgetmetadata)
all_tab_cols
WHERE
table_name = '{table}'
AND
owner = '{owner}'
ORDER BY
column_id
"""
Expand All @@ -225,13 +234,15 @@ def describe(self, table, fmt='pretty', comments=False, show=False):
data_scale as scale,
comments
FROM
table(fgetmetadata)
all_tab_cols
WHERE
table_name = '{table}'
AND
owner = '{owner}'
ORDER BY
column_id
"""
q=q.format(table=table.upper())
q=q.format(table=table.upper(), owner=owner.upper())

if show:
stderr.write(q)
Expand Down