Skip to content

Conversation

@stuxuhai
Copy link
Contributor

The current implementation of HiveViewOperations's doCommit method correctly updates the view properties and the Iceberg metadata location in the Hive Metastore (HMS) when a view is altered. However, it fails to update the actual SQL query string stored in the HMS.

This bug causes severe inconsistency:

  1. A user alters an Iceberg View (e.g., changing the underlying query logic).
  2. The Iceberg metadata is updated correctly.
  3. The HMS continues to store the old query string, which can lead to users or tools relying on the HMS metadata executing the outdated definition.

This fix guarantees that the view definition in the Hive Metastore is always synchronized with the canonical Iceberg view definition, enhancing compatibility and reliability when using external systems that rely on HMS for query metadata.

@github-actions github-actions bot added the hive label Dec 12, 2025
@huaxingao
Copy link
Contributor

@stuxuhai Thanks for the PR! Can we add a test?

@stuxuhai
Copy link
Contributor Author

@huaxingao Thx! Unit test has been added.

@ebyhr
Copy link
Contributor

ebyhr commented Dec 13, 2025

Could you fix a checkstyle error? You can run:

./gradlew :iceberg-hive-metastore:spotlessApply

@stuxuhai
Copy link
Contributor Author

@ebyhr thanks,fixed

@nastra nastra self-requested a review December 16, 2025 17:51
}

@Test
public void testViewQueryIsUpdatedOnCommit() throws Exception {
Copy link
Contributor

Choose a reason for hiding this comment

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

can you slightly update the test to have

@Test
  public void testViewQueryIsUpdatedOnCommit() throws Exception {
    HiveViewOperations ops = (HiveViewOperations) ((BaseView) view).operations();
    assertThat(view.currentVersion().representations())
        .containsExactly(
            ImmutableSQLViewRepresentation.builder().sql(VIEW_QUERY).dialect("hive").build());

    Table hmsTable = ops.loadHmsTable();
    assertThat(hmsTable.getViewOriginalText()).isEqualTo(VIEW_QUERY);
    assertThat(hmsTable.getViewExpandedText()).isEqualTo(VIEW_QUERY);

    String newQuery = "select * from ns.tbl2 limit 10";
    view =
        catalog
            .buildView(VIEW_IDENTIFIER)
            .withSchema(SCHEMA)
            .withDefaultNamespace(NS)
            .withQuery("hive", newQuery)
            .replace();

    assertThat(view.currentVersion().representations())
        .containsExactly(
            ImmutableSQLViewRepresentation.builder().sql(newQuery).dialect("hive").build());

    Table updatedHmsTable = ops.loadHmsTable();
    assertThat(updatedHmsTable.getViewOriginalText()).isEqualTo(newQuery);
    assertThat(updatedHmsTable.getViewExpandedText()).isEqualTo(newQuery);
  }

Copy link
Contributor

@nastra nastra left a comment

Choose a reason for hiding this comment

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

LGTM, thanks @stuxuhai

@nastra
Copy link
Contributor

nastra commented Dec 19, 2025

@stuxuhai I've pushed some minor changes to your branch. There's a flaky test that causes CI failures, so please rebase when you get a chance

@stuxuhai stuxuhai force-pushed the fix_update_view_query branch from 35865d8 to 7831b81 Compare December 19, 2025 14:30
@stuxuhai
Copy link
Contributor Author

@nastra Rebased on top of the latest changes. Thanks!

@nastra nastra merged commit 59280a1 into apache:main Dec 19, 2025
44 checks passed
@stuxuhai stuxuhai deleted the fix_update_view_query branch December 19, 2025 19:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants