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.SerializableThe 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
DataTypeis 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 StructTypegetSchema()org.apache.spark.sql.catalyst.InternalRowtoInternalRow(org.bson.BsonDocument bsonDocument)Converts aBsonDocumentinto aInternalRow.java.lang.StringtoString()
-
-
-
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 aBsonDocumentinto aInternalRow. Uses the BSON types of values in thebsonDocumentto 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:
toStringin classjava.lang.Object
-
-