SBIN2010 commented on code in PR #36050:
URL: https://github.com/apache/superset/pull/36050#discussion_r2683917657
##########
superset-frontend/plugins/plugin-chart-pivot-table/src/react-pivottable/TableRenderers.jsx:
##########
@@ -348,6 +433,108 @@ export class TableRenderer extends Component {
return spans;
}
+ getAggregatedData(pivotData, visibleColName, rowPartialOnTop) {
+ // Transforms flat row keys into a hierarchical group structure where each
level
+ // represents a grouping dimension. For each row key path, it calculates
the
+ // aggregated value for the specified column and builds a nested object
that
+ // preserves the hierarchy while storing aggregation values at each level.
+ const groups = {};
+ const rows = pivotData.rowKeys;
+ rows.forEach(rowKey => {
+ const aggValue =
+ pivotData.getAggregator(rowKey, visibleColName).value() ?? 0;
+
+ if (rowPartialOnTop) {
+ const parent = rowKey
+ .slice(0, -1)
+ .reduce((acc, key) => (acc[key] ??= {}), groups);
+ parent[rowKey.at(-1)] = { currentVal: aggValue };
+ } else {
+ rowKey.reduce((acc, key) => {
+ acc[key] = acc[key] || { currentVal: 0 };
+ acc[key].currentVal = aggValue;
+ return acc[key];
+ }, groups);
+ }
+ });
+ return groups;
+ }
+
+ sortAndCacheData(
+ groups,
+ sortOrder,
+ rowEnabled,
+ rowPartialOnTop,
+ maxRowIndex,
+ ) {
+ // Processes hierarchical data by first sorting it according to the
specified order
+ // and then converting the sorted structure into a flat array format. This
function
+ // serves as an intermediate step between hierarchical data representation
and
+ // flat array representation needed for rendering.
+ const sortedGroups = sortHierarchicalObject(
+ groups,
+ sortOrder,
+ rowPartialOnTop,
+ );
+ return convertToArray(
+ sortedGroups,
+ rowEnabled,
+ rowPartialOnTop,
+ maxRowIndex,
+ );
+ }
+
+ sortData(columnIndex, visibleColKeys, pivotData, maxRowIndex) {
+ // Handles column sorting with direction toggling (asc/desc) and implements
+ // caching mechanism to avoid redundant sorting operations. When sorting
the same
+ // column multiple times, it cycles through sorting directions. Uses
composite
+ // cache keys based on sorting parameters for optimal performance.
+ this.setState(state => {
+ const { sortingOrder, activeSortColumn } = state;
+
+ const newSortingOrder = [];
+ let newDirection = 'asc';
+
+ if (activeSortColumn === columnIndex) {
+ newDirection = sortingOrder[columnIndex] === 'asc' ? 'desc' : 'asc';
+ }
+
+ const { rowEnabled, rowPartialOnTop } = pivotData.subtotals;
+ newSortingOrder[columnIndex] = newDirection;
+
+ const cacheKey =
`${columnIndex}-${visibleColKeys.length}-${rowEnabled}-${rowPartialOnTop}-${newDirection}`;
Review Comment:
Yes, the cache key includes columnsIndex, which is the column index.
Cached results cannot be used for another column.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]