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
-
-
Constructor Summary
Constructors Constructor Description RowToBsonDocumentConverter()
Construct a new instanceRowToBsonDocumentConverter(StructType schema)
Construct a new instance
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description org.bson.BsonDocument
fromRow(org.apache.spark.sql.catalyst.InternalRow row)
Converts aRow
to aBsonDocument
org.bson.BsonDocument
fromRow(Row row)
Converts aRow
to aBsonDocument
static org.bson.BsonValue
toBsonValue(DataType dataType, java.lang.Object data)
Converts data to a bson value that the data type represents
-
-
-
Constructor Detail
-
RowToBsonDocumentConverter
@TestOnly public RowToBsonDocumentConverter()
Construct a new instance
-
RowToBsonDocumentConverter
public RowToBsonDocumentConverter(StructType schema)
Construct a new instance- Parameters:
schema
- the schema for the row
-
-
Method Detail
-
fromRow
public org.bson.BsonDocument fromRow(org.apache.spark.sql.catalyst.InternalRow row)
Converts aRow
to aBsonDocument
- Parameters:
row
- the row to convert- Returns:
- a BsonDocument representing the data in the row
- Throws:
DataException
- if theRow
does not have a schema associated with it
-
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
does not have a schema associated with it
-
toBsonValue
public static org.bson.BsonValue toBsonValue(DataType dataType, java.lang.Object data)
Converts data to a bson value that the data type represents- Parameters:
dataType
- the data typedata
- the data- Returns:
- the bsonValue
-
-