Skip to content

Conversation

codluca
Copy link
Member

@codluca codluca commented Sep 29, 2025

Set existing location for view when replacing view for Iceberg Rest catalog
Fixes #25425

Description

If replace and useUniqueTableLocation, load the existing view and reuse its location.

Additional context and related issues

Release notes

(X) This is not user-visible or is docs only, and no release notes are required.
( ) Release notes are required. Please propose a release note for me.
( ) Release notes are required, with the following suggested text:

## Section
* Fix some things. ({issue}`25425`)

@cla-bot cla-bot bot added the cla-signed label Sep 29, 2025
@github-actions github-actions bot added the iceberg Iceberg connector label Sep 29, 2025
Copy link
Member

@ebyhr ebyhr left a comment

Choose a reason for hiding this comment

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

Please update the test and shorten the commit title: https://trino.io/development/process.html#pull-request-and-commit-guidelines-

@codluca codluca force-pushed the 25425-create-or-replace-view-unique-location-iceberg-rest branch 2 times, most recently from 1233e1b to 82b5c3b Compare September 29, 2025 07:49
@codluca
Copy link
Member Author

codluca commented Sep 29, 2025

Added a new test with useUniqueTableLocations=true and made the commit title shorter.
Thanks!

@codluca codluca force-pushed the 25425-create-or-replace-view-unique-location-iceberg-rest branch 2 times, most recently from f0c00e9 to f8f7dae Compare September 29, 2025 09:22

@Test
@Override
public void testViewUnique()
Copy link
Contributor

Choose a reason for hiding this comment

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

update name sth like testCreateReplaceViewUniqueLocation

Copy link
Member Author

Choose a reason for hiding this comment

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

update name sth like testCreateReplaceViewUniqueLocation

Fixed

ViewBuilder viewBuilder = restSessionCatalog.buildView(convert(session), toRemoteView(session, schemaViewName, true));
String tableLocation = defaultTableLocation(session, schemaViewName);
if (replace && useUniqueTableLocation) {
Optional<View> view = getIcebergView(session, schemaViewName, true);
Copy link
Contributor

Choose a reason for hiding this comment

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

will we fail to get the view if it isn't in the view cache?

Copy link
Member Author

Choose a reason for hiding this comment

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

will we fail to get the view if it isn't in the view cache?

I believe it will attempt to return from the cache, and if missing it will load it.
It reaches CacheUtils.uncheckedCacheGet, where it does "return cache.get(key, loader::get);"

@codluca codluca force-pushed the 25425-create-or-replace-view-unique-location-iceberg-rest branch from 17f408d to 30ffe4c Compare October 3, 2025 14:38
try {
catalog.dropNamespace(SESSION, namespace);
}
catch (Exception e) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove this

Copy link
Member Author

Choose a reason for hiding this comment

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

Removed

.doesNotContain(renamedSchemaTableName);
}
finally {
try {
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove this try catch

Copy link
Member Author

Choose a reason for hiding this comment

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

Removed

String namespace = "test_create_view_" + randomNameSuffix();
String viewName = "viewName";
String renamedViewName = "renamedViewName";
SchemaTableName schemaTableName = new SchemaTableName(namespace, viewName);
Copy link
Contributor

Choose a reason for hiding this comment

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

Where is the logic to check the location is the same before and after the "create or replace"

Copy link
Member Author

Choose a reason for hiding this comment

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

Couldn't find a way to get the view location, as that is a property from apache iceberg view (org.apache.iceberg.view).
Moved the test to TestTrinoRestCatalog, where I could inspect the temporary folder and extract the view name.

@codluca codluca force-pushed the 25425-create-or-replace-view-unique-location-iceberg-rest branch from 6927de5 to 8f5b537 Compare October 4, 2025 15:05
If replace and useUniqueTableLocation, load the existing view and reuse its location.
@codluca codluca force-pushed the 25425-create-or-replace-view-unique-location-iceberg-rest branch from 8f5b537 to 9748f78 Compare October 7, 2025 12:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla-signed iceberg Iceberg connector
Development

Successfully merging this pull request may close these issues.

[iceberg] inconsistent set-location between create or replace view / table
3 participants