"""Python implementation for deserializing a dynamo db streams image. This codebase and its tests should be updated prior to making any Snowflake database PRs to update the UDF. """ from typing import Any from boto3.dynamodb.types import TypeDeserializer def _clean_dynamodb_streams_image(item: Any) -> Any: """Clean a DynamoDBStreams Image.""" if isinstance(item, dict): if "type" in item: return { item["type"]: _clean_dynamodb_streams_image(item[item["type"].lower()]) } cleaned_dict = {} for key, val in item.items(): cleaned_dict[key] = _clean_dynamodb_streams_image(val) return cleaned_dict elif isinstance(item, list): cleaned_list = [] for li in item: cleaned_list.append(_clean_dynamodb_streams_image(li)) return cleaned_list return item def udf_entrypoint(obj: Any) -> Any: """Deserializes a DynamoDBStreams Image into a Python Dict.""" dynamo_item = _clean_dynamodb_streams_image(obj) return TypeDeserializer().deserialize({"M": dynamo_item})