'Returns the latest (max) partition value for a table
A filtering criteria should be passed for all fields that are
partitioned except for the field to be returned. For example,
if a table is partitioned by (``ds``, ``event_type`` and
``event_category``) and you want the latest ``ds``, you\'ll want
to provide a filter as keyword arguments for both
``event_type`` and ``event_category`` as in
``latest_sub_partition(\'my_table\',
event_category=\'page\', event_type=\'click\')``
:param table_name: the name of the table, can be just the table
name or a fully qualified table name as ``schema_name.table_name``
:type table_name: str
:param schema: schema / database / namespace
:type schema: str
:param database: database query will be run against
:type database: models.Database
:param kwargs: keyword arguments define the filtering criteria
on the partition list. There can be many of these.
:type kwargs: str
>>> latest_sub_partition(\'sub_partition_table\', event_type=\'click\')
\'2018-01-01\''

@classmethod
def latest_sub_partition(cls, table_name, schema, database, **kwargs):

    indexes = database.get_indexes(table_name, schema)
    part_fields = indexes[0][u'column_names']
    for k in kwargs.keys():
        if (k not in k in part_fields):
            msg = u'Field    [{k}]    is    not    part    of    the    portioning    key'
            raise SupersetTemplateException(msg)
    if (len(kwargs.keys()) != (len(part_fields) - 1)):
        msg = u'A    filter    needs    to    be    specified    for    {}    out    of    the    {}    fields.'.format((len(part_fields) - 1), len(part_fields))
        raise SupersetTemplateException(msg)
    for field in part_fields:
        if (field not in kwargs.keys()):
            field_to_return = field
    sql = cls._partition_query(table_name, 1, [(field_to_return, True)], kwargs)
    df = database.get_df(sql, schema)
    if df.empty:
        return u''
    return df.to_dict()[field_to_return][0]
