Skip to content

Commit

Permalink
Revert "Integrate measure row filters to pivot (#4062)" (#4130)
Browse files Browse the repository at this point in the history
This reverts commit 68c5289.
  • Loading branch information
djbarnwal authored and nishantmonu51 committed Feb 21, 2024
1 parent 5b33651 commit 793783a
Show file tree
Hide file tree
Showing 4 changed files with 114 additions and 46 deletions.
66 changes: 38 additions & 28 deletions web-common/src/features/dashboards/pivot/pivot-data-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import {
getTimeGrainFromDimension,
getTotalColumnCount,
isTimeDimension,
reconcileMissingDimensionValues,
} from "./pivot-utils";
import {
PivotChipType,
Expand Down Expand Up @@ -150,7 +151,6 @@ export function createTableCellQuery(
};
} else return { name: dimension };
});
const measureBody = config.measureNames.map((m) => ({ name: m }));

const { filters: filterForInitialTable, timeFilters } =
getFilterForPivotTable(
Expand All @@ -174,7 +174,7 @@ export function createTableCellQuery(
];
return createPivotAggregationRowQuery(
ctx,
measureBody,
config.measureNames,
dimensionBody,
mergedFilter,
config.measureFilter,
Expand Down Expand Up @@ -235,6 +235,7 @@ function createPivotDataStore(ctx: StateManagers): PivotDataStore {
*/
return derived(getPivotConfig(ctx), (config, configSet) => {
const { rowDimensionNames, colDimensionNames, measureNames } = config;

if (
(!rowDimensionNames.length && !measureNames.length) ||
(colDimensionNames.length && !measureNames.length)
Expand All @@ -251,13 +252,10 @@ function createPivotDataStore(ctx: StateManagers): PivotDataStore {
totalColumns: 0,
});
}
const measureBody = measureNames.map((m) => ({ name: m }));

const columnDimensionAxesQuery = getAxisForDimensions(
ctx,
config,
colDimensionNames,
measureBody,
config.whereFilter,
);

Expand All @@ -275,35 +273,32 @@ function createPivotDataStore(ctx: StateManagers): PivotDataStore {
}
const anchorDimension = rowDimensionNames[0];

const {
where: measureWhere,
sortPivotBy,
timeRange,
} = getSortForAccessor(
const { where, sortPivotBy, timeRange } = getSortForAccessor(
anchorDimension,
config,
columnDimensionAxes?.data,
);

let sortFilteredMeasureBody = measureBody;
if (sortPivotBy.length && measureWhere) {
const accessor = sortPivotBy[0]?.name;
sortFilteredMeasureBody = measureBody.map((m) => {
if (m.name === accessor) return { ...m, filter: measureWhere };
return m;
});
}

const rowDimensionAxisQuery = getAxisForDimensions(
ctx,
config,
rowDimensionNames.slice(0, 1),
sortFilteredMeasureBody,
config.whereFilter,
where,
sortPivotBy,
timeRange,
);

/**
* We need to query the unsorted row dimension values because the sorted
* row dimension values may not have all the dimensions values
*/
const rowDimensionUnsortedAxisQuery = getAxisForDimensions(
ctx,
config,
rowDimensionNames.slice(0, 1),
config.whereFilter,
);

let globalTotalsQuery:
| Readable<null>
| CreateQueryResult<V1MetricsViewAggregationResponse, unknown> =
Expand All @@ -315,7 +310,7 @@ function createPivotDataStore(ctx: StateManagers): PivotDataStore {
if (rowDimensionNames.length && measureNames.length) {
globalTotalsQuery = createPivotAggregationRowQuery(
ctx,
config.measureNames.map((m) => ({ name: m })),
config.measureNames,
[],
config.whereFilter,
config.measureFilter,
Expand All @@ -338,16 +333,27 @@ function createPivotDataStore(ctx: StateManagers): PivotDataStore {
* Derive a store from axes queries
*/
return derived(
[rowDimensionAxisQuery, globalTotalsQuery, totalsRowQuery],
[
rowDimensionAxisQuery,
rowDimensionUnsortedAxisQuery,
globalTotalsQuery,
totalsRowQuery,
],
(
[rowDimensionAxes, globalTotalsResponse, totalsRowResponse],
[
rowDimensionAxes,
rowDimensionUnsortedAxis,
globalTotalsResponse,
totalsRowResponse,
],
axesSet,
) => {
if (
(globalTotalsResponse !== null &&
globalTotalsResponse?.isFetching) ||
(totalsRowResponse !== null && totalsRowResponse?.isFetching) ||
rowDimensionAxes?.isFetching
rowDimensionAxes?.isFetching ||
rowDimensionUnsortedAxis?.isFetching
) {
return axesSet({
isFetching: true,
Expand All @@ -358,9 +364,6 @@ function createPivotDataStore(ctx: StateManagers): PivotDataStore {
});
}

const rowDimensionValues =
rowDimensionAxes?.data?.[anchorDimension] || [];
const rowTotals = rowDimensionAxes?.totals?.[anchorDimension] || [];
const totalsRow = getTotalsRow(
config,
columnDimensionAxes?.data,
Expand All @@ -370,6 +373,13 @@ function createPivotDataStore(ctx: StateManagers): PivotDataStore {

const totalColumns = getTotalColumnCount(totalsRow);

const { rows: rowDimensionValues, totals: rowTotals } =
reconcileMissingDimensionValues(
anchorDimension,
rowDimensionAxes,
rowDimensionUnsortedAxis,
);

let initialTableCellQuery:
| Readable<null>
| CreateQueryResult<V1MetricsViewAggregationResponse, unknown> =
Expand Down
5 changes: 1 addition & 4 deletions web-common/src/features/dashboards/pivot/pivot-expansion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ export function createSubTableCellQuery(
};
} else return { name: dimension };
});
const measureBody = config.measureNames.map((m) => ({ name: m }));

const { filters: filterForSubTable, timeFilters: colTimeFilters } =
getFilterForPivotTable(config, columnDimensionAxesData, totalsRow);
Expand All @@ -106,7 +105,7 @@ export function createSubTableCellQuery(
];
return createPivotAggregationRowQuery(
ctx,
measureBody,
config.measureNames,
dimensionBody,
filterForSubTable,
config.measureFilter,
Expand Down Expand Up @@ -141,7 +140,6 @@ export function queryExpandedRowMeasureValues(
const expanded = config.pivot.expanded;
if (!tableData || Object.keys(expanded).length == 0) return writable(null);

const measureBody = config.measureNames.map((m) => ({ name: m }));
return derived(
Object.keys(expanded)?.map((expandIndex) => {
const nestLevel = expandIndex?.split(".")?.length;
Expand Down Expand Up @@ -227,7 +225,6 @@ export function queryExpandedRowMeasureValues(
ctx,
config,
[anchorDimension],
measureBody,
allMergedFilters,
sortPivotBy,
timeRange,
Expand Down
14 changes: 6 additions & 8 deletions web-common/src/features/dashboards/pivot/pivot-queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import type { TimeRangeString } from "@rilldata/web-common/lib/time/types";
import {
V1Expression,
V1MetricsViewAggregationDimension,
V1MetricsViewAggregationMeasure,
V1MetricsViewAggregationResponseDataItem,
V1MetricsViewAggregationSort,
createQueryServiceMetricsViewAggregation,
Expand All @@ -33,7 +32,7 @@ import { mergeFilters } from "./pivot-merge-filters";
*/
export function createPivotAggregationRowQuery(
ctx: StateManagers,
measures: V1MetricsViewAggregationMeasure[],
measures: string[],
dimensions: V1MetricsViewAggregationDimension[],
whereFilter: V1Expression,
measureFilter: ResolvedMeasureFilter | undefined,
Expand All @@ -46,7 +45,7 @@ export function createPivotAggregationRowQuery(
sort = [
{
desc: false,
name: measures[0]?.name || dimensions?.[0]?.name,
name: measures[0] || dimensions?.[0]?.name,
},
];
}
Expand All @@ -58,7 +57,7 @@ export function createPivotAggregationRowQuery(
runtime.instanceId,
metricViewName,
{
measures,
measures: measures.map((measure) => ({ name: measure })),
dimensions,
where: sanitiseExpression(whereFilter, measureFilter?.filter),
timeRange: {
Expand Down Expand Up @@ -87,21 +86,21 @@ export function getAxisForDimensions(
ctx: StateManagers,
config: PivotDataStoreConfig,
dimensions: string[],
measures: V1MetricsViewAggregationMeasure[],
whereFilter: V1Expression,
sortBy: V1MetricsViewAggregationSort[] = [],
timeRange: TimeRangeString | undefined = undefined,
): Readable<PivotAxesData | null> {
if (!dimensions.length) return readable(null);

const measures = config.measureNames;
const { time } = config;

let sortProvided = true;
if (!sortBy.length) {
sortBy = [
{
desc: true,
name: measures[0]?.name || dimensions?.[0],
name: measures[0] || dimensions?.[0],
},
];
sortProvided = false;
Expand Down Expand Up @@ -181,7 +180,6 @@ export function getTotalsRowQuery(
const { colDimensionNames } = config;

const { time } = config;
const measureBody = config.measureNames.map((m) => ({ name: m }));
const dimensionBody = colDimensionNames.map((dimension) => {
if (isTimeDimension(dimension, time.timeDimension)) {
return {
Expand Down Expand Up @@ -212,7 +210,7 @@ export function getTotalsRowQuery(
];
return createPivotAggregationRowQuery(
ctx,
measureBody,
config.measureNames,
dimensionBody,
mergedFilter,
config.measureFilter,
Expand Down
Loading

0 comments on commit 793783a

Please sign in to comment.