-
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.
Merge branch 'main' into rule-footer-link
- Loading branch information
Showing
24 changed files
with
385 additions
and
211 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
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
Oops, something went wrong.