airflow/hooks/hive_hooks.py
def max_partition(self, schema, table_name, field=None, filter_map=None):
        """
        Returns the maximum value for all partitions with given field in a table.
        If only one partition key exist in the table, the key will be used as field.
        filter_map should be a partition_key:partition_value map and will be used to
        filter out partitions.

        :param schema: schema name.
        :type schema: str
        :param table_name: table name.
        :type table_name: str
        :param field: partition key to get max partition from.
        :type field: str
        :param filter_map: partition_key:partition_value map used for partition filtering.
        :type filter_map: map

        >>> hh = HiveMetastoreHook()
        >>> filter_map = {'ds': '2015-01-01', 'ds': '2014-01-01'}
        >>> t = 'static_babynames_partitioned'
        >>> hh.max_partition(schema='airflow',\
        ... table_name=t, field='ds', filter_map=filter_map)
        '2015-01-01'
        """
        with self.metastore as client:
            table = client.get_table(dbname=schema, tbl_name=table_name)
            key_name_set = set(key.name for key in table.partitionKeys)
            if len(table.partitionKeys) == 1:
                field = table.partitionKeys[0].name
            elif not field:
                raise AirflowException("Please specify the field you want the max "
                                       "value for.")
            elif field not in key_name_set:
                raise AirflowException("Provided field is not a partition key.")

            if filter_map and not set(filter_map.keys()).issubset(key_name_set):
                raise AirflowException("Provided filter_map contains keys "
                                       "that are not partition key.")

            part_names = \
                client.get_partition_names(schema,
                                           table_name,
                                           max_parts=HiveMetastoreHook.MAX_PART_COUNT)
            part_specs = [client.partition_name_to_spec(part_name)
                          for part_name in part_names]

        return HiveMetastoreHook._get_max_partition_from_part_specs(part_specs,
                                                                    field,
                                                                    filter_map)
def max_partition(self, schema, table_name, field=None, filter_map=None):
        """
        Returns the maximum value for all partitions with given field in a table.
        If only one partition key exist in the table, the key will be used as field.
        filter_map should be a partition_key:partition_value map and will be used to
        filter out partitions.

        :param schema: schema name.
        :type schema: str
        :param table_name: table name.
        :type table_name: str
        :param field: partition key to get max partition from.
        :type field: str
        :param filter_map: partition_key:partition_value map used for partition filtering.
        :type filter_map: map

        >>> hh = HiveMetastoreHook()
        >>> filter_map = {'ds': '2015-01-01', 'ds': '2014-01-01'}
        >>> t = 'static_babynames_partitioned'
        >>> hh.max_partition(schema='airflow',\
        ... table_name=t, field='ds', filter_map=filter_map)
        '2015-01-01'
        """
        with self.metastore as client:
            table = client.get_table(dbname=schema, tbl_name=table_name)
            key_name_set = set(key.name for key in table.partitionKeys)
            if len(table.partitionKeys) == 1:
                field = table.partitionKeys[0].name
            elif not field:
                raise AirflowException("Please specify the field you want the max "
                                       "value for.")
            elif field not in key_name_set:
                raise AirflowException("Provided field is not a partition key.")

            if filter_map and not set(filter_map.keys()).issubset(key_name_set):
                raise AirflowException("Provided filter_map contains keys "
                                       "that are not partition key.")

            part_names = \
                client.get_partition_names(schema,
                                           table_name,
                                           max_parts=HiveMetastoreHook.MAX_PART_COUNT)
            part_specs = [client.partition_name_to_spec(part_name)
                          for part_name in part_names]

        return HiveMetastoreHook._get_max_partition_from_part_specs(part_specs,
                                                                    field,
                                                                    filter_map)
def max_partition ( self , schema , table_name , field = None , filter_map = None ) : with self . metastore as client : table = client . get_table ( dbname = schema , tbl_name = table_name ) key_name_set = set ( key . name for key in table . partitionKeys ) if len ( table . partitionKeys ) == 1 : field = table . partitionKeys [ 0 ] . name elif not field : raise AirflowException ( "Please specify the field you want the max " "value for." ) elif field not in key_name_set : raise AirflowException ( "Provided field is not a partition key." ) if filter_map and not set ( filter_map . keys ( ) ) . issubset ( key_name_set ) : raise AirflowException ( "Provided filter_map contains keys " "that are not partition key." ) part_names = client . get_partition_names ( schema , table_name , max_parts = HiveMetastoreHook . MAX_PART_COUNT ) part_specs = [ client . partition_name_to_spec ( part_name ) for part_name in part_names ] return HiveMetastoreHook . _get_max_partition_from_part_specs ( part_specs , field , filter_map )
Returns the maximum value for all partitions with given field in a table.
        If only one partition key exist in the table, the key will be used as field.
        filter_map should be a partition_key:partition_value map and will be used to
        filter out partitions.

        :param schema: schema name.
        :type schema: str
        :param table_name: table name.
        :type table_name: str
        :param field: partition key to get max partition from.
        :type field: str
        :param filter_map: partition_key:partition_value map used for partition filtering.
        :type filter_map: map

        >>> hh = HiveMetastoreHook()
        >>> filter_map = {'ds': '2015-01-01', 'ds': '2014-01-01'}
        >>> t = 'static_babynames_partitioned'
        >>> hh.max_partition(schema='airflow',\
        ... table_name=t, field='ds', filter_map=filter_map)
        '2015-01-01'
Returns the maximum value for all partitions with given field in a table . If only one partition key exist in the table the key will be used as field . filter_map should be a partition_key : partition_value map and will be used to filter out partitions .