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

Ensure null values can be converted to BsonNull #89

Merged
merged 1 commit into from
Jan 4, 2023

Conversation

rozza
Copy link
Member

@rozza rozza commented Jan 3, 2023

Fixes issue saving arrays / maps containing nulls
Top level fields containing null are included when writing the document. This mirrors nulls and creating of rows.

Users should filter data containing nulls, should they not want to save that data.

SPARK-384
SPARK-351

Fixes issue saving arrays / maps containing nulls
Top level fields containing null are included when writing the document.
This mirrors nulls and creating of rows.

Users should filter data containing nulls, should they not want to save
that data.

SPARK-384
SPARK-351
@rozza rozza requested a review from jyemin January 3, 2023 16:05
@rozza
Copy link
Member Author

rozza commented Jan 3, 2023

A side effect of the fix for this ticket is that any fields with null values are now stored in MongoDB. This does mean that top level fields with null values and lists / maps containing null values behave the same.

The benefit of this is now data can fully round trip when using the connector.

Note: In 10.0.x null fields were automatically excluded and null values in lists / maps threw an error.

Copy link
Contributor

@jyemin jyemin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a question, but LGTM.

@@ -138,7 +140,7 @@ public BsonValue toBsonValue(final DataType dataType, final Object data) {
|| DataTypes.TimestampType.acceptsType(dataType)) {
return new BsonDateTime(((Date) data).getTime());
} else if (DataTypes.NullType.acceptsType(dataType)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So it wouldn't have fallen into this conditional, but instead would throw DataException below?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the case of data type Array<String> eg: ["a", null] the string value a would have been fine but it would have tried to convert a null value to string eg: new BsonString((String) data). That causes the BsonString constructor to throw an exception that is then caught and wrapped in a DataException below.

@rozza rozza merged commit 44d2913 into mongodb:main Jan 4, 2023
@rozza rozza deleted the SPARK-384 branch January 4, 2023 11:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants