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

Display the first partition in the latest_partition function. #2425

Merged
merged 1 commit into from
Mar 16, 2017
Merged
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
9 changes: 6 additions & 3 deletions superset/db_engine_specs.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ def extra_table_metadata(cls, database, table_name, schema_name):
full_table_name = "{}.{}".format(schema_name, table_name)
pql = cls._partition_query(full_table_name)
col_name, latest_part = cls.latest_partition(
table_name, schema_name, database)
table_name, schema_name, database, show_first=True)
return {
'partitions': {
'cols': cols,
Expand Down Expand Up @@ -423,7 +423,7 @@ def _latest_partition_from_df(cls, df):
return df.to_records(index=False)[0][0]

@classmethod
def latest_partition(cls, table_name, schema, database):
def latest_partition(cls, table_name, schema, database, show_first=False):
"""Returns col name and the latest (max) partition value for a table

:param table_name: the name of the table
Expand All @@ -432,6 +432,9 @@ def latest_partition(cls, table_name, schema, database):
:type schema: str
:param database: database query will be run against
:type database: models.Database
:param show_first: displays the value for the first partitioning key
if there are many partitioning keys
:type show_first: bool

>>> latest_partition('foo_table')
'2018-01-01'
Expand All @@ -440,7 +443,7 @@ def latest_partition(cls, table_name, schema, database):
if len(indexes[0]['column_names']) < 1:
raise SupersetTemplateException(
"The table should have one partitioned field")
elif len(indexes[0]['column_names']) > 1:
elif not show_first and len(indexes[0]['column_names']) > 1:
raise SupersetTemplateException(
"The table should have a single partitioned field "
"to use this function. You may want to use "
Expand Down