Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -311,9 +311,9 @@ public DefaultTableRuntime refresh(AmoroTable<?> table) {
TableConfiguration newConfiguration = TableConfigurations.parseTableConfig(tableConfig);
TableConfiguration oldConfiguration = getTableConfiguration();
boolean configChanged = !newConfiguration.equals(oldConfiguration);
Copy link
Member

Choose a reason for hiding this comment

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

Seems the configChanged has never been used, maybe we can return immediately if configChanged is false?

String newGroupName = newConfiguration.getOptimizingConfig().getOptimizerGroup();

if (!Objects.equals(
getGroupName(), newConfiguration.getOptimizingConfig().getOptimizerGroup())) {
if (!Objects.equals(getGroupName(), newGroupName)) {
if (optimizingProcess != null) {
optimizingProcess.close(false);
}
Expand All @@ -327,6 +327,7 @@ public DefaultTableRuntime refresh(AmoroTable<?> table) {
config.clear();
config.putAll(tableConfig);
})
.updateGroup(g -> newGroupName)
.updateState(
OPTIMIZING_STATE_KEY,
s -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,49 @@ public void testInitialize() throws Exception {
tableService = null;
}

@Test
public void testRefreshUpdatesOptimizerGroup() throws Exception {
tableService =
new DefaultTableService(new Configurations(), CATALOG_MANAGER, runtimeFactoryManager);
TestHandler handler = new TestHandler();
tableService.addHandlerChain(handler);
tableService.initialize();
if (!(catalogTestHelper().tableFormat().equals(TableFormat.MIXED_HIVE)
&& TEST_HMS.getHiveClient().getDatabase(TableTestHelper.TEST_DB_NAME) != null)) {
createDatabase();
}
createTable();

ServerTableIdentifier tableId = tableManager().listManagedTables().get(0);
DefaultTableRuntime runtime = getDefaultTableRuntime(tableId.getId());

// Verify initial group name is "default"
String initialGroup = runtime.getGroupName();
Assert.assertEquals(TableProperties.SELF_OPTIMIZING_GROUP_DEFAULT, initialGroup);

// Change optimizer group property
String newGroupName = "new-optimizer-group";
MixedTable mixedTable = (MixedTable) tableService().loadTable(tableId).originalTable();
mixedTable.updateProperties().set(TableProperties.SELF_OPTIMIZING_GROUP, newGroupName).commit();

// Refresh the runtime
runtime.refresh(tableService.loadTable(tableId));

// Verify that getGroupName() returns the new group name
Assert.assertEquals(newGroupName, runtime.getGroupName());

// Verify config changed handler was called
Assert.assertEquals(1, handler.getConfigChangedTables().size());

// Cleanup
dropTable();
dropDatabase();
tableService.dispose();
MetricManager.dispose();
EventsManager.dispose();
tableService = null;
}

protected DefaultTableService tableService() {
if (tableService != null) {
return tableService;
Expand Down