Skip to content

Commit 70afb9d

Browse files
authored
[Source-mongodb] : Populate null values in airbyte record message (#37348)
1 parent c9f4ad4 commit 70afb9d

File tree

5 files changed

+14
-4
lines changed

5 files changed

+14
-4
lines changed

airbyte-integrations/connectors/source-mongodb-v2/build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ plugins {
33
}
44

55
airbyteJavaConnector {
6-
cdkVersionRequired = '0.29.2'
6+
cdkVersionRequired = '0.30.4'
77
features = ['db-sources', 'datastore-mongo']
88
useLocalCdk = false
99
}

airbyte-integrations/connectors/source-mongodb-v2/metadata.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ data:
88
connectorSubtype: database
99
connectorType: source
1010
definitionId: b2e713cd-cc36-4c0a-b5bd-b47cb8a0561e
11-
dockerImageTag: 1.3.3
11+
dockerImageTag: 1.3.4
1212
dockerRepository: airbyte/source-mongodb-v2
1313
documentationUrl: https://docs.airbyte.com/integrations/sources/mongodb-v2
1414
githubIssueLabel: source-mongodb-v2

airbyte-integrations/connectors/source-mongodb-v2/src/main/java/io/airbyte/integrations/source/mongodb/cdc/MongoDbCdcEventUtils.java

+6
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,7 @@ private static ObjectNode readField(final BsonReader reader,
248248
case JAVASCRIPT -> o.put(fieldName, reader.readJavaScript());
249249
case JAVASCRIPT_WITH_SCOPE -> readJavaScriptWithScope(o, reader, fieldName);
250250
case REGULAR_EXPRESSION -> o.put(fieldName, readRegularExpression(reader.readRegularExpression()));
251+
case NULL -> readNull(o, reader, fieldName);
251252
default -> reader.skipValue();
252253
}
253254

@@ -289,6 +290,11 @@ private static byte[] toByteArray(final BsonBinary value) {
289290
return value == null ? null : value.getData();
290291
}
291292

293+
private static void readNull(final ObjectNode o, final BsonReader reader, final String fieldName) {
294+
o.putNull(fieldName);
295+
reader.readNull();
296+
}
297+
292298
private static void readJavaScriptWithScope(final ObjectNode o, final BsonReader reader, final String fieldName) {
293299
final var code = reader.readJavaScriptWithScope();
294300
final var scope = readDocument(reader, (ObjectNode) Jsons.jsonNode(Collections.emptyMap()), Set.of("scope"), false);

airbyte-integrations/connectors/source-mongodb-v2/src/test/java/io/airbyte/integrations/source/mongodb/cdc/MongoDbCdcEventUtilsTest.java

+5-2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import static org.junit.jupiter.api.Assertions.assertTrue;
1818

1919
import com.fasterxml.jackson.databind.JsonNode;
20+
import com.fasterxml.jackson.databind.node.JsonNodeType;
2021
import com.fasterxml.jackson.databind.node.ObjectNode;
2122
import io.airbyte.cdk.db.DataTypeUtils;
2223
import io.airbyte.commons.json.Jsons;
@@ -150,7 +151,8 @@ void testTransformDataTypes() {
150151
assertEquals("code2", transformed.get("field13").get("code").asText());
151152
assertEquals("scope", transformed.get("field13").get("scope").get("scope").asText());
152153
assertEquals("pattern", transformed.get("field14").asText());
153-
assertFalse(transformed.has("field15"));
154+
assertTrue(transformed.has("field15"));
155+
assertEquals(JsonNodeType.NULL, transformed.get("field15").getNodeType());
154156
assertEquals("value", transformed.get("field16").get("key").asText());
155157
// Assert that UUIDs can be serialized. Currently, they will be represented as base 64 encoded
156158
// strings. Since the original mongo source
@@ -247,7 +249,8 @@ void testTransformDataTypesNoSchema() {
247249
assertTrue(abDataNode.has("field12"));
248250
assertTrue(abDataNode.has("field13"));
249251
assertTrue(abDataNode.has("field14"));
250-
assertFalse(abDataNode.has("field15"));
252+
assertTrue(abDataNode.has("field15"));
253+
assertEquals(JsonNodeType.NULL, abDataNode.get("field15").getNodeType());
251254
assertTrue(abDataNode.has("field16"));
252255
}
253256

docs/integrations/sources/mongodb-v2.md

+1
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@ For more information regarding configuration parameters, please see [MongoDb Doc
221221

222222
| Version | Date | Pull Request | Subject |
223223
|:--------|:-----------|:---------------------------------------------------------|:----------------------------------------------------------------------------------------------------------|
224+
| 1.3.4 | 2024-04-16 | [37348](https://github.com/airbytehq/airbyte/pull/37348) | Populate null values in airbyte record messages. |
224225
| 1.3.3 | 2024-04-05 | [36872](https://github.com/airbytehq/airbyte/pull/36872) | Update to connector's metadat definition. |
225226
| 1.3.2 | 2024-04-04 | [36845](https://github.com/airbytehq/airbyte/pull/36845) | Adopt Kotlin CDK. |
226227
| 1.3.1 | 2024-04-04 | [36837](https://github.com/airbytehq/airbyte/pull/36837) | Adopt CDK 0.28.0. |

0 commit comments

Comments
 (0)