Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename maxCursor and add comment #18570

Merged
merged 3 commits into from
Oct 30, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ public class StateDecoratingIterator extends AbstractIterator<AirbyteMessage> im
private final JsonSchemaPrimitive cursorType;

private final String initialCursor;
private String maxCursor;
private long maxCursorRecordCount = 0L;
private String currentMaxCursor;
private long currentMaxCursorRecordCount = 0L;
private boolean hasEmittedFinalState;

/**
Expand Down Expand Up @@ -82,7 +82,7 @@ public StateDecoratingIterator(final Iterator<AirbyteMessage> messageIterator,
this.cursorField = cursorField;
this.cursorType = cursorType;
this.initialCursor = initialCursor;
this.maxCursor = initialCursor;
this.currentMaxCursor = initialCursor;
this.stateEmissionFrequency = stateEmissionFrequency;
}

Expand Down Expand Up @@ -126,17 +126,18 @@ protected AirbyteMessage computeNext() {
final AirbyteMessage message = messageIterator.next();
if (message.getRecord().getData().hasNonNull(cursorField)) {
final String cursorCandidate = getCursorCandidate(message);
final int cursorComparison = IncrementalUtils.compareCursors(maxCursor, cursorCandidate, cursorType);
final int cursorComparison = IncrementalUtils.compareCursors(currentMaxCursor, cursorCandidate, cursorType);
if (cursorComparison < 0) {
if (stateEmissionFrequency > 0 && !Objects.equals(maxCursor, initialCursor) && messageIterator.hasNext()) {
// Update the current max cursor only when current max cursor < cursor candidate from the message
if (stateEmissionFrequency > 0 && !Objects.equals(currentMaxCursor, initialCursor) && messageIterator.hasNext()) {
// Only emit an intermediate state when it is not the first or last record message,
// because the last state message will be taken care of in a different branch.
intermediateStateMessage = createStateMessage(false);
}
maxCursor = cursorCandidate;
maxCursorRecordCount = 1L;
currentMaxCursor = cursorCandidate;
currentMaxCursorRecordCount = 1L;
} else if (cursorComparison == 0) {
maxCursorRecordCount++;
currentMaxCursorRecordCount++;
}
}

Expand Down Expand Up @@ -188,7 +189,7 @@ protected final Optional<AirbyteMessage> getIntermediateMessage() {
* @return AirbyteMessage which includes information on state of records read so far
*/
public AirbyteMessage createStateMessage(final boolean isFinalState) {
final AirbyteStateMessage stateMessage = stateManager.updateAndEmit(pair, maxCursor, maxCursorRecordCount);
final AirbyteStateMessage stateMessage = stateManager.updateAndEmit(pair, currentMaxCursor, currentMaxCursorRecordCount);
final Optional<CursorInfo> cursorInfo = stateManager.getCursorInfo(pair);
LOGGER.info("State report for stream {} - original: {} = {} (count {}) -> latest: {} = {} (count {})",
pair,
Expand Down