30.2. Adding a Parquet File to a Local Storage #

Consider a scenario where the data already exists as a Parquet file and must be loaded to a local storage for analytical queries.

To prepare the environment for this scenario:

Note

If you already have a Parquet file and a local storage configured, skip these steps.

  1. Create directories for Parquet files and grant write access to the operating system user on behalf of whom the Postgres Pro DBMS runs.

    These directories store Parquet files of analytical tables and are required to create a local storage.

    Example 30.7. 

      sudo -u postgres mkdir -p /tmp/my_storage /tmp/my_storage/tmp_mystorage /tmp/my_storage/data
      sudo chown -R postgres:postgres /tmp/my_storage
    

  2. Create a local storage.

    Example 30.8. 

      SELECT metastore.add_storage(
          'my_storage',
          'file:///tmp/my_storage/',
          'file:///tmp/my_storage/tmp_mystorage/'
      );
    

  3. Place a Parquet file to the local storage or create a Parquet file by exporting the data from a heap table.

    Example 30.9. 

      COPY my_table TO '/tmp/my_storage/data/data.parquet' (FORMAT PARQUET);
    

To configure this scenario:

  1. Create an analytical table from the Parquet file.

    Postgres Pro AXE uses analytical tables to register the data in the metadata catalog.

    Example 30.10. 

      SELECT metastore.add_table(
          'analytic_table_from_parquet',
          'my_storage',
          'file:///tmp/my_storage/data/data.parquet',
          ''
      );
    

  2. Create a shared directory.

    The shared directory specifies the path to the Parquet file to be added to the analytical table.

    Example 30.11. 

      SELECT metastore.add_folder(
          'src_folder',
          'my_storage',
          'data/'
      );
    

  3. Add the Parquet file to the analytical table.

    When you add the file, it is registered in the metadata catalog.

    Example 30.12. 

      SELECT metastore.add_files(
          'analytic_table_from_parquet',
          'src_folder/data.parquet'
      );
    

  4. Create a Postgres Pro view for the analytical table.

    When you create the view, the data becomes available for analytical queries through this view.

    Example 30.13. 

      SELECT metastore.create_view('analytic_table_from_parquet');
      SELECT * FROM analytic_table_from_parquet;