22.8. Чтение метаданных #
- 22.8.1. Получение снимка
- 22.8.2. Получение аналитических таблиц
- 22.8.3. Вывод столбцов аналитической таблицы
- 22.8.4. Вывод отфильтрованных Parquet-файлов
- 22.8.5. Получение статистики аналитических таблиц
- 22.8.6. Получение статистики столбцов аналитической таблицы
- 22.8.7. Получение статистики аналитической таблицы за определённый временной интервал
- 22.8.2. Получение аналитических таблиц
В этом разделе описывается, как читать метаданные с помощью запросов к таблицам метаданных.
22.8.1. Получение снимка #
Выполните следующую команду на сервере с каталогом метаданных:
SELECT * FROM axe_catalog.axe_snapshot WHERE snapshot_id = идентификатор_снимка;
Где идентификатор_снимка — это идентификатор снимка, который требуется получить, из таблицы метаданных axe_snapshot.
Чтобы получить самый последний снимок, выполните следующую команду на сервере с каталогом метаданных:
SELECT * FROM axe_catalog.axe_snapshot WHERE snapshot_id = (SELECT max(snapshot_id) FROM axe_catalog.axe_snapshot);
22.8.2. Получение аналитических таблиц #
Выполните следующую команду на сервере с каталогом метаданных:
SELECT table_id, table_name FROM axe_catalog.axe_table WHERE schema_id =идентификатор_схемыANDидентификатор_снимка>= begin_snapshot AND (идентификатор_снимка< end_snapshot OR end_snapshot IS NULL);
Где:
идентификатор_схемы: идентификатор схемы, содержащей аналитические таблицы, которые требуется получить, из таблицы метаданныхaxe_schema.идентификатор_снимка: идентификатор снимка, связанного с требуемым периодом времени, из таблицы метаданныхaxe_snapshot.
22.8.3. Вывод столбцов аналитической таблицы #
Выполните следующую команду на сервере с каталогом метаданных:
SELECT column_id, column_name, column_type
FROM axe_catalog.axe_column
WHERE
table_id = идентификатор_таблицы AND
идентификатор_снимка >= begin_snapshot AND
(идентификатор_снимка < end_snapshot OR end_snapshot IS NULL)
ORDER BY column_order;Где:
идентификатор_таблицы: идентификатор аналитической таблицы, содержащей столбец, который требуется получить, из таблицы метаданныхaxe_table.идентификатор_снимка: идентификатор снимка, связанного с требуемым периодом времени, из таблицы метаданныхaxe_snapshot.
22.8.4. Вывод отфильтрованных Parquet-файлов #
Получить Parquet-файлы можно после получения столбцов аналитической таблицы. Файлы можно отфильтровать с помощью статистики из таблицы метаданных axe_file_column_stats.
Выполните следующую команду на сервере с каталогом метаданных:
SELECT data_file_id
FROM axe_catalog.axe_file_column_stats
WHERE
table_id = идентификатор_таблицы AND
column_id = идентификатор_столбца AND
(скалярное_значение >= min_value OR min_value IS NULL) AND
(скалярное_значение <= max_value OR max_value IS NULL);Где:
идентификатор_таблицы: идентификатор аналитической таблицы, содержащей Parquet-файлы, которые требуется получить, из таблицы метаданныхaxe_table.идентификатор_столбца: идентификатор столбца, значения которого используются для фильтрации Parquet-файлов, из таблицы метаданныхaxe_column.скалярное_значение: значение, используемое для фильтрации Parquet-файлов. Получаются только те Parquet-файлы, диапазон значений столбцов которых включает это значение.
Значения столбцов можно фильтровать по различным условиям, например «больше чем (>)», соответствующим образом изменив команду. Минимальное и максимальное значения столбцов хранятся в виде строк, поэтому перед сравнением их необходимо преобразовать в тип данных фильтруемого столбца.
22.8.5. Получение статистики аналитических таблиц #
Выполните следующую команду на сервере с каталогом метаданных:
SELECT s1.record_count, s1.file_size_bytes FROM axe_catalog.axe_table_stats s1, axe_catalog.axe_table t1 WHERE s1.table_id = t1.table_id
AND t1.table_name='имя_таблицы';Где имя_таблицы — это имя аналитической таблицы, для которой требуется получить статистику, из таблицы метаданных axe_table.
22.8.6. Получение статистики столбцов аналитической таблицы #
Выполните следующую команду на сервере с каталогом метаданных:
SELECT c1.column_name, s1.contains_null, s1.min_value, s1.max_value
FROM axe_catalog.axe_column c1, axe_catalog.axe_table_column_stats s1, axe_catalog.axe_table t1
WHERE c1.table_id = t1.table_id AND t1.table_name = 'имя_таблицы' AND s1.column_id = c1.column_id;Где имя_таблицы — это имя аналитической таблицы, для которой требуется получить статистику столбцов, из таблицы метаданных axe_table.
22.8.7. Получение статистики аналитической таблицы за определённый временной интервал #
На сервере с каталогом метаданных получите пути к Parquet-файлам, добавленным в аналитическую таблицу за определённый временной интервал:
SELECT array_agg(t1.path) FROM axe_catalog.axe_data_file t1, axe_catalog.axe_table t2, axe_catalog.axe_snapshot t3 WHERE t1.end_snapshot IS NULL AND t1.table_id = t2.table_id AND t2.end_snapshot IS NULL AND t2.table_name = '
имя_таблицы' AND t1.begin_snapshot = t3.snapshot_id AND t3.snapshot_time > timestamptz 'начальная_дата_и_время' AND t3.snapshot_time < timestamptz 'конечная_дата_и_время';Где:
имя_таблицы: имя аналитической таблицы, для которой требуется получить Parquet-файлы, из таблицы метаданныхaxe_table.начальная_дата_и_времяиконечная_дата_и_время: начальная и конечная дата и время для получения Parquet-файлов.
На сервере Postgres Pro AXE выполните запросы к полученным Parquet-файлам, чтобы рассчитать статистику аналитической таблицы:
SELECT COUNT(*) FROM read_parquet(['
путь_к_файлу_1', 'путь_к_файлу_N']);Где
путь_к_файлу_1ипуть_к_файлу_N— это пути к полученным Parquet-файлам.
22.8. Reading Metadata #
- 22.8.1. Retrieving a Snapshot
- 22.8.2. Retrieving Analytical Tables
- 22.8.3. Retrieving Columns of an Analytical Table
- 22.8.4. Retrieving Filtered Parquet Files
- 22.8.5. Retrieving Analytical Table Statistics
- 22.8.6. Retrieving Analytical Table Column Statistics
- 22.8.7. Retrieving Analytical Table Statistics for a Specific Time Interval
- 22.8.2. Retrieving Analytical Tables
This section describes how to read metadata by querying metadata tables.
22.8.1. Retrieving a Snapshot #
Execute the following command on the server with the metadata catalog:
SELECT * FROM axe_catalog.axe_snapshot WHERE snapshot_id = snapshot_ID;
Where snapshot_ID is the ID of the snapshot that must be retrieved, from the axe_snapshot metadata table.
To retrieve the latest snapshot, execute the following command on the server with the metadata catalog:
SELECT * FROM axe_catalog.axe_snapshot WHERE snapshot_id = (SELECT max(snapshot_id) FROM axe_catalog.axe_snapshot);
22.8.2. Retrieving Analytical Tables #
Execute the following command on the server with the metadata catalog:
SELECT table_id, table_name FROM axe_catalog.axe_table WHERE schema_id =schema_IDANDsnapshot_ID>= begin_snapshot AND (snapshot_ID< end_snapshot OR end_snapshot IS NULL);
Where:
schema_ID: The ID of the schema containing the analytical tables that must be retrieved, from theaxe_schemametadata table.snapshot_ID: The ID of the snapshot associated with the required time period, from theaxe_snapshotmetadata table.
22.8.3. Retrieving Columns of an Analytical Table #
Execute the following command on the server with the metadata catalog:
SELECT column_id, column_name, column_type
FROM axe_catalog.axe_column
WHERE
table_id = table_ID AND
snapshot_ID >= begin_snapshot AND
(snapshot_ID < end_snapshot OR end_snapshot IS NULL)
ORDER BY column_order;
Where:
table_ID: The ID of the analytical table containing the column that must be retrieved, from theaxe_tablemetadata table.snapshot_ID: The ID of the snapshot associated with the required time period, from theaxe_snapshotmetadata table.
22.8.4. Retrieving Filtered Parquet Files #
You can retrieve Parquet files after retrieving columns of an analytical table. The files can be filtered using statistics from the axe_file_column_stats metadata table.
Execute the following command on the server with the metadata catalog:
SELECT data_file_id
FROM axe_catalog.axe_file_column_stats
WHERE
table_id = table_ID AND
column_id = column_ID AND
(scalar_value >= min_value OR min_value IS NULL) AND
(scalar_value <= max_value OR max_value IS NULL);
Where:
table_ID: The ID of the analytical table containing the Parquet files that must be retrieved, from theaxe_tablemetadata table.column_ID: The ID of the column whose values are used for filtering the Parquet files, from theaxe_columnmetadata table.scalar_value: The value used for filtering the Parquet files. Only Parquet files whose range of column values includes this value are retrieved.
You can filter column values using different conditions, such as "greater than (>)", by updating the command accordingly. The minimum and maximum column values are stored as strings, so they must be converted to the data type of the filtered column before comparison.
22.8.5. Retrieving Analytical Table Statistics #
Execute the following command on the server with the metadata catalog:
SELECT s1.record_count, s1.file_size_bytes FROM axe_catalog.axe_table_stats s1, axe_catalog.axe_table t1 WHERE s1.table_id = t1.table_id
AND t1.table_name='table_name';
Where table_name is the name of the analytical table for which the statistics must be retrieved, from the axe_table metadata table.
22.8.6. Retrieving Analytical Table Column Statistics #
Execute the following command on the server with the metadata catalog:
SELECT c1.column_name, s1.contains_null, s1.min_value, s1.max_value
FROM axe_catalog.axe_column c1, axe_catalog.axe_table_column_stats s1, axe_catalog.axe_table t1
WHERE c1.table_id = t1.table_id AND t1.table_name = 'table_name' AND s1.column_id = c1.column_id;
Where table_name is the name of the analytical table for which the column statistics must be retrieved, from the axe_table metadata table.
22.8.7. Retrieving Analytical Table Statistics for a Specific Time Interval #
On the server with the metadata catalog, retrieve paths to the Parquet files added to the analytical table within a specific time interval:
SELECT array_agg(t1.path) FROM axe_catalog.axe_data_file t1, axe_catalog.axe_table t2, axe_catalog.axe_snapshot t3 WHERE t1.end_snapshot IS NULL AND t1.table_id = t2.table_id AND t2.end_snapshot IS NULL AND t2.table_name = '
table_name' AND t1.begin_snapshot = t3.snapshot_id AND t3.snapshot_time > timestamptz 'start_date_and_time' AND t3.snapshot_time < timestamptz 'end_date_and_time';Where:
table_name: The name of the analytical table for which the Parquet files must be retrieved, from theaxe_tablemetadata table.start_date_and_timeandend_date_and_time: The start and end date and time for retrieving the Parquet files.
On the Postgres Pro AXE server, query the retrieved Parquet files to calculate the analytical table statistics:
SELECT COUNT(*) FROM read_parquet(['
path_to_file_1', 'path_to_file_N']);Where
path_to_file_1andpath_to_file_Nare paths to the retrieved Parquet files.