To allow users to select the primary keys for incremental syncs in a custom Airbyte connector built with the airbyte-cdk, you should: 1.
Define the stream(s) in your connector manifest (YAML file) without hardcoding the primary key. The Airbyte platform allows users to specify the primary key for each stream during connection setup if it is not defined by the source or if the user wants to override it. 2.
Instruct users to select the primary key in the Airbyte UI: When configuring a connection, users can choose which field(s) to use as the primary key for each stream. This is especially important for the Incremental Sync - Append + Deduped mode, which requires a primary key for deduplication. Users can select a single field or multiple fields to form a composite primary key. This is done in the Schema tab for the connection, where the user can pick the primary key from the available fields in the stream. If the source does not define a primary key, the UI will prompt the user to select one. If the user wants to override the source-defined primary key, they can do so as well [User-Defined Primary key](
https://docs.airbyte.com/platform/using-airbyte/core-concepts/sync-modes/incremental-append-deduped#user-defined-primary-key). 3.
Connector Manifest (YAML) Example: In your YAML, you do not need to specify the primary key statically. Instead, ensure your stream definition allows for user selection. The Airbyte platform will handle the UI and configuration for primary key selection. 4.
How it works in the protocol: The selected primary key(s) will be included in the
primary_key
field of the
ConfiguredAirbyteStream
object, which is required for the
append_dedup
destination sync mode [ConfiguredAirbyteStream](
https://docs.airbyte.com/platform/understanding-airbyte/airbyte-protocol#configuredairbytestream).
Summary: You do not need to implement special logic in your connector code to allow user selection of primary keys. Instead, design your connector so that the primary key is not hardcoded, and instruct users to select the primary key in the Airbyte UI during connection setup. The platform will handle passing the selected primary key to your connector as part of the configuration. For more details, see the documentation on [User-Defined Primary key](
https://docs.airbyte.com/platform/using-airbyte/core-concepts/sync-modes/incremental-append-deduped#user-defined-primary-key) and [ConfiguredAirbyteStream](
https://docs.airbyte.com/platform/understanding-airbyte/airbyte-protocol#configuredairbytestream).