aaron-y-chen commented on code in PR #71135:
URL: https://github.com/apache/airflow/pull/71135#discussion_r3879255452


##########
providers/amazon/src/airflow/providers/amazon/aws/triggers/kinesis.py:
##########
@@ -0,0 +1,336 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+from __future__ import annotations
+
+import asyncio
+import base64
+import hashlib
+import json
+from collections.abc import AsyncIterator
+from typing import TYPE_CHECKING, Any
+
+from airflow.providers.amazon.aws.hooks.kinesis import KinesisHook
+from airflow.providers.amazon.version_compat import AIRFLOW_V_3_0_PLUS
+
+if AIRFLOW_V_3_0_PLUS:
+    from airflow.triggers.base import BaseEventTrigger, TriggerEvent
+else:
+    from airflow.triggers.base import (  # type: ignore
+        BaseTrigger as BaseEventTrigger,
+        TriggerEvent,
+    )
+
+if TYPE_CHECKING:
+    from airflow.providers.amazon.aws.hooks.base_aws import BaseAwsConnection
+
+_CHECKPOINT_KEY_PREFIX = "kinesis_shard_sequence_numbers"
+_ITERATOR_TYPES_WITHOUT_EXTRA_ARGS = frozenset({"LATEST", "TRIM_HORIZON"})
+
+
+class KinesisTrigger(BaseEventTrigger):
+    """
+    Wait asynchronously for records on an Amazon Kinesis Data Stream.
+
+    The trigger is long-running and emits one event for each non-empty shard 
response. Record data is
+    base64-encoded in the event payload and must be decoded by the consumer. 
Delivery is best-effort:
+    a triggerer failure can cause records to be repeated or missed around the 
failure window.
+
+    When Airflow provides an asset state store for a single watched asset, the 
trigger checkpoints the
+    last sequence number read from each shard. The same asset and stream 
identity share one logical cursor;
+    do not configure multiple watchers that require independent progress for 
the same stream on one asset.
+
+    :param stream_name: Name of the Kinesis Data Stream to watch.
+    :param aws_conn_id: AWS connection id.
+    :param shard_iterator_type: Position used when a shard has no checkpoint. 
``LATEST`` only sees records
+        that arrive after the watcher starts; ``TRIM_HORIZON`` starts from the 
oldest retained record.

Review Comment:
   Yes, intentionally. In this PR, I'd prefer to keep the initial-position API 
limited to `LATEST` and `TRIM_HORIZON`, since they do not require additional 
arguments.
   
   Supporting `AT_TIMESTAMP` would require adding and serializing a timestamp 
parameter, while `AT_SEQUENCE_NUMBER` would require a per-shard sequence-number 
mapping because this trigger polls all shards. Both would add public API 
surface with their own semantics around checkpoint recovery and resharding, so 
I think they are better considered separately.
   
   I'll make the reasoning explicit in the docstring; validation already 
rejects the other values with the supported set in the message.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to