Skip to content

Commit d0258b1

Browse files
Merge branch 'main' into enable-value-list-moadl
2 parents 9767318 + d887763 commit d0258b1

39 files changed

Lines changed: 829 additions & 376 deletions

packages/kbn-esql-utils/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ export {
1717
getESQLWithSafeLimit,
1818
appendToESQLQuery,
1919
TextBasedLanguages,
20-
getESQLQueryColumns,
2120
} from './src';
2221

2322
export { ESQL_LATEST_VERSION } from './constants';

packages/kbn-esql-utils/src/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,3 @@ export {
1717
removeDropCommandsFromESQLQuery,
1818
} from './utils/query_parsing_helpers';
1919
export { appendToESQLQuery } from './utils/append_to_query';
20-
export { getESQLQueryColumns } from './utils/run_query_utils';

packages/kbn-esql-utils/src/utils/run_query_utils.ts

Lines changed: 0 additions & 52 deletions
This file was deleted.

packages/kbn-esql-utils/tsconfig.json

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,8 @@
1717
],
1818
"kbn_references": [
1919
"@kbn/data-views-plugin",
20-
"@kbn/data-plugin",
2120
"@kbn/crypto-browser",
2221
"@kbn/data-view-utils",
2322
"@kbn/esql-ast",
24-
"@kbn/expressions-plugin",
25-
"@kbn/field-types",
26-
"@kbn/es-types",
2723
]
2824
}

x-pack/packages/kbn-slo-schema/src/rest_specs/routes/fetch_historical_summary.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,13 @@ const fetchHistoricalSummaryParamsSchema = t.type({
3131
groupBy: allOrAnyStringOrArray,
3232
revision: t.number,
3333
}),
34-
t.partial({ remoteName: t.string }),
34+
t.partial({
35+
remoteName: t.string,
36+
range: t.type({
37+
from: t.string,
38+
to: t.string,
39+
}),
40+
}),
3541
])
3642
),
3743
}),

x-pack/packages/kbn-slo-schema/src/schema/common.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,10 @@ const groupSummarySchema = t.type({
8181
noData: t.number,
8282
});
8383

84-
const dateRangeSchema = t.type({ from: dateType, to: dateType });
84+
const dateRangeSchema = t.type({
85+
from: t.union([dateType, t.string]),
86+
to: t.union([dateType, t.string]),
87+
});
8588

