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

🐛 Source Relational DB : remove unicode nulls from cursors #13854

Merged
merged 3 commits into from
Jun 17, 2022
Merged
Show file tree
Hide file tree
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 @@ -16,5 +16,5 @@ ENV APPLICATION source-relational-db

COPY --from=build /airbyte /airbyte

LABEL io.airbyte.version=0.3.0
LABEL io.airbyte.version=0.3.1
LABEL io.airbyte.name=airbyte/source-relational-db
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,17 @@ public StateDecoratingIterator(final Iterator<AirbyteMessage> messageIterator,
stateManager.setIsCdc(false);
}

private String getCursorCandidate(final AirbyteMessage message) {
String cursorCandidate = message.getRecord().getData().get(cursorField).asText();
return (cursorCandidate != null ? cursorCandidate.replaceAll("\u0000", "") : null);
}

@Override
protected AirbyteMessage computeNext() {
if (messageIterator.hasNext()) {
final AirbyteMessage message = messageIterator.next();
if (message.getRecord().getData().hasNonNull(cursorField)) {
final String cursorCandidate = message.getRecord().getData().get(cursorField).asText();
final String cursorCandidate = getCursorCandidate(message);
if (IncrementalUtils.compareCursors(maxCursor, cursorCandidate, cursorType) < 0) {
maxCursor = cursorCandidate;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ class StateDecoratingIteratorTest {
.withRecord(new AirbyteRecordMessage()
.withData(Jsons.jsonNode(ImmutableMap.of(UUID_FIELD_NAME, "def"))));

private static final AirbyteMessage RECORD_MESSAGE3 = new AirbyteMessage()
.withType(Type.RECORD)
.withRecord(new AirbyteRecordMessage()
.withData(Jsons.jsonNode(ImmutableMap.of(UUID_FIELD_NAME, "abc\u0000"))));

private static Iterator<AirbyteMessage> messageIterator;
private StateManager stateManager;
private AirbyteStateMessage stateMessage;
Expand Down Expand Up @@ -130,4 +135,22 @@ void testEmptyStream() {
assertFalse(iterator.hasNext());
}

@Test
void testUnicodeNull() {
messageIterator = MoreIterators.of(RECORD_MESSAGE3);
when(stateManager.updateAndEmit(NAME_NAMESPACE_PAIR, "abc")).thenReturn(stateMessage);

final StateDecoratingIterator iterator = new StateDecoratingIterator(
messageIterator,
stateManager,
NAME_NAMESPACE_PAIR,
UUID_FIELD_NAME,
null,
JsonSchemaPrimitive.STRING);

assertEquals(RECORD_MESSAGE3, iterator.next());
assertEquals(stateMessage, iterator.next().getState());
assertFalse(iterator.hasNext());
}

}