Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion presto-docs/src/main/sphinx/connector/iceberg.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2224,7 +2224,7 @@ Querying branches and tags

Iceberg supports branches and tags which are named references to snapshots.

Query Iceberg table by specifying the branch name:
Query Iceberg table by specifying the branch name using ``FOR SYSTEM_VERSION AS OF``:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (typo): Consider adding an article for grammatical correctness ("Query an Iceberg table").

Suggested wording: Query an Iceberg table by specifying the branch name using FOR SYSTEM_VERSION AS OF:

Suggested change
Query Iceberg table by specifying the branch name using ``FOR SYSTEM_VERSION AS OF``:
Query an Iceberg table by specifying the branch name using ``FOR SYSTEM_VERSION AS OF``:


.. code-block:: sql

Expand All @@ -2239,6 +2239,21 @@ Query Iceberg table by specifying the branch name:
30 | mexico | 3 | comment
(3 rows)

Alternatively, you can query a branch using the dot notation syntax with quoted identifiers:

.. code-block:: sql

SELECT * FROM "nation.branch_testBranch";

.. code-block:: text

nationkey | name | regionkey | comment
-----------+---------------+-----------+---------
10 | united states | 1 | comment
20 | canada | 2 | comment
30 | mexico | 3 | comment
(3 rows)

Query Iceberg table by specifying the tag name:

.. code-block:: sql
Expand All @@ -2253,6 +2268,8 @@ Query Iceberg table by specifying the tag name:
20 | canada | 2 | comment
(3 rows)

**Note:** The dot notation syntax ``"<table>.branch_<branch_name>"`` requires double quotes to prevent the SQL parser from interpreting the dot as a schema.table separator. This syntax works for both querying (SELECT) and mutating (INSERT, UPDATE, DELETE, MERGE) branch data.

Mutating Iceberg Branches
^^^^^^^^^^^^^^^^^^^^^^^^^

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2432,6 +2432,30 @@ public void testRefsTable()
assertQuery("SELECT * FROM test_table_references FOR SYSTEM_VERSION AS OF 'testTag' where id1=1", "VALUES(1, NULL)");
}

@Test
public void testQueryBranch()
{
assertUpdate("CREATE TABLE test_branch_dot_notation (id BIGINT, name VARCHAR, value BIGINT)");
assertUpdate("INSERT INTO test_branch_dot_notation VALUES (1, 'Alice', 100), (2, 'Bob', 200)", 2);
Table icebergTable = loadTable("test_branch_dot_notation");
icebergTable.manageSnapshots().createBranch("audit_branch").commit();
assertUpdate("INSERT INTO test_branch_dot_notation VALUES (3, 'Charlie', 300), (4, 'David', 400)", 2);
// Test querying branch using FOR SYSTEM_VERSION AS OF syntax
assertQuery("SELECT count(*) FROM test_branch_dot_notation FOR SYSTEM_VERSION AS OF 'audit_branch'", "VALUES 2");
assertQuery("SELECT count(*) FROM test_branch_dot_notation FOR SYSTEM_VERSION AS OF 'main'", "VALUES 4");
// Test querying branch using dot notation syntax
assertQuery("SELECT count(*) FROM \"test_branch_dot_notation.branch_audit_branch\"", "VALUES 2");
assertQuery("SELECT id, name, value FROM \"test_branch_dot_notation.branch_audit_branch\" ORDER BY id",
"VALUES (1, 'Alice', 100), (2, 'Bob', 200)");
// Verify both syntaxes return the same results by comparing actual results
MaterializedResult resultWithForSyntax = computeActual("SELECT id FROM test_branch_dot_notation FOR SYSTEM_VERSION AS OF 'audit_branch' ORDER BY id");
MaterializedResult resultWithDotNotation = computeActual("SELECT id FROM \"test_branch_dot_notation.branch_audit_branch\" ORDER BY id");
assertEquals(resultWithForSyntax, resultWithDotNotation);
// Test that main table has all records
assertQuery("SELECT count(*) FROM test_branch_dot_notation", "VALUES 4");
assertQuerySucceeds("DROP TABLE test_branch_dot_notation");
}

@Test
public void testMetadataLogTable()
{
Expand Down
Loading