Skip to content

Commit

Permalink
Display the first partition. (#2425)
Browse files Browse the repository at this point in the history
  • Loading branch information
bkyryliuk authored Mar 16, 2017
1 parent 36deb8d commit 3d77a12
Showing 1 changed file with 6 additions and 3 deletions.
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

0 comments on commit 3d77a12

Please sign in to comment.