Class CarpetWriter<T>

java.lang.Object
com.jerolba.carpet.CarpetWriter<T>
Type Parameters:
T - The type of records to write.
All Implemented Interfaces:
Closeable, AutoCloseable, Consumer<T>

public class CarpetWriter<T> extends Object implements Closeable, Consumer<T>
A Parquet file writer for writing java records of type T to a file or output stream. The writer is also a consumer that can be used with Java 8 streams. Creates a ParquetWriter with this configuration:

 .withWriteMode(Mode.OVERWRITE)
 .withCompressionCodec(CompressionCodecName.SNAPPY)

 
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static class 
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    CarpetWriter(OutputStream outputSrream, Class<T> recordClass)
    Constructs a CarpetWriter that writes records of type T to the specified OutputStream.
    CarpetWriter(org.apache.parquet.io.OutputFile outputFile, Class<T> recordClass)
    Constructs a CarpetWriter that writes records of type T to the specified OutputFile.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    accept(T value)
    Writes the specified Java object to a Parquet file implementing Consumer
    void
     
    void
    write(Collection<T> collection)
    Writes the specified collection of Java objects to a Parquet file.
    void
    write(Stream<T> stream)
    Writes the specified stream of Java objects to a Parquet file.
    void
    write(T value)
    Writes the specified Java object to a Parquet file

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface java.util.function.Consumer

    andThen
  • Constructor Details

    • CarpetWriter

      public CarpetWriter(org.apache.parquet.io.OutputFile outputFile, Class<T> recordClass) throws IOException
      Constructs a CarpetWriter that writes records of type T to the specified OutputFile.
      Parameters:
      outputFile - The output file to write to.
      recordClass - The class of the records to write.
      Throws:
      IOException - If an I/O error occurs while creating the Parquet writer.
    • CarpetWriter

      public CarpetWriter(OutputStream outputSrream, Class<T> recordClass) throws IOException
      Constructs a CarpetWriter that writes records of type T to the specified OutputStream.
      Parameters:
      outputSrream - An OutputStream to write to, of any type.
      recordClass - The class of the records to write.
      Throws:
      IOException - If an I/O error occurs while creating the Parquet writer.
  • Method Details

    • write

      public void write(Collection<T> collection) throws IOException
      Writes the specified collection of Java objects to a Parquet file.
      Parameters:
      collection - the collection of objects to write
      Throws:
      IOException - if an error occurs while writing the records
    • write

      public void write(T value) throws IOException
      Writes the specified Java object to a Parquet file
      Parameters:
      value - object to write
      Throws:
      IOException - if an error occurs while writing the records
    • accept

      public void accept(T value)
      Writes the specified Java object to a Parquet file implementing Consumer
      Specified by:
      accept in interface Consumer<T>
      Parameters:
      value - object to write
      Throws:
      UncheckedIOException - if an error occurs while writing the records
    • write

      public void write(Stream<T> stream) throws IOException
      Writes the specified stream of Java objects to a Parquet file.
      Parameters:
      stream - the stream of objects to write
      Throws:
      IOException - if an error occurs while writing the records
    • close

      public void close() throws IOException
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Throws:
      IOException