Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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 @@ -143,6 +143,7 @@ public enum RollupNodeType {

private Column rowDepthCol;
private Column rowExpandedCol;
private JsArray<Column> aggregatedColumns;
private JsArray<Column> groupedColumns;
private JsLayoutHints layoutHints;

Expand Down Expand Up @@ -232,6 +233,7 @@ private void extractDefinition(final HierarchicalTableDescriptor treeDescriptor)
boolean hasConstituentColumns = !columnDefsByName.get(true).isEmpty();

Map<String, Column> constituentColumns = new HashMap<>();
JsArray<Column> aggregatedColumns = new JsArray<>();
JsArray<Column> groupedColumns = new JsArray<>();
for (ColumnDefinition definition : tableDefinition.getColumns()) {
Column column = definition.makeJsColumn(columns.length, columnDefsByName);
Expand Down Expand Up @@ -260,6 +262,8 @@ private void extractDefinition(final HierarchicalTableDescriptor treeDescriptor)
if (hasConstituentColumns) {
column.setConstituentType(columnDefsByName.get(true).get(definition.getName()).getType());
}
} else if (definition.isRollupAggregatedNodeColumn()) {
aggregatedColumns.push(column);
}
String aggInputCol = definition.getRollupAggregationInputColumn();
if (hasConstituentColumns && aggInputCol != null && !aggInputCol.isEmpty()) {
Expand All @@ -269,6 +273,7 @@ private void extractDefinition(final HierarchicalTableDescriptor treeDescriptor)
}
}
}
this.aggregatedColumns = JsObject.freeze(aggregatedColumns);
this.groupedColumns = JsObject.freeze(groupedColumns);

sourceColumns = columnDefsByName.get(false).values().stream()
Expand Down Expand Up @@ -1267,6 +1272,16 @@ public boolean isIncludeConstituents() {
return Arrays.stream(tableDefinition.getColumns()).anyMatch(ColumnDefinition::isRollupConstituentNodeColumn);
}

/**
* Returns the columns that are aggregated.
*
* @return array of aggregated columns
*/
@JsProperty
public JsArray<Column> getAggregatedColumns() {
return aggregatedColumns;
}

@JsProperty
public JsArray<Column> getGroupedColumns() {
return groupedColumns;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -691,4 +691,104 @@ public void testCreateRollupUpdateViewUnsafe() {
})
.then(this::report, this::finish);
}

public void testRollupAggregatedColumns() {
connect(tables)
.then(table("table_to_rollup"))
.then(table -> {
List<Supplier<Promise<JsTreeTable>>> tests = new ArrayList<>();
JsRollupConfig cfg = new JsRollupConfig();
cfg.groupingColumns = Js.uncheckedCast(JsArray.of("X"));
cfg.aggregations = JsPropertyMap.of(JsAggregationOperation.SUM, JsArray.of("Y"));
// Rollup with or without constituents should populate aggregated columns
Stream.of(true, false).forEach(includeConstituents -> {
cfg.includeConstituents = includeConstituents;
JsRollupConfig copy = new JsRollupConfig((JsPropertyMap<Object>) cfg);
tests.add(() -> table.rollup(copy).then(r -> {
assertEquals(1, r.getAggregatedColumns().length);
assertEquals("Y", r.getAggregatedColumns().getAt(0).getName());
return Promise.resolve(r);
}));
});
return tests.stream().reduce((p1, p2) -> () -> p1.get().then(result -> p2.get())).get().get();
})
.then(this::finish)
.catch_(this::report);
}

public void testRollupSkipAggAggregatedColumns() {
connect(tables)
.then(table("table_to_rollup"))
.then(table -> {
List<Supplier<Promise<JsTreeTable>>> tests = new ArrayList<>();
JsRollupConfig cfg = new JsRollupConfig();
Comment thread
niloc132 marked this conversation as resolved.
Outdated
cfg.groupingColumns = Js.uncheckedCast(JsArray.of("X"));
cfg.aggregations = JsPropertyMap.of(JsAggregationOperation.SKIP, JsArray.of("Y"));
// Rollup should not include Skip aggregation in aggregated columns
Stream.of(true, false).forEach(includeConstituents -> {
cfg.includeConstituents = includeConstituents;
JsRollupConfig copy = new JsRollupConfig((JsPropertyMap<Object>) cfg);
Comment thread
vbabich marked this conversation as resolved.
Outdated
tests.add(() -> table.rollup(copy).then(r -> {
assertEquals(0, r.getAggregatedColumns().length);
return Promise.resolve(r);
}));
});
return tests.stream().reduce((p1, p2) -> () -> p1.get().then(result -> p2.get())).get().get();
})
.then(this::finish)
.catch_(this::report);
}

public void testRollupSkipAggWithConstituentColumns() {
connect(tables)
.then(table("table_to_rollup"))
.then(table -> {
List<Supplier<Promise<JsTreeTable>>> tests = new ArrayList<>();
JsRollupConfig cfg = new JsRollupConfig();
cfg.groupingColumns = Js.uncheckedCast(JsArray.of("X"));
cfg.aggregations = JsPropertyMap.of(JsAggregationOperation.SKIP, JsArray.of("Y"));
cfg.includeConstituents = true;
// Rollup with constituents should have the column with a SKIP aggregation
Comment thread
vbabich marked this conversation as resolved.
Outdated
return table.rollup(cfg).then(rollupTable -> {
assertEquals(4, rollupTable.getColumns().length);
assertEquals("Y", rollupTable.getColumns().getAt(2).getName());
return null;
});
})
.then(this::finish)
.catch_(this::report);
}

public void testRollupSkipAggNoConstituentsColumns() {
connect(tables)
.then(table("table_to_rollup"))
.then(table -> {
List<Supplier<Promise<JsTreeTable>>> tests = new ArrayList<>();
JsRollupConfig cfg = new JsRollupConfig();
cfg.groupingColumns = Js.uncheckedCast(JsArray.of("X"));
cfg.aggregations = JsPropertyMap.of(JsAggregationOperation.SKIP, JsArray.of("Y"));
cfg.includeConstituents = false;
// Rollup without constituents shouldn't have the column with a SKIP aggregation
return table.rollup(cfg).then(rollupTable -> {
assertEquals(1, rollupTable.getColumns().length);
assertEquals("X", rollupTable.getColumns().getAt(0).getName());
return null;
});
})
.then(this::finish)
.catch_(this::report);
}

public void testTreeTableAggregatedColumns() {
connect(tables)
.then(treeTable("static_tree"))
.then(treeTable -> {
// Tree tables should have no aggregated columns
JsArray<Column> aggColumns = treeTable.getAggregatedColumns();
assertEquals(0, aggColumns.length);
return null;
})
.then(this::finish)
.catch_(this::report);
}
}
Loading