示例#1
0
 def __new__(cls, data: Optional[Dict[str, Any]]):
     data = check.opt_dict_param(data, "data", key_type=str)
     try:
         # check that the value is JSON serializable
         seven.dumps(data)
     except TypeError:
         raise DagsterInvalidMetadata("Value is a dictionary but is not JSON serializable.")
     return super(JsonMetadataValue, cls).__new__(cls, data)
示例#2
0
def parse_metadata_entry(label: str, value: ParseableMetadataEntryData) -> "EventMetadataEntry":
    check.str_param(label, "label")

    if isinstance(value, (EventMetadataEntry, PartitionMetadataEntry)):
        raise DagsterInvalidEventMetadata(
            f"Expected a metadata value, found an instance of {value.__class__.__name__}. Consider "
            "instead using a EventMetadata wrapper for the value, or using the `metadata_entries` "
            "parameter to pass in a List[EventMetadataEntry|PartitionMetadataEntry]."
        )

    if isinstance(
        value,
        (
            TextMetadataEntryData,
            UrlMetadataEntryData,
            PathMetadataEntryData,
            JsonMetadataEntryData,
            MarkdownMetadataEntryData,
            FloatMetadataEntryData,
            IntMetadataEntryData,
            PythonArtifactMetadataEntryData,
            DagsterAssetMetadataEntryData,
            DagsterPipelineRunMetadataEntryData,
        ),
    ):
        return EventMetadataEntry(label, None, value)

    if isinstance(value, str):
        return EventMetadataEntry.text(value, label)

    if isinstance(value, float):
        return EventMetadataEntry.float(value, label)

    if isinstance(value, int):
        return EventMetadataEntry.int(value, label)

    if isinstance(value, dict):
        try:
            # check that the value is JSON serializable
            seven.dumps(value)
            return EventMetadataEntry.json(value, label)
        except TypeError:
            raise DagsterInvalidEventMetadata(
                f'Could not resolve the metadata value for "{label}" to a JSON serializable value. '
                "Consider wrapping the value with the appropriate EventMetadata type."
            )

    raise DagsterInvalidEventMetadata(
        f'Could not resolve the metadata value for "{label}" to a known type. '
        f"Its type was {type(value)}. Consider wrapping the value with the appropriate "
        "EventMetadata type."
    )
示例#3
0
def package_metadata_value(label: str,
                           value: RawMetadataValue) -> "MetadataEntry":
    check.str_param(label, "label")

    if isinstance(value, (MetadataEntry, PartitionMetadataEntry)):
        raise DagsterInvalidMetadata(
            f"Expected a metadata value, found an instance of {value.__class__.__name__}. Consider "
            "instead using a MetadataValue wrapper for the value.")

    if isinstance(value, MetadataValue):
        return MetadataEntry(label, None, value)

    if isinstance(value, str):
        return MetadataEntry.text(value, label)

    if isinstance(value, float):
        return MetadataEntry.float(value, label)

    if isinstance(value, int):
        return MetadataEntry.int(value, label)

    if isinstance(value, dict):
        try:
            # check that the value is JSON serializable
            seven.dumps(value)
            return MetadataEntry.json(value, label)
        except TypeError:
            raise DagsterInvalidMetadata(
                f'Could not resolve the metadata value for "{label}" to a JSON serializable value. '
                "Consider wrapping the value with the appropriate MetadataValue type."
            )

    raise DagsterInvalidMetadata(
        f'Could not resolve the metadata value for "{label}" to a known type. '
        f"Its type was {type(value)}. Consider wrapping the value with the appropriate "
        "MetadataValue type.")
示例#4
0
    def _apply_asset_filter_to_query(
        self,
        query,
        asset_keys=None,
        prefix=None,
        limit=None,
        cursor=None,
    ):
        if asset_keys:
            query = query.where(
                AssetKeyTable.c.asset_key.in_([asset_key.to_string() for asset_key in asset_keys])
            )

        if prefix:
            prefix_str = seven.dumps(prefix)[:-1]
            query = query.where(AssetKeyTable.c.asset_key.startswith(prefix_str))

        if cursor:
            query = query.where(AssetKeyTable.c.asset_key > cursor)

        if limit:
            query = query.limit(limit)
        return query