java.lang.Object
org.odpi.openmetadata.adapters.connectors.datastore.parquetfile.data.ParquetDataReader
All Implemented Interfaces:
AutoCloseable

public class ParquetDataReader extends Object implements AutoCloseable
ParquetDataReader retrieves the values stored in a Parquet file.

Reading the values in a Parquet file means supporting every version of the data page layout, every encoding and every compression algorithm. Rather than implement these, or add the Apache Parquet libraries (and the Apache Hadoop libraries they depend on), this class passes the work to DuckDB, which has a complete implementation of the Parquet format built in to its JDBC driver.

DuckDB is only called through the standard java.sql interfaces. This means there is no compile time dependency on DuckDB, and the rest of the Parquet connector works without it. The DuckDB JDBC driver needs to be on the class path for this class to work. It is included in the OMAG Server Platform.

The DuckDB database is a private, in-memory, database that is only used to run queries against the file. Nothing is stored in it.
  • Constructor Details

    • ParquetDataReader

      public ParquetDataReader()
      Default constructor.
  • Method Details

    • isAvailable

      public static boolean isAvailable()
      Return whether the DuckDB JDBC driver is available, and so it is possible to read values.
      Returns:
      boolean
    • readRow

      public List<String> readRow(String fileName, long rowNumber) throws SQLException
      Return a row from the file.
      Parameters:
      fileName - location of the file
      rowNumber - the position of the row in the file - the first row is 0
      Returns:
      the value from each top-level column, as a string, or null if there is no such row. A null value is returned as null and a nested value uses DuckDB's string format for lists, maps and structures.
      Throws:
      SQLException - DuckDB is not available, or is not able to read the file
    • getValueCounts

      public Map<String,Long> getValueCounts(String fileName, String columnName, int maxDistinctValues) throws SQLException
      Return how many times each value occurs in a top-level column, with the most frequent value first. Nulls are not included.
      Parameters:
      fileName - location of the file
      columnName - the name of a top-level column
      maxDistinctValues - the largest number of different values to return
      Returns:
      map of value to the number of times it occurs, or null if the column has more than the maximum number of different values
      Throws:
      SQLException - DuckDB is not available, or is not able to read the file
    • close

      public void close()
      Release the DuckDB database.
      Specified by:
      close in interface AutoCloseable