-
Notifications
You must be signed in to change notification settings - Fork 488
feat(persistence): replace EventEntity.REALM_SCOPED sentinel with nullable catalog_id #4981
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
flyrain
merged 2 commits into
apache:main
from
sririshindra:issue-4674-nullable-event-catalog-id
Jul 20, 2026
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
119 changes: 119 additions & 0 deletions
119
...c/test/java/org/apache/polaris/persistence/relational/jdbc/JdbcEventsPersistenceTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,119 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
| package org.apache.polaris.persistence.relational.jdbc; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||
| import static org.junit.jupiter.api.Assertions.assertNull; | ||
| import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
|
||
| import java.io.InputStream; | ||
| import java.sql.Connection; | ||
| import java.sql.PreparedStatement; | ||
| import java.sql.ResultSet; | ||
| import java.util.List; | ||
| import java.util.UUID; | ||
| import java.util.stream.Stream; | ||
| import javax.sql.DataSource; | ||
| import org.apache.polaris.core.PolarisDefaultDiagServiceImpl; | ||
| import org.apache.polaris.core.entity.EventEntity; | ||
| import org.apache.polaris.core.persistence.PrincipalSecretsGenerator; | ||
| import org.apache.polaris.persistence.relational.jdbc.models.ModelEvent; | ||
| import org.h2.jdbcx.JdbcConnectionPool; | ||
| import org.junit.jupiter.params.ParameterizedTest; | ||
| import org.junit.jupiter.params.provider.MethodSource; | ||
|
|
||
| /** | ||
| * Tests event persistence across schema versions: schema versions before v5 declare | ||
| * events.catalog_id NOT NULL, so realm-scoped events (null catalog id) must be stored with the | ||
| * legacy sentinel; from v5 on they are stored as SQL NULL. | ||
| */ | ||
| class JdbcEventsPersistenceTest { | ||
|
|
||
| static Stream<Integer> schemaVersions() { | ||
| // The events table exists from schema v3 on. | ||
| return SchemaVersions.discoverAsStream(DatabaseType.H2).filter(version -> version >= 3); | ||
| } | ||
|
|
||
| @ParameterizedTest | ||
| @MethodSource("schemaVersions") | ||
| void writeEventsStoresNullCatalogIdPerSchemaVersion(int schemaVersion) throws Exception { | ||
| DataSource dataSource = | ||
| JdbcConnectionPool.create( | ||
| "jdbc:h2:mem:test_events_" + UUID.randomUUID() + ";DB_CLOSE_DELAY=-1", "sa", ""); | ||
| DatasourceOperations datasourceOperations = | ||
| new DatasourceOperations( | ||
| dataSource, SimpleRelationalJdbcConfiguration.forDatabaseType(DatabaseType.H2)); | ||
| try (InputStream schemaStream = DatabaseType.H2.openInitScriptResource(schemaVersion)) { | ||
| datasourceOperations.executeScript(schemaStream); | ||
| } | ||
| JdbcBasePersistenceImpl persistence = | ||
| new JdbcBasePersistenceImpl( | ||
| new PolarisDefaultDiagServiceImpl(), | ||
| datasourceOperations, | ||
| PrincipalSecretsGenerator.RANDOM_SECRETS, | ||
| "TEST_REALM", | ||
| schemaVersion); | ||
|
|
||
| EventEntity realmScopedEvent = | ||
| new EventEntity( | ||
| null, | ||
| "realm-event", | ||
| null, | ||
| "CREATE_PRINCIPAL", | ||
| 1234L, | ||
| "test-user", | ||
| EventEntity.ResourceType.REALM, | ||
| "principal-1"); | ||
| EventEntity catalogScopedEvent = | ||
| new EventEntity( | ||
| "catalog-1", | ||
| "catalog-event", | ||
| "req-1", | ||
| "CREATE_TABLE", | ||
| 1234L, | ||
| "test-user", | ||
| EventEntity.ResourceType.TABLE, | ||
| "table-1"); | ||
|
|
||
| persistence.writeEvents(List.of(realmScopedEvent, catalogScopedEvent)); | ||
|
|
||
| if (schemaVersion < 5) { | ||
| assertEquals( | ||
| ModelEvent.LEGACY_REALM_SCOPED_CATALOG_ID, | ||
| readStoredCatalogId(dataSource, "realm-event")); | ||
| } else { | ||
| assertNull(readStoredCatalogId(dataSource, "realm-event")); | ||
| } | ||
| assertEquals("catalog-1", readStoredCatalogId(dataSource, "catalog-event")); | ||
| } | ||
|
|
||
| private static String readStoredCatalogId(DataSource dataSource, String eventId) | ||
| throws Exception { | ||
| try (Connection connection = dataSource.getConnection(); | ||
| PreparedStatement statement = | ||
| connection.prepareStatement( | ||
| "SELECT catalog_id FROM POLARIS_SCHEMA.EVENTS WHERE event_id = ?")) { | ||
| statement.setString(1, eventId); | ||
| try (ResultSet resultSet = statement.executeQuery()) { | ||
| assertTrue(resultSet.next()); | ||
| return resultSet.getString(1); | ||
| } | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm wondering how long should we support old schemas? With our
support rolling upgradespolicy (https://polaris.apache.org/releases/1.6.0/evolution/#managing-polaris-database), after we release 1.7 with this change, can we eliminate the sentinel completely in 1.9?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I 've been meaning to start this thread on
devfor a long time, but never find a break to just write that email 😅Feel free to initiate this conversation.