Class CarpetReader<T>

java.lang.Object
com.jerolba.carpet.CarpetReader<T>
Type Parameters:
T - The type of the records being read.
All Implemented Interfaces:
Iterable<T>

public class CarpetReader<T> extends Object implements Iterable<T>
CarpetReader wraps the creation of CarpetParquetReader CarpetReader is an Iterable and Streamable class that can be used to read a Parquet file and iterate over its records.
  • Constructor Details

    • CarpetReader

      public CarpetReader(org.apache.parquet.io.InputFile inputFile, Class<T> recordClass)
      Creates a new CarpetReader instance from the specified InputFile and record class.
      Parameters:
      inputFile - the input file from which the records will be read
      recordClass - the class of the records being read
    • CarpetReader

      public CarpetReader(File file, Class<T> recordClass)
      Creates a new CarpetReader instance from the specified File and record class.
      Parameters:
      file - the File containing the Parquet data
      recordClass - the class of the records being read
  • Method Details

    • withFailOnMissingColumn

      public CarpetReader<T> withFailOnMissingColumn(boolean value)
      Feature that determines whether encountering of missed parquet column should result in a failure (by throwing a RecordTypeConversionException) or not. Feature is enabled by default.
      Parameters:
      value - The new value for the failOnMissingColumn flag.
      Returns:
      a new instance of CarpetReader
    • withFailOnNullForPrimitives

      public CarpetReader<T> withFailOnNullForPrimitives(boolean value)
      Feature that determines whether encountering null is an error when deserializing into Java primitive types (like 'int' or 'double'). If it is, a RecordTypeConversionException is thrown to indicate this; if not, default value is used (0 for 'int', 0.0 for double, same defaulting as what JVM uses). Feature is disabled by default.
      Parameters:
      value - The new value for the failOnNullForPrimitives flag.
      Returns:
      a new instance of CarpetReader
    • withFailNarrowingPrimitiveConversion

      public CarpetReader<T> withFailNarrowingPrimitiveConversion(boolean value)
      Feature that determines whether coercion from one number type to other number type with less resolutions is allowed or not. If disabled, coercion truncates value. A narrowing primitive conversion may lose information about the overall magnitude of a numeric value and may also lose precision and range. Narrowing follows Java Language Specification Feature is disabled by default.
      Parameters:
      value -
      Returns:
      a new instance of CarpetReader
    • withFieldMatchingStrategy

      public CarpetReader<T> withFieldMatchingStrategy(FieldMatchingStrategy value)
    • iterator

      public Iterator<T> iterator()
      Returns an Iterator that can be used to iterate over the records in the Parquet file.
      Specified by:
      iterator in interface Iterable<T>
      Returns:
      an iterator for the records in the Parquet file
      Throws:
      UncheckedIOException - if an I/O error occurs
    • stream

      public Stream<T> stream()
      Returns a Stream that can be used to access the records in the Parquet file.
      Returns:
      a stream for the records in the Parquet file
      Throws:
      IOException - if an I/O error occurs
    • toList

      public List<T> toList() throws IOException
      Returns a List containing all records in the Parquet file.
      Returns:
      a list of all records in the Parquet file
      Throws:
      IOException - if an I/O error occurs