Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/platform/packages/shared/kbn-esql-ast/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export type {
AstProviderFn,
EditorError,
ESQLAstNode,
ESQLInlineCast,
} from './src/types';

export {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,14 @@ describe('esql query helpers', () => {
)
).toBe('event.timefield');
});

it('should return the time field if the column is casted', () => {
expect(
getTimeFieldFromESQLQuery(
'from a | WHERE date_nanos::date >= ?_tstart AND date_nanos::date <= ?_tend'
)
).toBe('date_nanos');
});
});

describe('prettifyQuery', function () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import type {
ESQLFunction,
ESQLColumn,
ESQLSingleAstItem,
ESQLInlineCast,
ESQLCommandOption,
} from '@kbn/esql-ast';
import type { ESQLControlVariable } from '@kbn/esql-types';
Expand Down Expand Up @@ -100,12 +101,27 @@ export const getTimeFieldFromESQLQuery = (esql: string) => {
}
const lowLevelFunction = allFunctionsWithNamedParams[allFunctionsWithNamedParams.length - 1];

const column = lowLevelFunction.args.find((arg) => {
const argument = arg as ESQLSingleAstItem;
return argument.type === 'column';
}) as ESQLColumn;
let columnName: string | undefined;

return column?.name;
lowLevelFunction.args.some((arg) => {
const argument = arg as ESQLSingleAstItem | ESQLInlineCast<ESQLSingleAstItem>;
if (argument.type === 'column') {
columnName = argument.name;
return true;
}

if (
argument.type === 'inlineCast' &&
(argument as ESQLInlineCast<ESQLSingleAstItem>).value.type === 'column'
) {
columnName = (argument as ESQLInlineCast<ESQLSingleAstItem>).value.name;
return true;
}

return false;
});

return columnName;
};

export const isQueryWrappedByPipes = (query: string): boolean => {
Expand Down