Class BsonDocumentToRowConverter
- java.lang.Object
-
- com.mongodb.spark.sql.connector.schema.BsonDocumentToRowConverter
-
- All Implemented Interfaces:
java.io.Serializable
@NotNull public final class BsonDocumentToRowConverter extends java.lang.Object implements java.io.Serializable
The helper for conversion of BsonDocuments to GenericRowWithSchema instances.All Bson types are considered convertible to Spark types. For any Bson types that doesn't have a direct conversion to a Spark type then a String type will be used.
When a
DataType
is provided by Spark, the conversion process will try to convert the Bson type into the declaredDataType
.- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description BsonDocumentToRowConverter()
Create a new instance with the default json writer settingsBsonDocumentToRowConverter(StructType schema)
Create a new instance with the default json writer settings
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description StructType
getSchema()
org.apache.spark.sql.catalyst.InternalRow
toInternalRow(org.bson.BsonDocument bsonDocument)
Converts aBsonDocument
into aInternalRow
.java.lang.String
toString()
-
-
-
Constructor Detail
-
BsonDocumentToRowConverter
@TestOnly public BsonDocumentToRowConverter()
Create a new instance with the default json writer settings
-
BsonDocumentToRowConverter
public BsonDocumentToRowConverter(StructType schema)
Create a new instance with the default json writer settings- Parameters:
schema
- the schema for the row
-
-
Method Detail
-
getSchema
public StructType getSchema()
- Returns:
- the schema for the converter
-
toInternalRow
public org.apache.spark.sql.catalyst.InternalRow toInternalRow(org.bson.BsonDocument bsonDocument)
Converts aBsonDocument
into aInternalRow
. Uses the BSON types of values in thebsonDocument
to determine theStructType
- Parameters:
bsonDocument
- the bson document to shape into an InternalRow.- Returns:
- the converted data as a Row
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-