Skip to content

Commit 9a5ad4c

Browse files
authored
Don't append display name suffix to data table file keys (#7104)
`CsvDataTableStore.fileKey()` always appended a sanitized suffix derived from `getInstanceName()`, which defaults to the display name. This meant every data table got a suffix like `--recipe-performance-c5de` even when no custom instance name was set and no disambiguation was needed. Now, when no group is set, a suffix is only added when the instance name was explicitly customized via `withInstanceName()` (i.e. differs from the default display name). Plain data tables like `RecipeRunStats` get a clean key: `org.openrewrite.table.RecipeRunStats`.
1 parent 892bbb8 commit 9a5ad4c

2 files changed

Lines changed: 36 additions & 3 deletions

File tree

rewrite-core/src/main/java/org/openrewrite/CsvDataTableStore.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -242,11 +242,19 @@ void close() {
242242
*/
243243
public static String fileKey(DataTable<?> dataTable) {
244244
String group = dataTable.getGroup();
245-
String suffix = group != null ? group : dataTable.getInstanceName();
246-
if (suffix.equals(dataTable.getName())) {
245+
if (group != null) {
246+
if (group.equals(dataTable.getName())) {
247+
return dataTable.getName();
248+
}
249+
return dataTable.getName() + "--" + sanitize(group);
250+
}
251+
// Only add a suffix when the instance name was explicitly customized
252+
// (i.e. differs from the default display name)
253+
String instanceName = dataTable.getInstanceName();
254+
if (instanceName.equals(dataTable.getDisplayName())) {
247255
return dataTable.getName();
248256
}
249-
return dataTable.getName() + "--" + sanitize(suffix);
257+
return dataTable.getName() + "--" + sanitize(instanceName);
250258
}
251259

252260
/**

rewrite-core/src/test/java/org/openrewrite/DataTableStoreTest.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,31 @@ void csvStoreReadDescriptor(@TempDir Path tempDir) throws Exception {
246246
}
247247
}
248248

249+
// =========================================================================
250+
// CsvDataTableStore.fileKey
251+
// =========================================================================
252+
253+
@Test
254+
void fileKeyNoSuffixWhenInstanceNameNotCustomized() {
255+
TestTable table = new TestTable(Recipe.noop());
256+
assertThat(CsvDataTableStore.fileKey(table)).isEqualTo(TestTable.class.getName());
257+
}
258+
259+
@Test
260+
void fileKeySuffixWhenInstanceNameCustomized() {
261+
TestTable table = new TestTable(Recipe.noop())
262+
.withInstanceName(() -> "custom instance");
263+
String key = CsvDataTableStore.fileKey(table);
264+
assertThat(key).startsWith(TestTable.class.getName() + "--");
265+
}
266+
267+
@Test
268+
void fileKeySuffixFromGroup() {
269+
TestTable table = new TestTable(Recipe.noop()).withGroup("my-group");
270+
String key = CsvDataTableStore.fileKey(table);
271+
assertThat(key).startsWith(TestTable.class.getName() + "--");
272+
}
273+
249274
// =========================================================================
250275
// CsvDataTableStore.sanitize
251276
// =========================================================================

0 commit comments

Comments
 (0)