Class 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 Detail

      • RowToBsonDocumentConverter

        public RowToBsonDocumentConverter​(StructType schema,
                                          WriteConfig.ConvertJson convertJson,
                                          boolean ignoreNulls)
        Construct a new instance
        Parameters:
        schema - the schema for the row
        convertJson - the convert Json configuration
        ignoreNulls - if true ignore any null values, even those in arrays, maps or struct values
    • Method Detail

      • fromRow

        public org.bson.BsonDocument fromRow​(org.apache.spark.sql.catalyst.InternalRow row)
        Converts a InternalRow to a BsonDocument
        Parameters:
        row - the internal row to convert
        Returns:
        a BsonDocument representing the data in the row
        Throws:
        DataException - if the Row is not convertable to a BsonDocument
      • fromRow

        public org.bson.BsonDocument fromRow​(Row row)
        Converts a Row to a BsonDocument
        Parameters:
        row - the row to convert
        Returns:
        a BsonDocument representing the data in the row
        Throws:
        DataException - if the Row is not convertable to a BsonDocument
      • createObjectToBsonValue

        public static RowToBsonDocumentConverter.ObjectToBsonValue createObjectToBsonValue​(DataType dataType,
                                                                                           WriteConfig.ConvertJson convertJson,
                                                                                           boolean ignoreNulls)
        Returns a conversion function that converts an object to a BsonValue
        Parameters:
        dataType - the data type of the object
        convertJson - the string json conversion setting
        ignoreNulls - true if ignoring null values
        Returns:
        a serializable function converts an object to a BsonValue