Example #1
0
    def asset_partitions_time_window_for_output(self, output_name: str) -> TimeWindow:
        """The time window for the partitions of the asset correponding to the given output.

        Raises an error if either of the following are true:
        - The output asset has no partitioning.
        - The output asset is not partitioned with a TimeWindowPartitionsDefinition.
        """
        partitions_def = self.solid_def.output_def_named(output_name).asset_partitions_def

        if not partitions_def:
            raise ValueError(
                "Tried to get asset partitions for an output that does not correspond to a "
                "partitioned asset."
            )

        if not isinstance(partitions_def, TimeWindowPartitionsDefinition):
            raise ValueError(
                "Tried to get asset partitions for an output that correponds to a partitioned "
                "asset that is not partitioned with a TimeWindowPartitionsDefinition."
            )
        partition_key_range = self.asset_partition_key_range_for_output(output_name)
        return TimeWindow(
            # mypy thinks partitions_def is <nothing> here because ????
            partitions_def.time_window_for_partition_key(partition_key_range.start).start,  # type: ignore
            partitions_def.time_window_for_partition_key(partition_key_range.end).end,  # type: ignore
        )
Example #2
0
    def asset_partitions_time_window(self) -> TimeWindow:
        """The time window for the partitions of the input asset.

        Raises an error if either of the following are true:
        - The input asset has no partitioning.
        - The input asset is not partitioned with a TimeWindowPartitionsDefinition.
        """
        if self.upstream_output is None:
            check.failed(
                "InputContext needs upstream_output to get asset_partitions_time_window"
            )

        partitions_def = self.upstream_output.solid_def.output_def_named(
            self.upstream_output.name).asset_partitions_def

        if not partitions_def:
            raise ValueError(
                "Tried to get asset partitions for an output that does not correspond to a "
                "partitioned asset.")

        if not isinstance(partitions_def, TimeWindowPartitionsDefinition):
            raise ValueError(
                "Tried to get asset partitions for an input that correponds to a partitioned "
                "asset that is not partitioned with a TimeWindowPartitionsDefinition."
            )

        partition_key_range = self.asset_partition_key_range
        return TimeWindow(
            # mypy thinks partitions_def is <nothing> here because ????
            partitions_def.time_window_for_partition_key(
                partition_key_range.start).start,  # type: ignore
            partitions_def.time_window_for_partition_key(
                partition_key_range.end).end,  # type: ignore
        )
 def load_input(self, context):
     assert context.asset_partitions_time_window == TimeWindow(
         pendulum.parse("2020-01-01"), pendulum.parse("2020-01-03"))
 def handle_output(self, context, obj):
     assert context.asset_partitions_time_window == TimeWindow(
         pendulum.parse("2020-01-02"), pendulum.parse("2020-01-03"))
 def handle_output(self, context, _obj):
     assert context.asset_partitions_time_window == TimeWindow(
         pendulum.parse("2021-06-06"), pendulum.parse("2021-06-07"))
Example #6
0
def time_window(start: str, end: str) -> TimeWindow:
    return TimeWindow(pendulum.parse(start), pendulum.parse(end))
Example #7
0
def time_window(start: str, end: str) -> TimeWindow:
    return TimeWindow(cast(datetime, pendulum.parse(start)),
                      cast(datetime, pendulum.parse(end)))