Skip to content

Commit

Permalink
datacube: fix aggregation count issue (#3876)
Browse files Browse the repository at this point in the history
  • Loading branch information
akphi authored Feb 7, 2025
1 parent 2936c20 commit c7384e1
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 18 deletions.
4 changes: 4 additions & 0 deletions .changeset/cyan-llamas-happen.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
'@finos/legend-application-data-cube': patch
'@finos/legend-data-cube': patch
---
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export class LegendDataCubeDataCubeCacheManager {
`Can't initialize cache manager: DuckDB main worker not initialized`,
);
const worker = new Worker(bundle.mainWorker);
const logger = new duckdb.ConsoleLogger(duckdb.LogLevel.WARNING);
const logger = new duckdb.ConsoleLogger(duckdb.LogLevel.WARNING); // only show warnings and errors
const database = new duckdb.AsyncDuckDB(logger, worker);
await database.instantiate(bundle.mainModule, bundle.pthreadWorker);
this._database = database;
Expand Down Expand Up @@ -115,6 +115,7 @@ export class LegendDataCubeDataCubeCacheManager {
colType = 'FLOAT';
break;
}
// We don't use type DATE because DuckDB will automatically convert it to a TIMESTAMP
case PRIMITIVE_TYPE.STRICTDATE:
case PRIMITIVE_TYPE.DATETIME:
case PRIMITIVE_TYPE.DATE: {
Expand Down Expand Up @@ -167,11 +168,11 @@ export class LegendDataCubeDataCubeCacheManager {
const data = result.toArray();
const columnNames = result.schema.fields.map((field) => field.name);
const rows = data.map((row) => {
const values = new TDSRow();
values.values = columnNames.map(
const tdsRow = new TDSRow();
tdsRow.values = columnNames.map(
(column) => row[column] as string | number | boolean | null,
);
return values;
return tdsRow;
});
const tdsExecutionResult = new TDSExecutionResult();
const tds = new TabularDataSet();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ import { _findCol, _sortByColName } from '../../core/model/DataCubeColumn.js';
import { isPivotResultColumnName } from '../../core/DataCubeQueryEngine.js';
import { buildQuerySnapshot } from './DataCubeGridQuerySnapshotBuilder.js';
import { AlertType } from '../../services/DataCubeAlertService.js';
import { sum } from 'mathjs';
import type { DataCubeViewState } from '../DataCubeViewState.js';
import {
_aggCountCol,
Expand Down Expand Up @@ -229,19 +228,17 @@ function buildRowData(
? value
: INTERNAL__GRID_CLIENT_MISSING_VALUE;
if (snapshot.data.pivot && snapshot.data.groupBy) {
row[INTERNAL__GRID_CLIENT_ROW_GROUPING_COUNT_AGG_COLUMN_ID] = Number(
sum(
result.columns
.filter(
(col) =>
isPivotResultColumnName(col) &&
col.endsWith(
INTERNAL__GRID_CLIENT_ROW_GROUPING_COUNT_AGG_COLUMN_ID,
),
)
.map((col) => (row[col] as number | undefined) ?? 0),
).toString(),
);
row[INTERNAL__GRID_CLIENT_ROW_GROUPING_COUNT_AGG_COLUMN_ID] =
result.columns
.filter(
(col) =>
isPivotResultColumnName(col) &&
col.endsWith(
INTERNAL__GRID_CLIENT_ROW_GROUPING_COUNT_AGG_COLUMN_ID,
),
)
.map((col) => (row[col] as number | undefined) ?? 0)
.reduce((a, b) => a + b, 0);
}
});
return row;
Expand Down

0 comments on commit c7384e1

Please sign in to comment.