3.3. Analytical Tables #
Analytical tables are sets of columns and rows with the OLAP data featuring a full history of data and table type updates.
Rows of analytical tables are stored as Parquet files in a storage. The metadata of analytical tables is stored in the pga_table metadata table.
3.3.1. Creating an Analytical Table #
Postgres Pro AXE provides the following ways of creating analytical tables:
3.3.1.1. Creating an Analytical Table from a Parquet File #
Execute the following query:
SELECT metastore.add_table('table_name', 'storage_name', 'Parquet_file_URI');
Where:
table_name: The unique analytical table name.The fully qualified name of the analytical table consists of the analytical schema and table name. It is generated in
analytical_schema_name.analytical_table_nameformat.storage_name: The name of the storage where Parquet files will be located.Parquet_file_URI: The URI of the Parquet file from which the analytical table will be created.The URI must either start with
file://ors3://.
Example 3.18.
SELECT metastore.add_table('example_table', 'example_storage', 'file:///home/user/tmp/parquet_data/t.parquet');
Once the query is executed, pgpro_metastore performs the following actions:
Verifies user privileges.
Ensures that the source of metadata of the analytical table exists.
Uses the Apache Arrow library to export information about columns from the Parquet file.
Associates the data type of each column of the analytical table with a pgpro_metastore data type.
Creates a new snapshot in the
pga_snapshotmetadata table, a new analytical table in thepga_tablemetadata table, and new columns in thepga_columnmetadata table.
3.3.1.2. Creating an Analytical Table From a Heap Table #
Execute the following query:
SELECT metastore.add_table('table_name', 'storage_name', 'heap_table_name');
Where:
table_name: The unique analytical table name.The fully qualified name of the analytical table consists of the analytical schema and table name. It is generated in
analytical_schema_name.analytical_table_nameformat.storage_name: The name of the storage where Parquet files will be located.heap_table_name: The fully qualified heap table name starting with the schema name.
Example 3.19.
SELECT metastore.add_table('example_table', 'example_storage', 'public.example_heap_table');
Once the query is executed, pgpro_metastore performs the following actions:
Verifies user privileges.
Ensures that the source of metadata of the analytical table exists.
Exports information about columns of the analytical table from the heap table by querying Postgres Pro service tables.
Associates the data type of each column with a pgpro_metastore data type.
Creates a new snapshot in the
pga_snapshotmetadata table, a new analytical table in thepga_tablemetadata table, and new columns in thepga_columnmetadata table.
3.3.2. Renaming an Analytical Table #
Execute the following query:
SELECT metastore.rename_table('schema_name.current_table_name' or 'current_table_name', 'new_table_name');
Where:
schema_name: The name of the analytical schema where the table is created.Optional parameter. If you do not specify it, the current schema is used.
current_table_name: The current analytical table name.new_table_name: The new unique analytical table name.
Example 3.20.
SELECT metastore.rename_table('testtable', 'testtable1');
Once the query is executed, pgpro_metastore performs the following actions:
Verifies user privileges.
Updates the
table_namevalue for the analytical table in thepga_tablemetadata table.Updates the
view_sqlvalue for the analytical table.
3.3.3. Creating a Postgres Pro View From an Analytical Table #
Execute the following query:
SELECT metastore.create_view('table_name', 'Postgres_Pro_schema_name');
Where:
table_name: The name of the analytical table from which the Postgres Pro view will be created.Postgres_Pro_schema_name: The name of the Postgres Pro schema associated with the view.Optional parameter. If you do not specify it, the schema is selected automatically.
Example 3.21.
SELECT metastore.create_view('example_table');
Once the query is executed, pgpro_metastore performs the following actions:
Verifies user privileges.
Receives metadata of the analytical table and the path to the shared directory.
Generates the
CREATE VIEWquery with the data source being the result of calling theread_parquet()function.Executes the
CREATE VIEWquery.Grants privileges to the Postgres Pro view.
Creates a new snapshot in the
pga_snapshotmetadata table.
3.3.4. Deleting an Analytical Table #
Execute the following query:
SELECT metastore.remove_table('table_name');
Where table_name is the name of the analytical table that will be deleted.
Example 3.22.
SELECT metastore.remove_table('example_table');
Once the query is executed, pgpro_metastore performs the following actions:
Verifies user privileges.
Creates a new snapshot in the
pga_snapshotmetadata table and specifies for the analytical table and all its associated pgpro_metastore objects theend_snapshotvalue in thepga_tablemetadata table and other metadata tables.