-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ES|QL] Omits sorting non sortable fields on Discover histogram (#195531
) ## Summary Closes #195510 Sorting by `geo_point`, tsdb counter fields and _source is not supported in ES|QL. This PR is omitting the sorting for these types and now the breakdown works fine. <img width="2500" alt="image" src="https://github.com/user-attachments/assets/1526f516-5f8d-491d-8b77-1f9734ce83a4"> Note: This behavior is unreleased. ### Checklist - [x] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios (cherry picked from commit 2bb9c3c)
- Loading branch information
Showing
6 changed files
with
179 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
packages/kbn-esql-utils/src/utils/esql_fields_utils.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the "Elastic License | ||
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side | ||
* Public License v 1"; you may not use this file except in compliance with, at | ||
* your election, the "Elastic License 2.0", the "GNU Affero General Public | ||
* License v3.0 only", or the "Server Side Public License, v 1". | ||
*/ | ||
import type { DatatableColumn } from '@kbn/expressions-plugin/common'; | ||
import { isESQLColumnSortable } from './esql_fields_utils'; | ||
|
||
describe('esql fields helpers', () => { | ||
describe('isESQLColumnSortable', () => { | ||
it('returns false for geo fields', () => { | ||
const geoField = { | ||
id: 'geo.coordinates', | ||
name: 'geo.coordinates', | ||
meta: { | ||
type: 'geo_point', | ||
esType: 'geo_point', | ||
}, | ||
isNull: false, | ||
} as DatatableColumn; | ||
expect(isESQLColumnSortable(geoField)).toBeFalsy(); | ||
}); | ||
|
||
it('returns false for source fields', () => { | ||
const sourceField = { | ||
id: '_source', | ||
name: '_source', | ||
meta: { | ||
type: '_source', | ||
esType: '_source', | ||
}, | ||
isNull: false, | ||
} as DatatableColumn; | ||
expect(isESQLColumnSortable(sourceField)).toBeFalsy(); | ||
}); | ||
|
||
it('returns false for counter fields', () => { | ||
const tsdbField = { | ||
id: 'tsbd_counter', | ||
name: 'tsbd_counter', | ||
meta: { | ||
type: 'number', | ||
esType: 'counter_long', | ||
}, | ||
isNull: false, | ||
} as DatatableColumn; | ||
expect(isESQLColumnSortable(tsdbField)).toBeFalsy(); | ||
}); | ||
|
||
it('returns true for everything else', () => { | ||
const keywordField = { | ||
id: 'sortable', | ||
name: 'sortable', | ||
meta: { | ||
type: 'string', | ||
esType: 'keyword', | ||
}, | ||
isNull: false, | ||
} as DatatableColumn; | ||
expect(isESQLColumnSortable(keywordField)).toBeTruthy(); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the "Elastic License | ||
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side | ||
* Public License v 1"; you may not use this file except in compliance with, at | ||
* your election, the "Elastic License 2.0", the "GNU Affero General Public | ||
* License v3.0 only", or the "Server Side Public License, v 1". | ||
*/ | ||
|
||
import type { DatatableColumn } from '@kbn/expressions-plugin/common'; | ||
|
||
const SPATIAL_FIELDS = ['geo_point', 'geo_shape', 'point', 'shape']; | ||
const SOURCE_FIELD = '_source'; | ||
const TSDB_COUNTER_FIELDS_PREFIX = 'counter_'; | ||
|
||
/** | ||
* Check if a column is sortable. | ||
* | ||
* @param column The DatatableColumn of the field. | ||
* @returns True if the column is sortable, false otherwise. | ||
*/ | ||
|
||
export const isESQLColumnSortable = (column: DatatableColumn): boolean => { | ||
// We don't allow sorting on spatial fields | ||
if (SPATIAL_FIELDS.includes(column.meta?.type)) { | ||
return false; | ||
} | ||
|
||
// we don't allow sorting on the _source field | ||
if (column.meta?.type === SOURCE_FIELD) { | ||
return false; | ||
} | ||
|
||
// we don't allow sorting on tsdb counter fields | ||
if (column.meta?.esType && column.meta?.esType?.indexOf(TSDB_COUNTER_FIELDS_PREFIX) !== -1) { | ||
return false; | ||
} | ||
|
||
return true; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters