Skip to content
Closed
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 @@ -60,22 +60,16 @@ public <Row> void insertRow(DataTable<Row> dataTable, ExecutionContext ctx, Row

@Override
public Stream<?> getRows(String dataTableName, @Nullable String group) {
// Scan for matching bucket
List<Object> allRows = new ArrayList<>();
for (Bucket bucket : buckets.values()) {
if (bucket.dataTable.getName().equals(dataTableName) &&
java.util.Objects.equals(bucket.dataTable.getGroup(), group)) {
return snapshotRows(bucket);
synchronized (bucket.rows) {
allRows.addAll(bucket.rows);
}
}
}
return Stream.empty();
}

private static Stream<Object> snapshotRows(Bucket bucket) {
List<Object> snapshot;
synchronized (bucket.rows) {
snapshot = new ArrayList<>(bucket.rows);
}
return snapshot.stream();
return allRows.stream();
}

@Override
Expand Down
17 changes: 17 additions & 0 deletions rewrite-core/src/test/java/org/openrewrite/DataTableStoreTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,23 @@ void ungroupedTablesGetSeparateBuckets() {
assertThat(store.getDataTables()).hasSize(2);
}

@Test
void getRowsAggregatesAcrossUngroupedBuckets() {
InMemoryDataTableStore store = new InMemoryDataTableStore();
ExecutionContext ctx = ctx();

// Two ungrouped tables with different instance names end up in separate buckets
TestTable table1 = new TestTable(Recipe.noop()).withInstanceName(() -> "instance-a");
TestTable table2 = new TestTable(Recipe.noop()).withInstanceName(() -> "instance-b");

store.insertRow(table1, ctx, new TestTable.Row("from-a"));
store.insertRow(table2, ctx, new TestTable.Row("from-b"));

// getRows should return rows from ALL matching buckets, not just the first
List<?> rows = store.getRows(TestTable.class.getName(), null).collect(Collectors.toList());
assertThat(rows).hasSize(2);
}

// =========================================================================
// DataTable identity
// =========================================================================
Expand Down