mirror of
https://github.com/apache/superset.git
synced 2026-04-19 08:04:53 +00:00
fix: revert and restore server-side sorting for value axis sorts (#39331)
This commit is contained in:
committed by
GitHub
parent
c971ea3ec6
commit
da371217ef
@@ -19,7 +19,6 @@
|
||||
import {
|
||||
QueryFormColumn,
|
||||
QueryFormData,
|
||||
QueryObject,
|
||||
QueryFormOrderBy,
|
||||
buildQueryContext,
|
||||
ensureIsArray,
|
||||
@@ -38,13 +37,17 @@ export default function buildQuery(formData: QueryFormData) {
|
||||
...ensureIsArray(groupby),
|
||||
];
|
||||
const orderby: QueryFormOrderBy[] = [];
|
||||
if (sort_x_axis && !sort_x_axis.includes('value')) {
|
||||
// Value sorts are applied post-query; SQL orderby biases row_limit truncation.
|
||||
orderby.push([columns[0], sort_x_axis.includes('asc')]);
|
||||
if (sort_x_axis) {
|
||||
orderby.push([
|
||||
sort_x_axis.includes('value') ? metric : columns[0],
|
||||
sort_x_axis.includes('asc'),
|
||||
]);
|
||||
}
|
||||
if (sort_y_axis && !sort_y_axis.includes('value')) {
|
||||
// Value sorts are applied post-query; SQL orderby biases row_limit truncation.
|
||||
orderby.push([columns[1], sort_y_axis.includes('asc')]);
|
||||
if (sort_y_axis) {
|
||||
orderby.push([
|
||||
sort_y_axis.includes('value') ? metric : columns[1],
|
||||
sort_y_axis.includes('asc'),
|
||||
]);
|
||||
}
|
||||
const group_by =
|
||||
normalize_across === 'x'
|
||||
@@ -52,7 +55,7 @@ export default function buildQuery(formData: QueryFormData) {
|
||||
: normalize_across === 'y'
|
||||
? getColumnLabel(groupby as unknown as QueryFormColumn)
|
||||
: undefined;
|
||||
return buildQueryContext(formData, (baseQueryObject: QueryObject) => [
|
||||
return buildQueryContext(formData, baseQueryObject => [
|
||||
{
|
||||
...baseQueryObject,
|
||||
columns,
|
||||
|
||||
@@ -32,25 +32,7 @@ const getQuery = (formData: QueryFormData) => buildQuery(formData).queries[0];
|
||||
const getRankOperation = (formData: QueryFormData) =>
|
||||
getQuery(formData).post_processing?.find(isPostProcessingRank);
|
||||
|
||||
test('Heatmap buildQuery omits orderby for value-based ascending X-axis sort', () => {
|
||||
const query = getQuery({
|
||||
...baseFormData,
|
||||
sort_x_axis: 'value_asc',
|
||||
});
|
||||
|
||||
expect(query.orderby).toEqual([]);
|
||||
});
|
||||
|
||||
test('Heatmap buildQuery omits orderby for value-based descending X-axis sort', () => {
|
||||
const query = getQuery({
|
||||
...baseFormData,
|
||||
sort_x_axis: 'value_desc',
|
||||
});
|
||||
|
||||
expect(query.orderby).toEqual([]);
|
||||
});
|
||||
|
||||
test('Heatmap buildQuery adds column orderby for alpha ascending X-axis sort', () => {
|
||||
test('adds X axis orderby when sorting alphabetically ascending', () => {
|
||||
const query = getQuery({
|
||||
...baseFormData,
|
||||
sort_x_axis: 'alpha_asc',
|
||||
@@ -59,49 +41,7 @@ test('Heatmap buildQuery adds column orderby for alpha ascending X-axis sort', (
|
||||
expect(query.orderby).toEqual([['category', true]]);
|
||||
});
|
||||
|
||||
test('Heatmap buildQuery adds column orderby for alpha descending X-axis sort', () => {
|
||||
const query = getQuery({
|
||||
...baseFormData,
|
||||
sort_x_axis: 'alpha_desc',
|
||||
});
|
||||
|
||||
expect(query.orderby).toEqual([['category', false]]);
|
||||
});
|
||||
|
||||
test('Heatmap buildQuery omits X-axis orderby when sort_x_axis is not set', () => {
|
||||
const query = getQuery({ ...baseFormData });
|
||||
|
||||
expect(query.orderby).toEqual([]);
|
||||
});
|
||||
|
||||
test('Heatmap buildQuery omits orderby for value-based ascending Y-axis sort', () => {
|
||||
const query = getQuery({
|
||||
...baseFormData,
|
||||
sort_y_axis: 'value_asc',
|
||||
});
|
||||
|
||||
expect(query.orderby).toEqual([]);
|
||||
});
|
||||
|
||||
test('Heatmap buildQuery omits orderby for value-based descending Y-axis sort', () => {
|
||||
const query = getQuery({
|
||||
...baseFormData,
|
||||
sort_y_axis: 'value_desc',
|
||||
});
|
||||
|
||||
expect(query.orderby).toEqual([]);
|
||||
});
|
||||
|
||||
test('Heatmap buildQuery adds column orderby for alpha ascending Y-axis sort', () => {
|
||||
const query = getQuery({
|
||||
...baseFormData,
|
||||
sort_y_axis: 'alpha_asc',
|
||||
});
|
||||
|
||||
expect(query.orderby).toEqual([['region', true]]);
|
||||
});
|
||||
|
||||
test('Heatmap buildQuery adds column orderby for alpha descending Y-axis sort', () => {
|
||||
test('adds Y axis orderby when sorting alphabetically descending', () => {
|
||||
const query = getQuery({
|
||||
...baseFormData,
|
||||
sort_y_axis: 'alpha_desc',
|
||||
@@ -110,13 +50,7 @@ test('Heatmap buildQuery adds column orderby for alpha descending Y-axis sort',
|
||||
expect(query.orderby).toEqual([['region', false]]);
|
||||
});
|
||||
|
||||
test('Heatmap buildQuery omits Y-axis orderby when sort_y_axis is not set', () => {
|
||||
const query = getQuery({ ...baseFormData });
|
||||
|
||||
expect(query.orderby).toEqual([]);
|
||||
});
|
||||
|
||||
test('Heatmap buildQuery always includes rank operation when normalized is true', () => {
|
||||
test('should ALWAYS include rank operation when normalized=true', () => {
|
||||
const rankOperation = getRankOperation({
|
||||
...baseFormData,
|
||||
normalized: true,
|
||||
@@ -126,7 +60,7 @@ test('Heatmap buildQuery always includes rank operation when normalized is true'
|
||||
expect(rankOperation?.operation).toBe('rank');
|
||||
});
|
||||
|
||||
test('Heatmap buildQuery always includes rank operation when normalized is false', () => {
|
||||
test('should ALWAYS include rank operation when normalized=false', () => {
|
||||
const rankOperation = getRankOperation({
|
||||
...baseFormData,
|
||||
normalized: false,
|
||||
@@ -136,8 +70,11 @@ test('Heatmap buildQuery always includes rank operation when normalized is false
|
||||
expect(rankOperation?.operation).toBe('rank');
|
||||
});
|
||||
|
||||
test('Heatmap buildQuery always includes rank operation when normalized is unset', () => {
|
||||
const rankOperation = getRankOperation({ ...baseFormData });
|
||||
test('should ALWAYS include rank operation when normalized is undefined', () => {
|
||||
const rankOperation = getRankOperation({
|
||||
...baseFormData,
|
||||
// normalized not set
|
||||
});
|
||||
|
||||
expect(rankOperation).toBeDefined();
|
||||
expect(rankOperation?.operation).toBe('rank');
|
||||
|
||||
Reference in New Issue
Block a user