mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 17:28:26 -04:00
[ES|QL] Moves the @timestamp assignment to the ESQL util (#186158)
## Summary This PR just moves the @timestamp assignment logic from the various consumers to the helper function. It is much cleaner that way and I want to add support of the named parameters so I want to have a central function to accomplish this https://github.com/elastic/kibana/issues/180805
This commit is contained in:
parent
41dc4173c5
commit
d243e4f28e
6 changed files with 13 additions and 30 deletions
|
@ -31,11 +31,19 @@ export async function getESQLAdHocDataview(
|
|||
indexPattern: string,
|
||||
dataViewsService: DataViewsPublicPluginStart
|
||||
) {
|
||||
return await dataViewsService.create({
|
||||
const dataView = await dataViewsService.create({
|
||||
title: indexPattern,
|
||||
type: ESQL_TYPE,
|
||||
id: await sha256(`esql-${indexPattern}`),
|
||||
});
|
||||
|
||||
// If the indexPattern is empty string means that the user used either the ROW or META FUNCTIONS / SHOW INFO commands
|
||||
// we don't want to add the @timestamp field in this case https://github.com/elastic/kibana/issues/163417
|
||||
if (indexPattern && dataView?.fields?.getByName?.('@timestamp')?.type === 'date') {
|
||||
dataView.timeFieldName = '@timestamp';
|
||||
}
|
||||
|
||||
return dataView;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -21,14 +21,7 @@ export async function getEsqlDataView(
|
|||
currentDataView?.isPersisted() ||
|
||||
indexPatternFromQuery !== currentDataView?.getIndexPattern()
|
||||
) {
|
||||
const dataViewObj = await getESQLAdHocDataview(indexPatternFromQuery, services.dataViews);
|
||||
|
||||
// If the indexPatternFromQuery is empty string means that the user used either the ROW or SHOW META / SHOW INFO commands
|
||||
// we don't want to add the @timestamp field in this case https://github.com/elastic/kibana/issues/163417
|
||||
if (indexPatternFromQuery && dataViewObj.fields.getByName('@timestamp')?.type === 'date') {
|
||||
dataViewObj.timeFieldName = '@timestamp';
|
||||
}
|
||||
return dataViewObj;
|
||||
return await getESQLAdHocDataview(indexPatternFromQuery, services.dataViews);
|
||||
}
|
||||
return currentDataView;
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
*/
|
||||
|
||||
import type { DataView, DataViewsContract } from '@kbn/data-views-plugin/public';
|
||||
import { getESQLAdHocDataview } from '@kbn/esql-utils';
|
||||
|
||||
/**
|
||||
* Get a saved data view that matches the index pattern (as close as possible)
|
||||
|
@ -34,14 +35,7 @@ export async function getOrCreateDataViewByIndexPattern(
|
|||
indexPatternFromQuery &&
|
||||
(currentDataView?.isPersisted() || indexPatternFromQuery !== currentDataView?.getIndexPattern())
|
||||
) {
|
||||
const dataViewObj = await dataViews.create({
|
||||
title: indexPatternFromQuery,
|
||||
});
|
||||
|
||||
if (dataViewObj.fields.getByName('@timestamp')?.type === 'date') {
|
||||
dataViewObj.timeFieldName = '@timestamp';
|
||||
}
|
||||
return dataViewObj;
|
||||
return await getESQLAdHocDataview(indexPatternFromQuery, dataViews);
|
||||
}
|
||||
return currentDataView;
|
||||
}
|
||||
|
|
|
@ -36,10 +36,6 @@ export const getSuggestions = async (
|
|||
? await deps.dataViews.create(dataViewSpec)
|
||||
: await getESQLAdHocDataview(indexPattern, deps.dataViews);
|
||||
|
||||
if (dataView.fields.getByName('@timestamp')?.type === 'date' && !dataViewSpec) {
|
||||
dataView.timeFieldName = '@timestamp';
|
||||
}
|
||||
|
||||
const columns = await getESQLQueryColumns({
|
||||
esqlQuery: 'esql' in query ? query.esql : '',
|
||||
search: deps.data.search.search,
|
||||
|
|
|
@ -88,9 +88,6 @@ export async function getStateFromAggregateQuery(
|
|||
const dataView = await getESQLAdHocDataview(indexPattern, dataViews);
|
||||
|
||||
if (dataView && dataView.id) {
|
||||
if (dataView?.fields?.getByName('@timestamp')?.type === 'date') {
|
||||
dataView.timeFieldName = '@timestamp';
|
||||
}
|
||||
dataViewId = dataView?.id;
|
||||
indexPatternRefs = [
|
||||
...indexPatternRefs,
|
||||
|
|
|
@ -124,12 +124,7 @@ export function VisualizeESQL({
|
|||
}, [lens]);
|
||||
|
||||
const dataViewAsync = useAsync(() => {
|
||||
return getESQLAdHocDataview(indexPattern, dataViews).then((dataView) => {
|
||||
if (dataView.fields.getByName('@timestamp')?.type === 'date') {
|
||||
dataView.timeFieldName = '@timestamp';
|
||||
}
|
||||
return dataView;
|
||||
});
|
||||
return getESQLAdHocDataview(indexPattern, dataViews);
|
||||
}, [indexPattern, dataViews]);
|
||||
|
||||
const chatFlyoutSecondSlotHandler = useContext(ObservabilityAIAssistantMultipaneFlyoutContext);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue