Skip to content

Commit

Permalink
[db-engine-spec] Aligning Hive/Presto partition logic (apache#7007)
Browse files Browse the repository at this point in the history
  • Loading branch information
john-bodley authored Mar 13, 2019
1 parent 7f3c145 commit 05be866
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions superset/db_engine_specs.py
Original file line number Diff line number Diff line change
Expand Up @@ -986,16 +986,16 @@ def where_latest_partition(
except Exception:
# table is not partitioned
return False
for c in columns:
if c.get('name') == col_name:
return qry.where(Column(col_name) == value)
if value is not None:
for c in columns:
if c.get('name') == col_name:
return qry.where(Column(col_name) == value)
return False

@classmethod
def _latest_partition_from_df(cls, df):
recs = df.to_records(index=False)
if recs:
return recs[0][0]
if not df.empty:
return df.to_records(index=False)[0][0]

@classmethod
def latest_partition(cls, table_name, schema, database, show_first=False):
Expand All @@ -1012,7 +1012,7 @@ def latest_partition(cls, table_name, schema, database, show_first=False):
:type show_first: bool
>>> latest_partition('foo_table')
'2018-01-01'
('ds', '2018-01-01')
"""
indexes = database.get_indexes(table_name, schema)
if len(indexes[0]['column_names']) < 1:
Expand Down Expand Up @@ -1330,9 +1330,10 @@ def where_latest_partition(
except Exception:
# table is not partitioned
return False
for c in columns:
if c.get('name') == col_name:
return qry.where(Column(col_name) == value)
if value is not None:
for c in columns:
if c.get('name') == col_name:
return qry.where(Column(col_name) == value)
return False

@classmethod
Expand All @@ -1343,7 +1344,8 @@ def latest_sub_partition(cls, table_name, schema, database, **kwargs):
@classmethod
def _latest_partition_from_df(cls, df):
"""Hive partitions look like ds={partition name}"""
return df.ix[:, 0].max().split('=')[1]
if not df.empty:
return df.ix[:, 0].max().split('=')[1]

@classmethod
def _partition_query(
Expand Down

0 comments on commit 05be866

Please sign in to comment.