8689
export {
8790
ALL_VALUE,

x-pack/plugins/lens/public/app_plugin/shared/edit_on_the_fly/helpers.test.ts

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* 2.0.
66
*/
77
import { dataViewPluginMocks } from '@kbn/data-views-plugin/public/mocks';
8-
import { getESQLQueryColumns } from '@kbn/esql-utils';
8+
import { fetchFieldsFromESQL } from '@kbn/text-based-editor';
99
import type { LensPluginStartDependencies } from '../../../plugin';
1010
import { createMockStartDependencies } from '../../../editor_frame_service/mocks';
1111
import {
@@ -18,44 +18,45 @@ import { suggestionsApi } from '../../../lens_suggestions_api';
1818
import { getSuggestions } from './helpers';
1919

2020
const mockSuggestionApi = suggestionsApi as jest.Mock;
21-
const mockFetchData = getESQLQueryColumns as jest.Mock;
21+
const mockFetchData = fetchFieldsFromESQL as jest.Mock;
2222

2323
jest.mock('../../../lens_suggestions_api', () => ({
2424
suggestionsApi: jest.fn(() => mockAllSuggestions),
2525
}));
2626

27-
jest.mock('@kbn/esql-utils', () => {
28-
return {
29-
getESQLQueryColumns: jest.fn().mockResolvedValue(() => [
30-
{
31-
name: '@timestamp',
32-
id: '@timestamp',
33-
meta: {
34-
type: 'date',
27+
jest.mock('@kbn/text-based-editor', () => ({
28+
fetchFieldsFromESQL: jest.fn(() => {
29+
return {
30+
columns: [
31+
{
32+
name: '@timestamp',
33+
id: '@timestamp',
34+
meta: {
35+
type: 'date',
36+
},
3537
},
36-
},
37-
{
38-
name: 'bytes',
39-
id: 'bytes',
40-
meta: {
41-
type: 'number',
38+
{
39+
name: 'bytes',
40+
id: 'bytes',
41+
meta: {
42+
type: 'number',
43+
},
4244
},
43-
},
44-
{
45-
name: 'memory',
46-
id: 'memory',
47-
meta: {
48-
type: 'number',
45+
{
46+
name: 'memory',
47+
id: 'memory',
48+
meta: {
49+
type: 'number',
50+
},
4951
},
50-
},
51-
]),
52-
getIndexPatternFromESQLQuery: jest.fn().mockReturnValue('index1'),
53-
};
54-
});
52+
],
53+
};
54+
}),
55+
}));
5556

5657
describe('getSuggestions', () => {
5758
const query = {
58-
esql: 'from index1 | limit 10 | stats average = avg(bytes)',
59+
esql: 'from index1 | limit 10 | stats average = avg(bytes',
5960
};
6061
const mockStartDependencies =
6162
createMockStartDependencies() as unknown as LensPluginStartDependencies;

x-pack/plugins/lens/public/app_plugin/shared/edit_on_the_fly/helpers.ts

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,39 @@
44
* 2.0; you may not use this file except in compliance with the Elastic License
55
* 2.0.
66
*/
7-
import {
8-
getIndexPatternFromSQLQuery,
9-
getIndexPatternFromESQLQuery,
10-
getESQLAdHocDataview,
11-
getESQLQueryColumns,
12-
} from '@kbn/esql-utils';
7+
import { getIndexPatternFromSQLQuery, getIndexPatternFromESQLQuery } from '@kbn/esql-utils';
138
import type { AggregateQuery } from '@kbn/es-query';
9+
import { getESQLAdHocDataview } from '@kbn/esql-utils';
1410
import { getLensAttributesFromSuggestion } from '@kbn/visualization-utils';
11+
import { fetchFieldsFromESQL } from '@kbn/text-based-editor';
1512
import type { DataViewSpec } from '@kbn/data-views-plugin/public';
1613
import type { TypedLensByValueInput } from '../../../embeddable/embeddable_component';
1714
import type { LensPluginStartDependencies } from '../../../plugin';
1815
import type { DatasourceMap, VisualizationMap } from '../../../types';
1916
import { suggestionsApi } from '../../../lens_suggestions_api';
2017

18+
export const getQueryColumns = async (
19+
query: AggregateQuery,
20+
deps: LensPluginStartDependencies,
21+
abortController?: AbortController
22+
) => {
23+
// Fetching only columns for ES|QL for performance reasons with limit 0
24+
// Important note: ES doesnt return the warnings for 0 limit,
25+
// I am skipping them in favor of performance now
26+
// but we should think another way to get them (from Lens embeddable or store)
27+
const performantQuery = { ...query };
28+
if ('esql' in performantQuery && performantQuery.esql) {
29+
performantQuery.esql = `${performantQuery.esql} | limit 0`;
30+
}
31+
const table = await fetchFieldsFromESQL(
32+
performantQuery,
33+
deps.expressions,
34+
undefined,
35+
abortController
36+
);
37+
return table?.columns;
38+
};
39+
2140
export const getSuggestions = async (
2241
query: AggregateQuery,
2342
deps: LensPluginStartDependencies,
@@ -46,12 +65,7 @@ export const getSuggestions = async (
4665
if (dataView.fields.getByName('@timestamp')?.type === 'date' && !dataViewSpec) {
4766
dataView.timeFieldName = '@timestamp';
4867
}
49-
50-
const columns = await getESQLQueryColumns({
51-
esqlQuery: 'esql' in query ? query.esql : '',
52-
search: deps.data.search,
53-
signal: abortController?.signal,
54-
});
68+
const columns = await getQueryColumns(query, deps, abortController);
5569
const context = {
5670
dataViewSpec: dataView?.toSpec(),
5771
fieldName: '',

x-pack/plugins/lens/public/editor_frame_service/mocks.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ export function createMockSetupDependencies() {
5555

5656
export function createMockStartDependencies() {
5757
return {
58-
data: dataPluginMock.createStartContract(),
58+
data: dataPluginMock.createSetupContract(),
5959
embeddable: embeddablePluginMock.createStartContract(),
6060
expressions: expressionsPluginMock.createStartContract(),
6161
charts: chartPluginMock.createStartContract(),

x-pack/plugins/lens/public/trigger_actions/open_lens_config/create_action_helpers.ts

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66
*/
77
import { createGetterSetter } from '@kbn/kibana-utils-plugin/common';
88
import type { CoreStart } from '@kbn/core/public';
9-
import { getESQLQueryColumns } from '@kbn/esql-utils';
109
import { getLensAttributesFromSuggestion } from '@kbn/visualization-utils';
1110
import { IncompatibleActionError } from '@kbn/ui-actions-plugin/public';
1211
import { PresentationContainer } from '@kbn/presentation-containers';
1312
import { getESQLAdHocDataview, getIndexForESQLQuery } from '@kbn/esql-utils';
1413
import type { Datasource, Visualization } from '../../types';
1514
import type { LensPluginStartDependencies } from '../../plugin';
15+
import { fetchDataFromAggregateQuery } from '../../datasources/text_based/fetch_data_from_aggregate_query';
1616
import { suggestionsApi } from '../../lens_suggestions_api';
1717
import { generateId } from '../../id_generator';
1818
import { executeEditAction } from './edit_action_helpers';
@@ -66,17 +66,21 @@ export async function executeCreateAction({
6666
// so we are requesting them with limit 0
6767
// this is much more performant than requesting
6868
// all the table
69-
const abortController = new AbortController();
70-
const columns = await getESQLQueryColumns({
71-
esqlQuery: `from ${defaultIndex}`,
72-
search: deps.data.search,
73-
signal: abortController.signal,
74-
});
69+
const performantQuery = {
70+
esql: `from ${defaultIndex} | limit 0`,
71+
};
72+
73+
const table = await fetchDataFromAggregateQuery(
74+
performantQuery,
75+
dataView,
76+
deps.data,
77+
deps.expressions
78+
);
7579

7680
const context = {
7781
dataViewSpec: dataView.toSpec(),
7882
fieldName: '',
79-
textBasedColumns: columns,
83+
textBasedColumns: table?.columns,
8084
query: defaultEsqlQuery,
8185
};
8286

0 commit comments

Comments
 (0)