<@U04S8PLJWMT> in incremental append mode, will th...
# ask-ai
a
@kapa.ai in incremental append mode, will there be a case when zero records are found in subsequent run? in case of jdbc db as a source?
k
Yes, in Incremental Append mode with a JDBC database as the source, it is possible for a sync run to find zero new records in a subsequent run. This can happen if no new or updated records have a cursor value greater than or equal to the last recorded cursor value since the previous sync. The incremental sync relies on a query like:
Copy code
sql SELECT * FROM table WHERE cursor_field >= 'last_sync_max_cursor_field_value'
If no records meet this condition (i.e., no new or updated data since the last sync), then zero records will be emitted during that sync run. This is expected behavior and is not specific to JDBC sources, but applies generally to how Airbyte handles incremental syncs using cursor fields [Incremental Sync - Append: Known Limitations](https://docs.airbyte.com/platform/using-airbyte/core-concepts/sync-modes/incremental-append#known-limitations). Additionally, if the cursor field is not updated when records are modified, those changes will not be detected, and again, no records will be emitted [Incremental Sync - Append: Known Limitations](https://docs.airbyte.com/platform/using-airbyte/core-concepts/sync-modes/incremental-append#known-limitations).
a
@kapa.ai provide example of it with timestamp as a cursor column. also due to greater than or equal to approach. Wouldn't there be a record having cursor column value = last_sync_max_cursor_field_value. and it will always be present in next sync?
k
A message from kapa.ai
Certainly! Here’s an example and explanation based on Airbyte documentation: ### Example: Timestamp as Cursor Column Suppose you have a table with the following data: | id | name | updated_at | |----|-------|----------------------| | 1 | Alice | 2024-06-01T100000Z | | 2 | Bob | 2024-06-01T110000Z | | 3 | Carol | 2024-06-01T120000Z | Assume your last sync ran at
2024-06-01T12:00:00Z
, so your
last_sync_max_cursor_field_value
is
2024-06-01T12:00:00Z
. #### Next Sync Query The incremental sync will run a query like:
Copy code
sql SELECT * FROM table WHERE updated_at >= '2024-06-01T12:00:00Z'
If no new records have been added or updated since the last sync, only Carol’s record (with
updated_at = 2024-06-01T12:00:00Z
) matches the condition. If the data hasn’t changed, this record will be emitted again. ### Will the Same Record Always Be Present in the Next Sync? Yes, if no new records are added and the cursor field value for the last record remains the same, the record with
updated_at = last_sync_max_cursor_field_value
will be included in every subsequent sync. This is due to the use of the
>=
(greater than or equal to) operator in the query. As a result, you may see the same row being emitted during each sync until new data arrives with a higher cursor value. This behavior is intentional and aligns with Airbyte’s at-least-once delivery guarantee. It ensures that no records are missed, especially when the cursor is not granular enough. However, it can result in duplicate records, which is why deduplication is often recommended downstream [Inclusive Cursors](https://docs.airbyte.com/platform/using-airbyte/core-concepts/sync-modes/incremental-append#inclusive-cursors). > "Additionally, you may run into behavior where you see the same row being emitted during each sync. This will occur if your data has not changed and you attempt to run additional syncs, as the cursor field will always be greater than or equal to itself, causing it to pull the latest row multiple times until there is new data at the source." > [Inclusive Cursors](https://docs.airbyte.com/platform/using-airbyte/core-concepts/sync-modes/incremental-append#inclusive-cursors) So, in summary: - If no new data is present, the last record (with the max cursor value) will be re-synced in each run. - This is expected and by design in Airbyte’s incremental append mode.
a
@kapa.ai what will happen when 2 new records are added. Will it sync 3 records or 2 records?
k
A message from kapa.ai
If two new records are added after the last sync, Airbyte's Incremental Append mode will sync only those two new records, not three. The only exception is if one of the new records has the same cursor value as the previous maximum cursor value (i.e., a duplicate timestamp), in which case the record with the duplicate cursor value may be re-synced due to the use of the
>=
operator in the query. From the documentation: > The inclusion of the cursor in the query limits the response to only records where the updated_at value is [greater than or equal to](https://docs.airbyte.com/platform/using-airbyte/core-concepts/sync-modes/incremental-append#inclusive-cursors) the largest updated_at value from the previous synchronization. So, if the two new records have
updated_at
values greater than the last synced value, only those two will be synced. If one of them has the same
updated_at
as the last sync, then that record (plus any with a greater value) will be included, potentially resulting in three records being synced (the previous max and the two new ones), but only if there is a duplicate cursor value. This behavior is due to the "inclusive cursor" approach, which can cause the last record from the previous sync to be included again if its cursor value matches the new records' cursor value [Inclusive Cursors](https://docs.airbyte.com/platform/using-airbyte/core-concepts/sync-modes/incremental-append#inclusive-cursors).
a
but wouldn't greater than equal to bring the last synced cursor value record as well even though two new records have greater cursor column value than last synced max cursor column value?
@kapa.ai but wouldn't greater than equal to bring the last synced cursor value record as well even though two new records have greater cursor column value than last synced max cursor column value?
k
A message from kapa.ai
Great question! If two new records are added and both have a cursor value greater than the last synced max cursor value, then only those two new records will be synced. The record with the previous max cursor value will not be included again, because the
>=
operator will only match records with a cursor value equal to or greater than the last synced value. However, the only time the previous record (with the last synced cursor value) would be included again is if a new record is inserted with the same cursor value as the previous max. In that case, both the old and new records with that cursor value would be included due to the
>=
condition. To summarize: - If new records have cursor values greater than the last synced value, only the new records are synced. - If a new record has a cursor value equal to the last synced value, the previous record (with that value) will be included again. This behavior is described in the documentation: > "Additionally, you may run into behavior where you see the same row being emitted during each sync. This will occur if your data has not changed and you attempt to run additional syncs, as the cursor field will always be greater than or equal to itself, causing it to pull the latest row multiple times until there is new data at the source." > [Inclusive Cursors](https://docs.airbyte.com/platform/using-airbyte/core-concepts/sync-modes/incremental-append#inclusive-cursors) So, if the new records have strictly greater cursor values, only those new records are synced. The previous record is not re-synced in that case.
a
@kapa.ai how come >= does not match with the record from last sync having cursor column value equal to last cursor max value?
k
A message from kapa.ai
a
@kapa.ai provide example
k
A message from kapa.ai
The use of
>=
in the incremental sync query does indeed match records where the cursor column value is equal to the last synced max value. This means that, unless new records have a cursor value strictly greater than the last synced value, the record with the previous max cursor value will be included again in the next sync. From the documentation: > "Additionally, you may run into behavior where you see the same row being emitted during each sync. This will occur if your data has not changed and you attempt to run additional syncs, as the cursor field will always be greater than or equal to itself, causing it to pull the latest row multiple times until there is new data at the source." > [Inclusive Cursors](https://docs.airbyte.com/platform/using-airbyte/core-concepts/sync-modes/incremental-append#inclusive-cursors) So, to clarify: - If a record exists with a cursor value equal to the last synced max value, and the query uses
>=
, that record will be included in the next sync. - This is intentional and part of Airbyte's at-least-once delivery guarantee, ensuring no data is missed, even if it results in duplicate records that may need to be deduplicated downstream. If both new records have cursor values strictly greater than the last synced value, only those new records will be included. But if any record (old or new) has a cursor value equal to the last synced value, it will be included due to the
>=
condition.
Certainly! Here’s an example based on Airbyte’s documented behavior for Incremental Append mode with a timestamp cursor: ### Example Scenario Suppose your table looks like this after the last sync: | id | name | updated_at | |----|-------|----------------------| | 1 | Alice | 2024-06-01T100000Z | | 2 | Bob | 2024-06-01T110000Z | | 3 | Carol | 2024-06-01T120000Z | The last sync’s max cursor value is:
last_sync_max_cursor_field_value = 2024-06-01T12:00:00Z
#### Two New Records Added Now, two new records are added: | id | name | updated_at | |----|--------|----------------------| | 4 | Dave | 2024-06-01T130000Z | | 5 | Emma | 2024-06-01T140000Z | #### Next Sync Query The incremental sync will run:
Copy code
sql SELECT * FROM table WHERE updated_at >= '2024-06-01T12:00:00Z'
Records in the table: | id | name | updated_at | |----|-------|----------------------| | 3 | Carol | 2024-06-01T120000Z | ← previous max | 4 | Dave | 2024-06-01T130000Z | ← new | 5 | Emma | 2024-06-01T140000Z | ← new Which records will be synced? - If Carol’s record (id 3) was already synced in the previous run, and no new record has
updated_at = 2024-06-01T12:00:00Z
, only Dave and Emma (the two new records) will be synced. - The previous record (Carol) will not be re-synced, because her record is not new and has already been processed. Conclusion: Only the two new records will be synced in this case, not three, because their
updated_at
values are strictly greater than the last synced value. The previous record is not re-synced unless a new record shares the same cursor value as the previous max [see documentation](https://docs.airbyte.com/platform/using-airbyte/core-concepts/sync-modes/incremental-append#inclusive-cursors). If you have further questions or want to see what happens with duplicate cursor values, let me know!
a
@kapa.ai what if both emma and carol had same updated_at?
k
A message from kapa.ai
If both Emma and Carol have the same
updated_at
value (which is equal to the last synced max cursor value), then both records will be included in the next sync due to the use of the
>=
operator in the incremental sync query. This means that the record with the previous max cursor value (Carol) will be re-synced, and the new record (Emma) with the same cursor value will also be synced. This behavior is explicitly described in the Airbyte documentation: > "Additionally, you may run into behavior where you see the same row being emitted during each sync. This will occur if your data has not changed and you attempt to run additional syncs, as the cursor field will always be greater than or equal to itself, causing it to pull the latest row multiple times until there is new data at the source." > [Inclusive Cursors](https://docs.airbyte.com/platform/using-airbyte/core-concepts/sync-modes/incremental-append#inclusive-cursors) So, in your scenario, if both Emma and Carol have
updated_at = 2024-06-01T12:00:00Z
, and that is the last synced max cursor value, both records will be included in the next sync. This is part of Airbyte's at-least-once delivery guarantee and is expected behavior.
a
@kapa.ai initial table content is | id | name | updated_at | |----|-------|----------------------| | 1 | Alice | 2024-06-01T100000Z | | 2 | Bob | 2024-06-01T120000Z | | 3 | Carol | 2024-06-01T120000Z | first sync ran, Now, two new records are added: | id | name | updated_at | |----|--------|----------------------| | 4 | Dave | 2024-06-01T130000Z | | 5 | Emma | 2024-06-01T140000Z | Explain which rows are synced in each sync
k
A message from kapa.ai
Let's walk through the scenario step by step, using Airbyte's Incremental Append mode with
updated_at
as the cursor field. ### Initial Table Content (before first sync): | id | name | updated_at | |----|-------|----------------------| | 1 | Alice | 2024-06-01T100000Z | | 2 | Bob | 2024-06-01T120000Z | | 3 | Carol | 2024-06-01T120000Z | #### First Sync - The first sync acts as a full refresh, so all records are synced: - Alice (
2024-06-01T10:00:00Z
) - Bob (
2024-06-01T12:00:00Z
) - Carol (
2024-06-01T12:00:00Z
) - The max cursor value after this sync is
2024-06-01T12:00:00Z
(from Bob and Carol). --- ### After Adding Two New Records: | id | name | updated_at | |----|--------|----------------------| | 4 | Dave | 2024-06-01T130000Z | | 5 | Emma | 2024-06-01T140000Z | #### Second Sync - The incremental sync will run a query like:
Copy code
sql   SELECT * FROM table WHERE updated_at >= '2024-06-01T12:00:00Z'
- This query will match: - Bob (
2024-06-01T12:00:00Z
) - Carol (
2024-06-01T12:00:00Z
) - Dave (
2024-06-01T13:00:00Z
) - Emma (
2024-06-01T14:00:00Z
) However, since Bob and Carol were already synced in the previous run and have not changed, only the new records with updated cursor values (Dave and Emma) are considered new for the destination. But, due to the use of
>=
, if the sync logic does not track which records have already been processed for a given cursor value, Bob and Carol could be re-synced. This is a known behavior in Airbyte's incremental append mode, especially when multiple records share the same cursor value as the last sync's max value ([see documentation](https://docs.airbyte.com/platform/using-airbyte/core-concepts/sync-modes/incremental-append#inclusive-cursors)). > "Additionally, you may run into behavior where you see the same row being emitted during each sync. This will occur if your data has not changed and you attempt to run additional syncs, as the cursor field will always be greater than or equal to itself, causing it to pull the latest row multiple times until there is new data at the source." So, in the second sync, the following records will be emitted: - Bob (
2024-06-01T12:00:00Z
) - Carol (
2024-06-01T12:00:00Z
) - Dave (
2024-06-01T13:00:00Z
) - Emma (
2024-06-01T14:00:00Z
) Summary Table: | Sync # | Records Synced | |--------|-------------------------------------------------------------------------------| | 1 | Alice, Bob, Carol | | 2 | Bob, Carol, Dave, Emma | This is expected behavior due to the inclusive cursor (
>=
) approach in Airbyte's incremental append mode ([source](https://docs.airbyte.com/platform/using-airbyte/core-concepts/sync-modes/incremental-append#inclusive-cursors)). Deduplication downstream is recommended if you want to avoid processing the same records multiple times.
a
@kapa.ai so along with max cursor value? what else is tracked? does it track all the records having max cursor values? also how many such records are tracked?
k
A message from kapa.ai
Airbyte’s documentation states that, for incremental syncs, Airbyte tracks the maximum cursor value from each sync to use as the starting point for the next sync. This is explicitly mentioned for both the general incremental sync logic and specific connectors like Snowflake and BigQuery: > "Tracks state: Stores the maximum cursor value from each sync to use as the starting point for the next sync" > [Snowflake Source: Incremental Sync](https://docs.airbyte.com/integrations/sources/snowflake#incremental-sync) > "State management: Tracks the maximum cursor value from each sync for resumability" > [BigQuery Source: Supported Sync Modes](https://docs.airbyte.com/integrations/sources/bigquery#supported-sync-modes) The documentation does not state that Airbyte tracks all records having the max cursor value, nor does it mention tracking how many such records exist. Only the maximum cursor value itself is stored and used for the next sync. This means that if multiple records share the same max cursor value, Airbyte does not keep a list of all those records; it simply uses the max value as the lower bound (inclusive) for the next sync. As a result, if new records are added with the same cursor value, or if there are multiple records with the same cursor value as the last max, those records may be re-synced in subsequent runs due to the use of the
>=
operator [see Inclusive Cursors](https://docs.airbyte.com/platform/using-airbyte/core-concepts/sync-modes/incremental-append#inclusive-cursors). In summary: - Airbyte tracks only the maximum cursor value, not all records with that value. - The number of records with the max cursor value is not tracked. - This can lead to re-syncing of records with the same cursor value in subsequent syncs. If you need to avoid re-processing such records, deduplication should be handled downstream.
a
@kapa.ai then if all 4 including bob and carol are synced then for initial state: | id | name | updated_at | |----|-------|----------------------| | 1 | Alice | 2024-06-01T100000Z | | 2 | Bob | 2024-06-01T110000Z | | 3 | Carol | 2024-06-01T120000Z | After first sync New records added. | id | name | updated_at | |----|--------|----------------------| | 4 | Dave | 2024-06-01T130000Z | | 5 | Emma | 2024-06-01T140000Z | as it tracks only max cursor value, Here as well.. 3 records carol, dave, emma should be synced and not just dave and emma. right?
k
A message from kapa.ai
Yes, you are correct. Based on Airbyte's documented behavior, since Airbyte only tracks the maximum cursor value (not all records with that value), in your scenario, the next incremental sync will include all records with an
updated_at
value equal to or greater than the last synced max cursor value
. Given your example: Initial state after first sync: | id | name | updated_at | |----|-------|----------------------| | 1 | Alice | 2024-06-01T100000Z | | 2 | Bob | 2024-06-01T110000Z | | 3 | Carol | 2024-06-01T120000Z | After first sync, new records added: | id | name | updated_at | |----|--------|----------------------| | 4 | Dave | 2024-06-01T130000Z | | 5 | Emma | 2024-06-01T140000Z | The last synced max cursor value is
2024-06-01T12:00:00Z
(Carol). The next sync will run:
Copy code
sql SELECT * FROM table WHERE updated_at >= '2024-06-01T12:00:00Z'
So, it will include: - Carol (
2024-06-01T12:00:00Z
) - Dave (
2024-06-01T13:00:00Z
) - Emma (
2024-06-01T14:00:00Z
) Bob will not be included because his
updated_at
is
2024-06-01T11:00:00Z
, which is less than the last max. This matches the documented behavior that Airbyte only tracks the max cursor value, and all records with that value or higher will be included in the next sync, potentially resulting in re-syncing records with the same cursor value as the previous max [see Inclusive Cursors](https://docs.airbyte.com/platform/using-airbyte/core-concepts/sync-modes/incremental-append#inclusive-cursors).