-
Notifications
You must be signed in to change notification settings - Fork 325
Support shared catalog config across tables in iceberg-source #6727
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
dlvenable
merged 2 commits into
opensearch-project:main
from
lawofcycles:feature/iceberg-source-shared-catalog
Apr 21, 2026
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
166 changes: 166 additions & 0 deletions
166
...e/src/test/java/org/opensearch/dataprepper/plugins/source/iceberg/IcebergServiceTest.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,166 @@ | ||
| /* | ||
| * Copyright OpenSearch Contributors | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| * | ||
| * The OpenSearch Contributors require contributions made to | ||
| * this file be licensed under the Apache-2.0 license or a | ||
| * compatible open source license. | ||
| * | ||
| */ | ||
|
|
||
| package org.opensearch.dataprepper.plugins.source.iceberg; | ||
|
|
||
| import org.apache.iceberg.CatalogUtil; | ||
| import org.apache.iceberg.Table; | ||
| import org.apache.iceberg.catalog.Catalog; | ||
| import org.apache.iceberg.catalog.TableIdentifier; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.junit.jupiter.api.extension.ExtendWith; | ||
| import org.mockito.ArgumentCaptor; | ||
| import org.mockito.Mock; | ||
| import org.mockito.MockedStatic; | ||
| import org.mockito.junit.jupiter.MockitoExtension; | ||
| import org.opensearch.dataprepper.metrics.PluginMetrics; | ||
| import org.opensearch.dataprepper.model.acknowledgements.AcknowledgementSetManager; | ||
| import org.opensearch.dataprepper.model.buffer.Buffer; | ||
| import org.opensearch.dataprepper.model.event.Event; | ||
| import org.opensearch.dataprepper.model.event.EventFactory; | ||
| import org.opensearch.dataprepper.model.record.Record; | ||
| import org.opensearch.dataprepper.model.source.coordinator.enhanced.EnhancedSourceCoordinator; | ||
|
|
||
| import java.time.Duration; | ||
| import java.util.Collections; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
|
|
||
| import static org.hamcrest.MatcherAssert.assertThat; | ||
| import static org.hamcrest.Matchers.equalTo; | ||
| import static org.mockito.ArgumentMatchers.any; | ||
| import static org.mockito.ArgumentMatchers.anyString; | ||
| import static org.mockito.ArgumentMatchers.isNull; | ||
| import static org.mockito.Mockito.lenient; | ||
| import static org.mockito.Mockito.mock; | ||
| import static org.mockito.Mockito.mockStatic; | ||
| import static org.mockito.Mockito.when; | ||
|
|
||
| @ExtendWith(MockitoExtension.class) | ||
| class IcebergServiceTest { | ||
|
|
||
| @Mock | ||
| private EnhancedSourceCoordinator sourceCoordinator; | ||
| @Mock | ||
| private IcebergSourceConfig sourceConfig; | ||
| @Mock | ||
| private PluginMetrics pluginMetrics; | ||
| @Mock | ||
| private AcknowledgementSetManager acknowledgementSetManager; | ||
| @Mock | ||
| private EventFactory eventFactory; | ||
| @Mock | ||
| private Buffer<Record<Event>> buffer; | ||
|
|
||
| @Test | ||
| @SuppressWarnings("unchecked") | ||
| void start_uses_shared_catalog_when_table_catalog_is_null() { | ||
| final Map<String, String> sharedCatalog = Map.of("type", "rest", "uri", "http://shared:8181"); | ||
| final TableConfig tableConfig = createTableConfig("db.my_table", null); | ||
|
|
||
| when(sourceConfig.getCatalog()).thenReturn(sharedCatalog); | ||
| when(sourceConfig.getTables()).thenReturn(List.of(tableConfig)); | ||
| when(sourceConfig.getPollingInterval()).thenReturn(Duration.ofSeconds(5)); | ||
| lenient().when(sourceConfig.isAcknowledgmentsEnabled()).thenReturn(false); | ||
|
|
||
| final Catalog catalog = mock(Catalog.class); | ||
| final Table table = mock(Table.class); | ||
| when(table.properties()).thenReturn(Collections.emptyMap()); | ||
| when(catalog.loadTable(any(TableIdentifier.class))).thenReturn(table); | ||
|
|
||
| final ArgumentCaptor<Map<String, String>> propsCaptor = ArgumentCaptor.forClass(Map.class); | ||
|
|
||
| try (MockedStatic<CatalogUtil> mockedCatalogUtil = mockStatic(CatalogUtil.class)) { | ||
| mockedCatalogUtil.when(() -> CatalogUtil.buildIcebergCatalog(anyString(), propsCaptor.capture(), isNull())) | ||
| .thenReturn(catalog); | ||
|
|
||
| final IcebergService service = new IcebergService(sourceCoordinator, sourceConfig, | ||
| pluginMetrics, acknowledgementSetManager, eventFactory); | ||
| service.start(buffer); | ||
| service.shutdown(); | ||
|
|
||
| assertThat(propsCaptor.getValue(), equalTo(sharedCatalog)); | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| @SuppressWarnings("unchecked") | ||
| void start_uses_table_catalog_when_table_catalog_is_set() { | ||
| final Map<String, String> tableCatalog = Map.of("type", "glue", "warehouse", "s3://other/"); | ||
| final TableConfig tableConfig = createTableConfig("db.my_table", tableCatalog); | ||
|
|
||
| when(sourceConfig.getTables()).thenReturn(List.of(tableConfig)); | ||
| when(sourceConfig.getPollingInterval()).thenReturn(Duration.ofSeconds(5)); | ||
| lenient().when(sourceConfig.isAcknowledgmentsEnabled()).thenReturn(false); | ||
|
|
||
| final Catalog catalog = mock(Catalog.class); | ||
| final Table table = mock(Table.class); | ||
| when(table.properties()).thenReturn(Collections.emptyMap()); | ||
| when(catalog.loadTable(any(TableIdentifier.class))).thenReturn(table); | ||
|
|
||
| final ArgumentCaptor<Map<String, String>> propsCaptor = ArgumentCaptor.forClass(Map.class); | ||
|
|
||
| try (MockedStatic<CatalogUtil> mockedCatalogUtil = mockStatic(CatalogUtil.class)) { | ||
| mockedCatalogUtil.when(() -> CatalogUtil.buildIcebergCatalog(anyString(), propsCaptor.capture(), isNull())) | ||
| .thenReturn(catalog); | ||
|
|
||
| final IcebergService service = new IcebergService(sourceCoordinator, sourceConfig, | ||
| pluginMetrics, acknowledgementSetManager, eventFactory); | ||
| service.start(buffer); | ||
| service.shutdown(); | ||
|
|
||
| assertThat(propsCaptor.getValue(), equalTo(tableCatalog)); | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| @SuppressWarnings("unchecked") | ||
| void start_uses_correct_catalog_for_each_table_in_mixed_config() { | ||
| final Map<String, String> sharedCatalog = Map.of("type", "rest", "uri", "http://shared:8181"); | ||
| final Map<String, String> tableBCatalog = Map.of("type", "glue", "warehouse", "s3://other/"); | ||
| final TableConfig configA = createTableConfig("db.table_a", null); | ||
| final TableConfig configB = createTableConfig("db.table_b", tableBCatalog); | ||
|
|
||
| when(sourceConfig.getCatalog()).thenReturn(sharedCatalog); | ||
| when(sourceConfig.getTables()).thenReturn(List.of(configA, configB)); | ||
| when(sourceConfig.getPollingInterval()).thenReturn(Duration.ofSeconds(5)); | ||
| lenient().when(sourceConfig.isAcknowledgmentsEnabled()).thenReturn(false); | ||
|
|
||
| final Catalog catalog = mock(Catalog.class); | ||
| final Table table = mock(Table.class); | ||
| when(table.properties()).thenReturn(Collections.emptyMap()); | ||
| when(catalog.loadTable(any(TableIdentifier.class))).thenReturn(table); | ||
|
|
||
| final ArgumentCaptor<Map<String, String>> propsCaptor = ArgumentCaptor.forClass(Map.class); | ||
|
|
||
| try (MockedStatic<CatalogUtil> mockedCatalogUtil = mockStatic(CatalogUtil.class)) { | ||
| mockedCatalogUtil.when(() -> CatalogUtil.buildIcebergCatalog(anyString(), propsCaptor.capture(), isNull())) | ||
| .thenReturn(catalog); | ||
|
|
||
| final IcebergService service = new IcebergService(sourceCoordinator, sourceConfig, | ||
| pluginMetrics, acknowledgementSetManager, eventFactory); | ||
| service.start(buffer); | ||
| service.shutdown(); | ||
|
|
||
| final List<Map<String, String>> captured = propsCaptor.getAllValues(); | ||
| assertThat(captured.get(0), equalTo(sharedCatalog)); | ||
| assertThat(captured.get(1), equalTo(tableBCatalog)); | ||
| } | ||
| } | ||
|
|
||
| private TableConfig createTableConfig(final String tableName, final Map<String, String> catalogProps) { | ||
| final TableConfig config = mock(TableConfig.class); | ||
| when(config.getTableName()).thenReturn(tableName); | ||
| when(config.getCatalog()).thenReturn(catalogProps); | ||
| when(config.getIdentifierColumns()).thenReturn(Collections.emptyList()); | ||
| lenient().when(config.isDisableExport()).thenReturn(false); | ||
| return config; | ||
| } | ||
| } |
40 changes: 40 additions & 0 deletions
40
.../test/java/org/opensearch/dataprepper/plugins/source/iceberg/IcebergSourceConfigTest.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,40 @@ | ||
| /* | ||
| * Copyright OpenSearch Contributors | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| * | ||
| * The OpenSearch Contributors require contributions made to | ||
| * this file be licensed under the Apache-2.0 license or a | ||
| * compatible open source license. | ||
| * | ||
| */ | ||
|
|
||
| package org.opensearch.dataprepper.plugins.source.iceberg; | ||
|
|
||
| import com.fasterxml.jackson.databind.ObjectMapper; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| import java.util.Map; | ||
|
|
||
| import static org.hamcrest.MatcherAssert.assertThat; | ||
| import static org.hamcrest.Matchers.equalTo; | ||
| import static org.hamcrest.Matchers.is; | ||
|
|
||
| class IcebergSourceConfigTest { | ||
|
|
||
| private static final ObjectMapper MAPPER = new ObjectMapper(); | ||
|
|
||
| @Test | ||
| void default_catalog_is_empty() throws Exception { | ||
| final IcebergSourceConfig config = MAPPER.readValue( | ||
| "{\"tables\": [{\"table_name\": \"db.t\"}]}", IcebergSourceConfig.class); | ||
| assertThat(config.getCatalog().isEmpty(), is(true)); | ||
| } | ||
|
|
||
| @Test | ||
| void top_level_catalog_is_deserialized() throws Exception { | ||
| final String json = "{\"catalog\": {\"type\": \"rest\", \"uri\": \"http://localhost:8181\"}, " + | ||
| "\"tables\": [{\"table_name\": \"db.t\"}]}"; | ||
| final IcebergSourceConfig config = MAPPER.readValue(json, IcebergSourceConfig.class); | ||
| assertThat(config.getCatalog(), equalTo(Map.of("type", "rest", "uri", "http://localhost:8181"))); | ||
| } | ||
| } |
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.
Should we use an alternative catalog to be sure that it is correctly selected?
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.
Since the integration test environment has a single REST catalog server, using a truly distinct catalog to verify selection is not straightforward. I added
IcebergServiceTestwith unit tests that usemockStatic(CatalogUtil.class)to capture and assert the exact catalog properties passed tobuildIcebergCatalogfor each table. The integration testexport_with_mixed_catalog_configis kept as a smoke test to confirm the mixed configuration works end to end.