Class RowToBsonDocumentConverter
- java.lang.Object
-
- com.mongodb.spark.sql.connector.schema.RowToBsonDocumentConverter
-
- All Implemented Interfaces:
java.io.Serializable
@NotNull public final class RowToBsonDocumentConverter extends java.lang.Object implements java.io.Serializable
The helper for conversion of GenericRowWithSchema instances to BsonDocuments.All Spark types are considered convertible to Bson types.
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
RowToBsonDocumentConverter.ObjectToBsonValue
A serializableFunction<Object, BsonValue>
interface.
-
Constructor Summary
Constructors Constructor Description RowToBsonDocumentConverter(StructType schema, WriteConfig.ConvertJson convertJson, boolean ignoreNulls)
Construct a new instance
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static RowToBsonDocumentConverter.ObjectToBsonValue
createObjectToBsonValue(DataType dataType, WriteConfig.ConvertJson convertJson, boolean ignoreNulls)
Returns a conversion function that converts an object to a BsonValueorg.bson.BsonDocument
fromRow(org.apache.spark.sql.catalyst.InternalRow row)
Converts aInternalRow
to aBsonDocument
org.bson.BsonDocument
fromRow(Row row)
Converts aRow
to aBsonDocument
-
-
-
Constructor Detail
-
RowToBsonDocumentConverter
public RowToBsonDocumentConverter(StructType schema, WriteConfig.ConvertJson convertJson, boolean ignoreNulls)
Construct a new instance- Parameters:
schema
- the schema for the rowconvertJson
- the convert Json configurationignoreNulls
- if true ignore any null values, even those in arrays, maps or struct values
-
-
Method Detail
-
fromRow
public org.bson.BsonDocument fromRow(org.apache.spark.sql.catalyst.InternalRow row)
Converts aInternalRow
to aBsonDocument
- Parameters:
row
- the internal row to convert- Returns:
- a BsonDocument representing the data in the row
- Throws:
DataException
- if theRow
is not convertable to aBsonDocument
-
fromRow
public org.bson.BsonDocument fromRow(Row row)
Converts aRow
to aBsonDocument
- Parameters:
row
- the row to convert- Returns:
- a BsonDocument representing the data in the row
- Throws:
DataException
- if theRow
is not convertable to aBsonDocument
-
createObjectToBsonValue
public static RowToBsonDocumentConverter.ObjectToBsonValue createObjectToBsonValue(DataType dataType, WriteConfig.ConvertJson convertJson, boolean ignoreNulls)
Returns a conversion function that converts an object to a BsonValue- Parameters:
dataType
- the data type of the objectconvertJson
- the string json conversion settingignoreNulls
- true if ignoring null values- Returns:
- a serializable function converts an object to a BsonValue
-
-