Class 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 declared DataType.

    See Also:
    Serialized Form
    • 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 a BsonDocument into a InternalRow.
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • 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 a BsonDocument into a InternalRow. Uses the BSON types of values in the bsonDocument to determine the StructType
        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 class java.lang.Object