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(StructType schema, boolean outputExtendedJson)
Create a new instance
-
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
public BsonDocumentToRowConverter(StructType schema, boolean outputExtendedJson)
Create a new instance- Parameters:
schema
- the schema for the rowoutputExtendedJson
- if true will produce extended JSON for any fields that have the String datatype.
-
-
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
-
-