[ES|QL] Supports date_nanos in bucket (#213319)

## Summary

Supports date_nanos in BUCKET. (Fixes this
https://github.com/elastic/kibana/issues/192255#issuecomment-2682565258)

Create a date_nanos field like here
https://www.elastic.co/guide/en/elasticsearch/reference/current/date_nanos.html
Test it with bucket

<img width="776" alt="image"
src="https://github.com/user-attachments/assets/3ba7d1b6-9000-4fc9-8bf0-74fb6c335596"
/>


### Checklist

- [ ] [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
This commit is contained in:
Stratoula Kalafateli 2025-03-10 16:58:55 +01:00 committed by GitHub
parent 311417d78e
commit 3e78503858
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 64 additions and 12 deletions

View file

@ -43,6 +43,8 @@ const bucketParameterTypes: Array<
// field // bucket //from // to //result
['date', 'date_period', null, null, 'date'],
['date', 'integer', 'date', 'date', 'date'],
['date_nanos', 'date_period', null, null, 'date_nanos'],
['date_nanos', 'integer', 'date', 'date', 'date_nanos'],
// Modified time_duration to time_literal
['date', 'time_literal', null, null, 'date'],
['double', 'double', null, null, 'double'],

View file

@ -98,12 +98,16 @@ describe('autocomplete.suggest', () => {
const { assertSuggestions } = await setup();
await assertSuggestions('from a | stats by bucket(/', [
...getFieldNamesByType([...ESQL_COMMON_NUMERIC_TYPES, 'date']).map(
...getFieldNamesByType([...ESQL_COMMON_NUMERIC_TYPES, 'date', 'date_nanos']).map(
(field) => `${field}, `
),
...getFunctionSignaturesByReturnType('eval', ['date', ...ESQL_COMMON_NUMERIC_TYPES], {
scalar: true,
}).map((s) => ({ ...s, text: `${s.text},` })),
...getFunctionSignaturesByReturnType(
'eval',
['date', 'date_nanos', ...ESQL_COMMON_NUMERIC_TYPES],
{
scalar: true,
}
).map((s) => ({ ...s, text: `${s.text},` })),
]);
await assertSuggestions('from a | stats round(/', [
...getFunctionSignaturesByReturnType('stats', roundParameterTypes, {
@ -318,17 +322,25 @@ describe('autocomplete.suggest', () => {
const { assertSuggestions } = await setup();
await assertSuggestions('from a | stats avg(b) by BUCKET(/, 50, ?_tstart, ?_tend)', [
// Note there's no space or comma in the suggested field names
...getFieldNamesByType(['date', ...ESQL_COMMON_NUMERIC_TYPES]),
...getFunctionSignaturesByReturnType('eval', ['date', ...ESQL_COMMON_NUMERIC_TYPES], {
scalar: true,
}),
...getFieldNamesByType(['date', 'date_nanos', ...ESQL_COMMON_NUMERIC_TYPES]),
...getFunctionSignaturesByReturnType(
'eval',
['date', 'date_nanos', ...ESQL_COMMON_NUMERIC_TYPES],
{
scalar: true,
}
),
]);
await assertSuggestions('from a | stats avg(b) by BUCKET( / , 50, ?_tstart, ?_tend)', [
// Note there's no space or comma in the suggested field names
...getFieldNamesByType(['date', ...ESQL_COMMON_NUMERIC_TYPES]),
...getFunctionSignaturesByReturnType('eval', ['date', ...ESQL_COMMON_NUMERIC_TYPES], {
scalar: true,
}),
...getFieldNamesByType(['date', 'date_nanos', ...ESQL_COMMON_NUMERIC_TYPES]),
...getFunctionSignaturesByReturnType(
'eval',
['date', 'date_nanos', ...ESQL_COMMON_NUMERIC_TYPES],
{
scalar: true,
}
),
]);
await assertSuggestions(

View file

@ -78,6 +78,44 @@ const bucketDefinition: FunctionDefinition = {
],
returnType: 'date',
},
{
params: [
{
name: 'field',
type: 'date_nanos',
},
{
name: 'buckets',
type: 'date_period',
constantOnly: true,
},
],
returnType: 'date_nanos',
},
{
params: [
{
name: 'field',
type: 'date_nanos',
},
{
name: 'buckets',
type: 'integer',
constantOnly: true,
},
{
name: 'startDate',
type: 'date',
constantOnly: true,
},
{
name: 'endDate',
type: 'date',
constantOnly: true,
},
],
returnType: 'date_nanos',
},
{
params: [
{