Skip to content

Commit

Permalink
fix the sort algorithm for sorting the query execution result by colu…
Browse files Browse the repository at this point in the history
…mn (#2518)
  • Loading branch information
YannanGao-gs authored Aug 17, 2023
1 parent 23112ad commit 5377836
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 16 deletions.
5 changes: 5 additions & 0 deletions .changeset/neat-kids-wonder.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@finos/legend-query-builder': patch
---

Fix the sort algorithm for sorting the query execution result by column
3 changes: 3 additions & 0 deletions .changeset/plenty-tips-fix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
'@finos/legend-graph': patch
---
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

import { guaranteeNonNullable, uuid } from '@finos/legend-shared';
import { guaranteeNonNullable, isString, uuid } from '@finos/legend-shared';

// Core
export enum BuilderType {
Expand Down Expand Up @@ -144,13 +144,17 @@ export const getTDSRowRankByColumnInAsc = (
b: TDSRow,
colIndex: number,
): number => {
const a1 =
a.values[colIndex] === null || a.values[colIndex] === undefined
? -Infinity
: a.values[colIndex];
const b1 =
b.values[colIndex] === null || b.values[colIndex] === undefined
? -Infinity
: b.values[colIndex];
return Number(guaranteeNonNullable(a1)) - Number(guaranteeNonNullable(b1));
const a1 = a.values[colIndex];
const b1 = b.values[colIndex];
if (a1 === null || a1 === undefined) {
return -1;
}
if (b1 === null || b1 === undefined) {
return 1;
}
if (isString(a1) && isString(b1)) {
return a1.localeCompare(b1);
} else {
return Number(guaranteeNonNullable(a1)) - Number(guaranteeNonNullable(b1));
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -524,19 +524,18 @@ const QueryResultCellRenderer = observer(
) {
return undefined;
}
const sortedExecutionResult = [
...resultState.executionResult.result.rows,
];
if (params.columnApi.getColumnState()[colIndex]?.sort === 'asc') {
sortedExecutionResult.sort((a, b) =>
resultState.executionResult.result.rows.sort((a, b) =>
getTDSRowRankByColumnInAsc(a, b, colIndex),
);
} else if (params.columnApi.getColumnState()[colIndex]?.sort === 'desc') {
sortedExecutionResult.sort((a, b) =>
resultState.executionResult.result.rows.sort((a, b) =>
getTDSRowRankByColumnInAsc(b, a, colIndex),
);
}
return sortedExecutionResult[rowIndex]?.values[colIndex];
return resultState.executionResult.result.rows[rowIndex]?.values[
colIndex
];
};

const isCoordinatesSelected = (
Expand Down

0 comments on commit 5377836

Please sign in to comment.