From 7c82190c646c4443a517536f349616336815400c Mon Sep 17 00:00:00 2001 From: Marius Grama Date: Thu, 8 Sep 2022 05:38:53 +0200 Subject: [PATCH 1/3] Break query into multiple lines --- docs/src/main/sphinx/connector/iceberg.rst | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/docs/src/main/sphinx/connector/iceberg.rst b/docs/src/main/sphinx/connector/iceberg.rst index b6a7c3855719..8922331312d6 100644 --- a/docs/src/main/sphinx/connector/iceberg.rst +++ b/docs/src/main/sphinx/connector/iceberg.rst @@ -520,7 +520,9 @@ The connector provides a system snapshots table for each Iceberg table. Snapsho identified by BIGINT snapshot IDs. You can find the latest snapshot ID for table ``customer_orders`` by running the following command:: - SELECT snapshot_id FROM iceberg.testdb."customer_orders$snapshots" ORDER BY committed_at DESC LIMIT 1 + SELECT snapshot_id + FROM iceberg.testdb."customer_orders$snapshots" + ORDER BY committed_at DESC LIMIT 1 A SQL procedure ``system.rollback_to_snapshot`` allows the caller to roll back the state of the table to a previous snapshot id:: From 2a5b0b49d1fbb5a73b9a9bcfbb337ec1d4fc8317 Mon Sep 17 00:00:00 2001 From: findinpath Date: Tue, 11 Jan 2022 12:09:35 +0100 Subject: [PATCH 2/3] Extract introduction for snapshots --- docs/src/main/sphinx/connector/iceberg.rst | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/docs/src/main/sphinx/connector/iceberg.rst b/docs/src/main/sphinx/connector/iceberg.rst index 8922331312d6..b69d463e8854 100644 --- a/docs/src/main/sphinx/connector/iceberg.rst +++ b/docs/src/main/sphinx/connector/iceberg.rst @@ -510,15 +510,25 @@ Row level deletion Tables using v2 of the Iceberg specification support deletion of individual rows by writing position delete files. -Rolling back to a previous snapshot ------------------------------------ +Snapshots +--------- Iceberg supports a "snapshot" model of data, where table snapshots are -identified by an snapshot IDs. +identified by a snapshot ID. + +The connector provides a system table exposing snapshot information for every +Iceberg table. Snapshots are identified by ``BIGINT`` snapshot IDs. +For example, you could find the snapshot IDs for the ``customer_orders`` table +by running the following query:: + + SELECT snapshot_id + FROM iceberg.testdb."customer_orders$snapshots" + ORDER BY committed_at DESC + +Rolling back to a previous snapshot +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -The connector provides a system snapshots table for each Iceberg table. Snapshots are -identified by BIGINT snapshot IDs. You can find the latest snapshot ID for table -``customer_orders`` by running the following command:: +Use the ``$snapshots`` metadata table to determine the latest snapshot ID of the table like in the following query:: SELECT snapshot_id FROM iceberg.testdb."customer_orders$snapshots" From 4210d7355f9a2640d19a1dfe8c4741a370c16929 Mon Sep 17 00:00:00 2001 From: findinpath Date: Mon, 10 Jan 2022 11:36:40 +0100 Subject: [PATCH 3/3] Document time travel queries --- docs/src/main/sphinx/connector/iceberg.rst | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/docs/src/main/sphinx/connector/iceberg.rst b/docs/src/main/sphinx/connector/iceberg.rst index b69d463e8854..a0514d27f95c 100644 --- a/docs/src/main/sphinx/connector/iceberg.rst +++ b/docs/src/main/sphinx/connector/iceberg.rst @@ -525,6 +525,28 @@ by running the following query:: FROM iceberg.testdb."customer_orders$snapshots" ORDER BY committed_at DESC +Time travel queries +^^^^^^^^^^^^^^^^^^^ + +The connector offers the ability to query historical data. +This allows you to query the table as it was when a previous snapshot +of the table was taken, even if the data has since been modified or deleted. + +The historical data of the table can be retrieved by specifying the +snapshot identifier corresponding to the version of the table that +needs to be retrieved:: + + SELECT * + FROM iceberg.testdb.customer_orders FOR VERSION AS OF 8954597067493422955 + +A different approach of retrieving historical data is to specify +a point in time in the past, such as a day or week ago. The latest snapshot +of the table taken before or at the specified timestamp in the query is +internally used for providing the previous state of the table:: + + SELECT * + FROM iceberg.testdb.customer_orders FOR TIMESTAMP AS OF TIMESTAMP '2022-03-23 09:59:29.803 Europe/Vienna' + Rolling back to a previous snapshot ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^