airflow/hooks/hive_hooks.py
def _get_max_partition_from_part_specs(part_specs, partition_key, filter_map):
        """
        Helper method to get max partition of partitions with partition_key
        from part specs. key:value pair in filter_map will be used to
        filter out partitions.

        :param part_specs: list of partition specs.
        :type part_specs: list
        :param partition_key: partition key name.
        :type partition_key: str
        :param filter_map: partition_key:partition_value map used for partition filtering,
                           e.g. {'key1': 'value1', 'key2': 'value2'}.
                           Only partitions matching all partition_key:partition_value
                           pairs will be considered as candidates of max partition.
        :type filter_map: map
        :return: Max partition or None if part_specs is empty.
        """
        if not part_specs:
            return None

        # Assuming all specs have the same keys.
        if partition_key not in part_specs[0].keys():
            raise AirflowException("Provided partition_key {} "
                                   "is not in part_specs.".format(partition_key))
        if filter_map:
            is_subset = set(filter_map.keys()).issubset(set(part_specs[0].keys()))
        if filter_map and not is_subset:
            raise AirflowException("Keys in provided filter_map {} "
                                   "are not subset of part_spec keys: {}"
                                   .format(', '.join(filter_map.keys()),
                                           ', '.join(part_specs[0].keys())))

        candidates = [p_dict[partition_key] for p_dict in part_specs
                      if filter_map is None or
                      all(item in p_dict.items() for item in filter_map.items())]

        if not candidates:
            return None
        else:
            return max(candidates).encode('utf-8')
def _get_max_partition_from_part_specs(part_specs, partition_key, filter_map):
        """
        Helper method to get max partition of partitions with partition_key
        from part specs. key:value pair in filter_map will be used to
        filter out partitions.

        :param part_specs: list of partition specs.
        :type part_specs: list
        :param partition_key: partition key name.
        :type partition_key: str
        :param filter_map: partition_key:partition_value map used for partition filtering,
                           e.g. {'key1': 'value1', 'key2': 'value2'}.
                           Only partitions matching all partition_key:partition_value
                           pairs will be considered as candidates of max partition.
        :type filter_map: map
        :return: Max partition or None if part_specs is empty.
        """
        if not part_specs:
            return None

        # Assuming all specs have the same keys.
        if partition_key not in part_specs[0].keys():
            raise AirflowException("Provided partition_key {} "
                                   "is not in part_specs.".format(partition_key))
        if filter_map:
            is_subset = set(filter_map.keys()).issubset(set(part_specs[0].keys()))
        if filter_map and not is_subset:
            raise AirflowException("Keys in provided filter_map {} "
                                   "are not subset of part_spec keys: {}"
                                   .format(', '.join(filter_map.keys()),
                                           ', '.join(part_specs[0].keys())))

        candidates = [p_dict[partition_key] for p_dict in part_specs
                      if filter_map is None or
                      all(item in p_dict.items() for item in filter_map.items())]

        if not candidates:
            return None
        else:
            return max(candidates).encode('utf-8')
Helper method to get max partition of partitions with partition_key
        from part specs. key:value pair in filter_map will be used to
        filter out partitions.

        :param part_specs: list of partition specs.
        :type part_specs: list
        :param partition_key: partition key name.
        :type partition_key: str
        :param filter_map: partition_key:partition_value map used for partition filtering,
                           e.g. {'key1': 'value1', 'key2': 'value2'}.
                           Only partitions matching all partition_key:partition_value
                           pairs will be considered as candidates of max partition.
        :type filter_map: map
        :return: Max partition or None if part_specs is empty.