[ES|QL] Remove SQL occurences from code (#182079)

## Summary

Cleanups the ES|QL code from occurences of SQL. We are not going to
support it so having an extra check on our code doesn't make any sense.

This was a leftover from the initial implementation of SQL support in
Discover which we removed at 8.11, when ESQL was released on tech
preview

---------

Co-authored-by: Marco Liberati <dej611@users.noreply.github.com>
This commit is contained in:
Stratoula Kalafateli 2024-05-03 10:19:50 +02:00 committed by GitHub
parent fafa0fbcd2
commit cd22c673ef
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
40 changed files with 75 additions and 290 deletions

View file

@ -51,7 +51,6 @@ export {
migrateFilter,
fromCombinedFilter,
isOfQueryType,
isOfEsqlQueryType,
isOfAggregateQueryType,
getAggregateQueryMode,
getLanguageDisplayName,

View file

@ -8,7 +8,7 @@
import { isOfQueryType, isOfAggregateQueryType, getAggregateQueryMode } from './es_aggregate_query';
describe('sql query helpers', () => {
describe('esql query helpers', () => {
describe('isOfQueryType', () => {
it('should return true for a Query type query', () => {
const flag = isOfQueryType({ query: 'foo', language: 'test' });
@ -16,7 +16,7 @@ describe('sql query helpers', () => {
});
it('should return false for an Aggregate type query', () => {
const flag = isOfQueryType({ sql: 'SELECT * FROM foo' });
const flag = isOfQueryType({ esql: 'FROM foo' });
expect(flag).toBe(false);
});
});
@ -33,17 +33,12 @@ describe('sql query helpers', () => {
});
it('should return true for an Aggregate type query', () => {
const flag = isOfAggregateQueryType({ sql: 'SELECT * FROM foo' });
const flag = isOfAggregateQueryType({ esql: 'FROM foo' });
expect(flag).toBe(true);
});
});
describe('getAggregateQueryMode', () => {
it('should return sql for an SQL AggregateQuery type', () => {
const mode = getAggregateQueryMode({ sql: 'SELECT * FROM foo' });
expect(mode).toBe('sql');
});
it('should return esql for an ESQL AggregateQuery type', () => {
const mode = getAggregateQueryMode({ esql: 'foo | where field > 100' });
expect(mode).toBe('esql');

View file

@ -16,21 +16,10 @@ export function isOfQueryType(arg?: Query | AggregateQuery): arg is Query {
}
// Checks if the query is of type AggregateQuery
// currently only supports the sql query type
// should be enhanced to support other query types
export function isOfAggregateQueryType(
query?: AggregateQuery | Query | { [key: string]: any }
): query is AggregateQuery {
return Boolean(query && ('sql' in query || 'esql' in query));
}
/**
* True if the query is of type AggregateQuery and is of type esql, false otherwise.
*/
export function isOfEsqlQueryType(
query?: AggregateQuery | Query | { [key: string]: any }
): query is { esql: string } {
return Boolean(query && 'esql' in query && !('sql' in query));
return Boolean(query && 'esql' in query);
}
// returns the language of the aggregate Query, sql, esql etc

View file

@ -16,7 +16,6 @@ export { decorateQuery } from './decorate_query';
export {
isOfQueryType,
isOfAggregateQueryType,
isOfEsqlQueryType,
getAggregateQueryMode,
getLanguageDisplayName,
} from './es_aggregate_query';

View file

@ -99,7 +99,8 @@ export type Query = {
language: string;
};
export type AggregateQuery = { sql: string } | { esql: string };
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
export type AggregateQuery = { esql: string };
/**
* An interface for a latitude-longitude pair

View file

@ -8,7 +8,6 @@
export {
getESQLAdHocDataview,
getIndexPatternFromSQLQuery,
getIndexPatternFromESQLQuery,
getLimitFromESQLQuery,
removeDropCommandsFromESQLQuery,

View file

@ -11,7 +11,6 @@ export { getESQLAdHocDataview, getIndexForESQLQuery } from './utils/get_esql_adh
export { getInitialESQLQuery } from './utils/get_initial_esql_query';
export { getESQLWithSafeLimit } from './utils/get_esql_with_safe_limit';
export {
getIndexPatternFromSQLQuery,
getIndexPatternFromESQLQuery,
getLimitFromESQLQuery,
removeDropCommandsFromESQLQuery,

View file

@ -7,50 +7,12 @@
*/
import {
getIndexPatternFromSQLQuery,
getIndexPatternFromESQLQuery,
getLimitFromESQLQuery,
removeDropCommandsFromESQLQuery,
} from './query_parsing_helpers';
describe('sql/esql query helpers', () => {
describe('getIndexPatternFromSQLQuery', () => {
it('should return the index pattern string from sql queries', () => {
const idxPattern1 = getIndexPatternFromSQLQuery('SELECT * FROM foo');
expect(idxPattern1).toBe('foo');
const idxPattern2 = getIndexPatternFromSQLQuery('SELECT woof, meow FROM "foo"');
expect(idxPattern2).toBe('foo');
const idxPattern3 = getIndexPatternFromSQLQuery('SELECT woof, meow FROM "the_index_pattern"');
expect(idxPattern3).toBe('the_index_pattern');
const idxPattern4 = getIndexPatternFromSQLQuery('SELECT woof, meow FROM "the-index-pattern"');
expect(idxPattern4).toBe('the-index-pattern');
const idxPattern5 = getIndexPatternFromSQLQuery('SELECT woof, meow from "the-index-pattern"');
expect(idxPattern5).toBe('the-index-pattern');
const idxPattern6 = getIndexPatternFromSQLQuery('SELECT woof, meow from "logstash-*"');
expect(idxPattern6).toBe('logstash-*');
const idxPattern7 = getIndexPatternFromSQLQuery(
'SELECT woof, meow from logstash-1234! WHERE field > 100'
);
expect(idxPattern7).toBe('logstash-1234!');
const idxPattern8 = getIndexPatternFromSQLQuery(
'SELECT * FROM (SELECT woof, miaou FROM "logstash-1234!" GROUP BY woof)'
);
expect(idxPattern8).toBe('logstash-1234!');
const idxPattern9 = getIndexPatternFromSQLQuery(
'SELECT * FROM remote_cluster:logs-* WHERE field > 20'
);
expect(idxPattern9).toBe('remote_cluster:logs-*');
});
});
describe('esql query helpers', () => {
describe('getIndexPatternFromESQLQuery', () => {
it('should return the index pattern string from esql queries', () => {
const idxPattern1 = getIndexPatternFromESQLQuery('FROM foo');

View file

@ -9,23 +9,6 @@ import { type ESQLSource, getAstAndSyntaxErrors } from '@kbn/esql-ast';
const DEFAULT_ESQL_LIMIT = 500;
// retrieves the index pattern from the aggregate query for SQL
export function getIndexPatternFromSQLQuery(sqlQuery?: string): string {
let sql = sqlQuery?.replaceAll('"', '').replaceAll("'", '');
const splitFroms = sql?.split(new RegExp(/FROM\s/, 'ig'));
const fromsLength = splitFroms?.length ?? 0;
if (splitFroms && splitFroms?.length > 2) {
sql = `${splitFroms[fromsLength - 2]} FROM ${splitFroms[fromsLength - 1]}`;
}
// case insensitive match for the index pattern
const regex = new RegExp(/FROM\s+([(\w*:)?\w*-.!@$^()~;]+)/, 'i');
const matches = sql?.match(regex);
if (matches) {
return matches[1];
}
return '';
}
// retrieves the index pattern from the aggregate query for ES|QL using ast parsing
export function getIndexPatternFromESQLQuery(esql?: string) {
const { ast } = getAstAndSyntaxErrors(esql);

View file

@ -138,14 +138,6 @@ export class ReportingCsvPanelAction implements ActionDefinition<ActionContext>
return false;
}
const savedSearch = embeddable.getSavedSearch();
const query = savedSearch?.searchSource.getField('query');
// using isOfAggregateQueryType(query) added increased the bundle size over the configured limit of 55.7KB
if (query && Boolean(query && 'sql' in query)) {
// hide exporting CSV for SQL
return false;
}
return embeddable.getInput().viewMode !== ViewMode.EDIT;
};

View file

@ -9,14 +9,7 @@
import React, { useRef, memo, useEffect, useState, useCallback, useMemo } from 'react';
import classNames from 'classnames';
import memoize from 'lodash/memoize';
import {
SQLLang,
monaco,
ESQL_LANG_ID,
ESQL_THEME_ID,
ESQLLang,
type ESQLCallbacks,
} from '@kbn/monaco';
import { monaco, ESQL_LANG_ID, ESQL_THEME_ID, ESQLLang, type ESQLCallbacks } from '@kbn/monaco';
import type { AggregateQuery } from '@kbn/es-query';
import { getAggregateQueryMode, getLanguageDisplayName } from '@kbn/es-query';
import type { DataViewsPublicPluginStart } from '@kbn/data-views-plugin/public';
@ -143,18 +136,6 @@ const KEYCODE_ARROW_DOWN = 40;
// for editor width smaller than this value we want to start hiding some text
const BREAKPOINT_WIDTH = 540;
const languageId = (language: string) => {
switch (language) {
case 'esql': {
return ESQL_LANG_ID;
}
case 'sql':
default: {
return SQLLang.ID;
}
}
};
let clickedOutside = false;
let initialRender = true;
let updateLinesFromModel = false;
@ -864,7 +845,7 @@ export const TextBasedLanguagesEditor = memo(function TextBasedLanguagesEditor({
/>
)}
<CodeEditor
languageId={languageId(language)}
languageId={ESQL_LANG_ID}
value={codeOneLiner || code}
options={codeEditorOptions}
width="100%"

View file

@ -9,7 +9,7 @@
import { useEffect, useState } from 'react';
import type { DataPublicPluginStart } from '@kbn/data-plugin/public';
import type { AggregateQuery, Query, Filter } from '@kbn/es-query';
import { getAggregateQueryMode, isOfAggregateQueryType } from '@kbn/es-query';
import { isOfAggregateQueryType } from '@kbn/es-query';
import { getResolvedDateRange } from '../utils/get_resolved_date_range';
import type { TimeRangeUpdatesType, SearchMode } from '../types';
@ -135,10 +135,7 @@ export function getSearchMode(query?: Query | AggregateQuery): SearchMode | unde
return undefined;
}
if (
isOfAggregateQueryType(query) &&
(getAggregateQueryMode(query) === 'sql' || getAggregateQueryMode(query) === 'esql')
) {
if (isOfAggregateQueryType(query)) {
return 'text-based';
}

View file

@ -82,13 +82,13 @@ describe('filters notification action', () => {
});
it('is compatible when api has at least one local query', async () => {
updateQuery({ sql: 'SELECT * FROM test_dataview' } as AggregateQuery);
updateQuery({ esql: 'FROM test_dataview' } as AggregateQuery);
expect(await action.isCompatible(context)).toBe(true);
});
it('is incompatible when api is in view mode', async () => {
updateFilters([getMockPhraseFilter('SuperField', 'SuperValue')]);
updateQuery({ sql: 'SELECT * FROM test_dataview' } as AggregateQuery);
updateQuery({ esql: 'FROM test_dataview' } as AggregateQuery);
updateViewMode('view');
expect(await action.isCompatible(context)).toBe(false);
});
@ -96,7 +96,7 @@ describe('filters notification action', () => {
it('calls onChange when view mode changes', () => {
const onChange = jest.fn();
updateFilters([getMockPhraseFilter('SuperField', 'SuperValue')]);
updateQuery({ sql: 'SELECT * FROM test_dataview' } as AggregateQuery);
updateQuery({ esql: 'FROM test_dataview' } as AggregateQuery);
action.subscribeToCompatibilityChanges(context, onChange);
updateViewMode('view');
expect(onChange).toHaveBeenCalledWith(false, action);
@ -112,7 +112,7 @@ describe('filters notification action', () => {
it('calls onChange when query changes', async () => {
const onChange = jest.fn();
action.subscribeToCompatibilityChanges(context, onChange);
updateQuery({ sql: 'SELECT * FROM test_dataview' } as AggregateQuery);
updateQuery({ esql: 'FROM test_dataview' } as AggregateQuery);
expect(onChange).toHaveBeenCalledWith(true, action);
});
});

View file

@ -90,7 +90,7 @@ describe('filters notification popover', () => {
});
it('renders the query section when given a query', async () => {
updateQuery({ sql: 'SELECT * FROM test_dataview' } as AggregateQuery);
updateQuery({ esql: 'FROM test_dataview' } as AggregateQuery);
await renderAndOpenPopover();
expect(await screen.findByTestId('filtersNotificationModal__query')).toBeInTheDocument();
});
@ -103,7 +103,7 @@ describe('filters notification popover', () => {
it('does not render an edit button when the query is ESQL', async () => {
updateFilters([getMockPhraseFilter('ay', 'oh')]);
updateQuery({ sql: 'SELECT * FROM test_dataview' } as AggregateQuery);
updateQuery({ esql: 'FROM test_dataview' } as AggregateQuery);
updateFilters([getMockPhraseFilter('ay', 'oh')]);
await renderAndOpenPopover();
expect(

View file

@ -48,7 +48,7 @@ export function FiltersNotificationPopover({ api }: { api: FiltersNotificationAc
}
} else {
setDisableEditButton(true);
const language: 'sql' | 'esql' | undefined = getAggregateQueryMode(query);
const language: 'esql' | undefined = getAggregateQueryMode(query);
return {
queryString: query[language as keyof AggregateQuery],
queryLanguage: language,

View file

@ -32,7 +32,7 @@ describe('textBasedQueryStateToExpressionAst', () => {
it('returns an object with the correct structure for an SQL query', async () => {
const actual = await textBasedQueryStateToExpressionAst({
filters: [],
query: { sql: 'SELECT * FROM foo' },
query: { esql: 'FROM foo' },
time: {
from: 'now',
to: 'now+7d',
@ -50,7 +50,7 @@ describe('textBasedQueryStateToExpressionAst', () => {
expect(actual).toHaveProperty(
'chain.2.arguments',
expect.objectContaining({
query: ['SELECT * FROM foo'],
query: ['FROM foo'],
})
);
});
@ -58,7 +58,7 @@ describe('textBasedQueryStateToExpressionAst', () => {
it('returns an object with the correct structure for an ES|QL query', async () => {
const actual = await textBasedQueryStateToExpressionAst({
filters: [],
query: { sql: 'FROM foo' },
query: { esql: 'FROM foo' },
time: {
from: 'now',
to: 'now+7d',

View file

@ -5,7 +5,7 @@
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/
import { isOfAggregateQueryType, getAggregateQueryMode, Query } from '@kbn/es-query';
import { isOfAggregateQueryType, Query } from '@kbn/es-query';
import { buildExpression, buildExpressionFunction } from '@kbn/expressions-plugin/common';
import {
ExpressionFunctionKibana,
@ -56,20 +56,15 @@ export function textBasedQueryStateToExpressionAst({
const ast = buildExpression([kibana, kibanaContext]).toAst();
if (query && isOfAggregateQueryType(query)) {
const mode = getAggregateQueryMode(query);
for (const esMode of ['sql', 'esql']) {
if (mode === esMode && esMode in query) {
const essql = aggregateQueryToAst({
query,
timeField: timeFieldName,
titleForInspector,
descriptionForInspector,
});
const esql = aggregateQueryToAst({
query,
timeField: timeFieldName,
titleForInspector,
descriptionForInspector,
});
if (essql) {
ast.chain.push(essql);
}
}
if (esql) {
ast.chain.push(esql);
}
}
return ast;

View file

@ -32,7 +32,7 @@ describe('textBasedQueryStateToAstWithValidation', () => {
});
const actual = await textBasedQueryStateToAstWithValidation({
filters: [],
query: { sql: 'SELECT * FROM foo' },
query: { esql: 'FROM foo' },
time: {
from: 'now',
to: 'now+7d',
@ -51,7 +51,7 @@ describe('textBasedQueryStateToAstWithValidation', () => {
expect(actual).toHaveProperty(
'chain.2.arguments',
expect.objectContaining({
query: ['SELECT * FROM foo'],
query: ['FROM foo'],
})
);
});
@ -59,7 +59,7 @@ describe('textBasedQueryStateToAstWithValidation', () => {
it('returns an object with the correct structure for text based language with non existing dataview', async () => {
const actual = await textBasedQueryStateToAstWithValidation({
filters: [],
query: { sql: 'SELECT * FROM index_pattern_with_no_data_view' },
query: { esql: 'FROM index_pattern_with_no_data_view' },
time: {
from: 'now',
to: 'now+7d',
@ -68,7 +68,7 @@ describe('textBasedQueryStateToAstWithValidation', () => {
expect(actual).toHaveProperty(
'chain.2.arguments',
expect.objectContaining({
query: ['SELECT * FROM index_pattern_with_no_data_view'],
query: ['FROM index_pattern_with_no_data_view'],
})
);
});

View file

@ -8,7 +8,6 @@
import { i18n } from '@kbn/i18n';
import { buildExpressionFunction, ExpressionAstFunction } from '@kbn/expressions-plugin/common';
import { AggregateQuery } from '../../query';
import { EssqlExpressionFunctionDefinition } from './essql';
import { EsqlExpressionFunctionDefinition } from './esql';
export const aggregateQueryToAst = ({
@ -22,19 +21,11 @@ export const aggregateQueryToAst = ({
titleForInspector?: string;
descriptionForInspector?: string;
}): undefined | ExpressionAstFunction => {
if ('sql' in query) {
return buildExpressionFunction<EssqlExpressionFunctionDefinition>('essql', {
query: query.sql,
timeField,
}).toAst();
}
if ('esql' in query) {
return buildExpressionFunction<EsqlExpressionFunctionDefinition>('esql', {
query: query.esql,
timeField,
locale: i18n.getLocale(),
titleForInspector,
descriptionForInspector,
}).toAst();
}
return buildExpressionFunction<EsqlExpressionFunctionDefinition>('esql', {
query: query.esql,
timeField,
locale: i18n.getLocale(),
titleForInspector,
descriptionForInspector,
}).toAst();
};

View file

@ -19,7 +19,7 @@ import { getSavedSearchFullPathUrl } from '@kbn/saved-search-plugin/public';
import useObservable from 'react-use/lib/useObservable';
import { reportPerformanceMetricEvent } from '@kbn/ebt-tools';
import { withSuspense } from '@kbn/shared-ux-utility';
import { isOfEsqlQueryType } from '@kbn/es-query';
import { isOfAggregateQueryType } from '@kbn/es-query';
import { getInitialESQLQuery } from '@kbn/esql-utils';
import { ESQL_TYPE } from '@kbn/data-view-utils';
import { useUrl } from './hooks/use_url';
@ -116,7 +116,7 @@ export function DiscoverMainRoute({
return true; // bypass NoData screen
}
if (isOfEsqlQueryType(stateContainer.appState.getState().query)) {
if (isOfAggregateQueryType(stateContainer.appState.getState().query)) {
return true;
}

View file

@ -66,12 +66,9 @@ export function useTextBasedQueryLanguage({
};
const { index, viewMode } = stateContainer.appState.getState();
let nextColumns: string[] = [];
const isTextBasedQueryLang =
recordRawType === 'plain' &&
isOfAggregateQueryType(query) &&
('sql' in query || 'esql' in query);
const isTextBasedQueryLang = recordRawType === 'plain' && isOfAggregateQueryType(query);
const hasResults = Boolean(next.result?.length);
let queryHasTransformationalCommands = 'sql' in query;
let queryHasTransformationalCommands = false;
if ('esql' in query) {
TRANSFORMATIONAL_COMMANDS.forEach((command: string) => {
if (query.esql.toLowerCase().includes(command)) {

View file

@ -6,11 +6,7 @@
* Side Public License, v 1.
*/
import type { AggregateQuery } from '@kbn/es-query';
import {
getESQLAdHocDataview,
getIndexPatternFromSQLQuery,
getIndexPatternFromESQLQuery,
} from '@kbn/esql-utils';
import { getESQLAdHocDataview, getIndexPatternFromESQLQuery } from '@kbn/esql-utils';
import { DataView } from '@kbn/data-views-plugin/common';
import { DiscoverServices } from '../../../build_services';
@ -19,13 +15,7 @@ export async function getDataViewByTextBasedQueryLang(
currentDataView: DataView | undefined,
services: DiscoverServices
) {
let indexPatternFromQuery = '';
if ('sql' in query) {
indexPatternFromQuery = getIndexPatternFromSQLQuery(query.sql);
}
if ('esql' in query) {
indexPatternFromQuery = getIndexPatternFromESQLQuery(query.esql);
}
const indexPatternFromQuery = getIndexPatternFromESQLQuery(query.esql);
if (
currentDataView?.isPersisted() ||

View file

@ -6,20 +6,11 @@
* Side Public License, v 1.
*/
import {
AggregateQuery,
Query,
isOfAggregateQueryType,
getAggregateQueryMode,
} from '@kbn/es-query';
import { AggregateQuery, Query, isOfAggregateQueryType } from '@kbn/es-query';
import { RecordRawType } from '../services/discover_data_state_container';
export function getRawRecordType(query?: Query | AggregateQuery) {
if (
query &&
isOfAggregateQueryType(query) &&
(getAggregateQueryMode(query) === 'sql' || getAggregateQueryMode(query) === 'esql')
) {
if (query && isOfAggregateQueryType(query)) {
return RecordRawType.PLAIN;
}

View file

@ -11,7 +11,6 @@ import { isTextBasedQuery } from './is_text_based_query';
describe('isTextBasedQuery', () => {
it('should work correctly', () => {
expect(isTextBasedQuery({ query: '', language: 'lucene' })).toEqual(false);
expect(isTextBasedQuery({ sql: 'SELECT * from foo' })).toEqual(true);
expect(isTextBasedQuery({ esql: 'from foo' })).toEqual(true);
expect(isTextBasedQuery()).toEqual(false);
});

View file

@ -33,7 +33,7 @@ export const canLinkLegacyEmbeddable = async (embeddable: CommonLegacyEmbeddable
const { isOfAggregateQueryType } = await import('@kbn/es-query');
const query = isFilterableEmbeddable(embeddable) && embeddable.getQuery();
// Textbased panels (i.e. ES|QL, SQL) should not save to library
// Textbased panels (i.e. ES|QL) should not save to library
const isTextBasedEmbeddable = isOfAggregateQueryType(query as AggregateQuery);
return Boolean(

View file

@ -7,12 +7,7 @@
*/
import { DataView, DataViewField, DataViewType } from '@kbn/data-views-plugin/common';
import {
AggregateQuery,
getAggregateQueryMode,
isOfAggregateQueryType,
Query,
} from '@kbn/es-query';
import { AggregateQuery, isOfAggregateQueryType, Query } from '@kbn/es-query';
import type { RequestAdapter } from '@kbn/inspector-plugin/public';
import { useCallback, useEffect, useMemo } from 'react';
import { UnifiedHistogramChartLoadEvent, UnifiedHistogramFetchStatus } from '../../types';
@ -56,11 +51,7 @@ export const useStateProps = ({
*/
const isPlainRecord = useMemo(() => {
return (
query &&
isOfAggregateQueryType(query) &&
['sql', 'esql'].some((mode) => mode === getAggregateQueryMode(query))
);
return query && isOfAggregateQueryType(query);
}, [query]);
const isTimeBased = useMemo(() => {

View file

@ -11,15 +11,5 @@ import { AggregateQuery } from '@kbn/es-query';
const TRANSFORMATIONAL_COMMANDS = ['stats', 'keep'];
export const shouldDisplayHistogram = (query: AggregateQuery) => {
let queryHasTransformationalCommands = false;
if ('esql' in query) {
TRANSFORMATIONAL_COMMANDS.forEach((command: string) => {
if (query.esql.toLowerCase().includes(command)) {
queryHasTransformationalCommands = true;
return;
}
});
}
return !queryHasTransformationalCommands;
return !TRANSFORMATIONAL_COMMANDS.some((command) => query.esql.toLowerCase().includes(command));
};

View file

@ -64,8 +64,8 @@ const kqlQuery = {
language: 'kuery',
};
const sqlQuery = {
sql: 'SELECT * FROM test',
const esqlQuery = {
esql: 'FROM test',
};
const createMockWebStorage = () => ({
@ -297,7 +297,7 @@ describe('QueryBarTopRowTopRow', () => {
it('Should NOT render query input bar if on text based languages mode', () => {
const component = mount(
wrapQueryBarTopRowInContext({
query: sqlQuery,
query: esqlQuery,
isDirty: false,
screenTitle: 'SQL Screen',
timeHistory: mockTimeHistory,
@ -322,7 +322,7 @@ describe('QueryBarTopRowTopRow', () => {
};
const component = mount(
wrapQueryBarTopRowInContext({
query: sqlQuery,
query: esqlQuery,
isDirty: false,
screenTitle: 'SQL Screen',
timeHistory: mockTimeHistory,

View file

@ -73,8 +73,8 @@ const kqlQuery = {
language: 'kuery',
};
const sqlQuery = {
sql: 'SELECT * from test',
const esqlQuery = {
esql: 'from test',
};
function wrapSearchBarInContext(testProps: any) {
@ -259,13 +259,13 @@ describe('SearchBar', () => {
expect(component.find(QUERY_INPUT).length).toBeTruthy();
});
it('Should NOT render the input query input, for sql query', () => {
it('Should NOT render the input query input, for es|ql query', () => {
const component = mount(
wrapSearchBarInContext({
indexPatterns: [mockIndexPattern],
screenTitle: 'test screen',
onQuerySubmit: noop,
query: sqlQuery,
query: esqlQuery,
})
);
expect(component.find(QUERY_INPUT).length).toBeFalsy();

View file

@ -815,7 +815,7 @@ export const LensTopNavMenu = ({
if (newQuery) {
if (!isEqual(newQuery, query)) {
dispatchSetState({ query: newQuery });
// check if query is text-based (sql, essql etc) and switchAndCleanDatasource
// check if query is text-based (esql etc) and switchAndCleanDatasource
if (isOfAggregateQueryType(newQuery) && !isOnTextBasedMode) {
setIsOnTextBasedMode(true);
dispatch(

View file

@ -4,9 +4,8 @@
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import { getIndexPatternFromSQLQuery, getIndexPatternFromESQLQuery } from '@kbn/esql-utils';
import { getIndexPatternFromESQLQuery, getESQLAdHocDataview } from '@kbn/esql-utils';
import type { AggregateQuery } from '@kbn/es-query';
import { getESQLAdHocDataview } from '@kbn/esql-utils';
import { getLensAttributesFromSuggestion } from '@kbn/visualization-utils';
import { fetchFieldsFromESQL } from '@kbn/text-based-editor';
import type { DataViewSpec } from '@kbn/data-views-plugin/public';
@ -47,13 +46,7 @@ export const getSuggestions = async (
abortController?: AbortController
) => {
try {
let indexPattern = '';
if ('sql' in query) {
indexPattern = getIndexPatternFromSQLQuery(query.sql);
}
if ('esql' in query) {
indexPattern = getIndexPatternFromESQLQuery(query.esql);
}
const indexPattern = getIndexPatternFromESQLQuery(query.esql);
const dataViewSpec = adHocDataViews.find((adHoc) => {
return adHoc.name === indexPattern;
});

View file

@ -52,22 +52,6 @@ jest.mock('./fetch_data_from_aggregate_query', () => ({
describe('Text based languages utils', () => {
describe('getIndexPatternFromTextBasedQuery', () => {
it('should return the index pattern for sql query', () => {
const indexPattern = getIndexPatternFromTextBasedQuery({
sql: 'SELECT bytes, memory from foo',
});
expect(indexPattern).toBe('foo');
});
it('should return empty index pattern for non sql query', () => {
const indexPattern = getIndexPatternFromTextBasedQuery({
lang1: 'SELECT bytes, memory from foo',
} as unknown as AggregateQuery);
expect(indexPattern).toBe('');
});
it('should return the index pattern for es|ql query', () => {
const indexPattern = getIndexPatternFromTextBasedQuery({
esql: 'from foo | keep bytes, memory ',

View file

@ -9,7 +9,7 @@ import type { DataPublicPluginStart } from '@kbn/data-plugin/public';
import type { ExpressionsStart } from '@kbn/expressions-plugin/public';
import { getESQLAdHocDataview } from '@kbn/esql-utils';
import type { AggregateQuery } from '@kbn/es-query';
import { getIndexPatternFromSQLQuery, getIndexPatternFromESQLQuery } from '@kbn/esql-utils';
import { getIndexPatternFromESQLQuery } from '@kbn/esql-utils';
import type { DatatableColumn } from '@kbn/expressions-plugin/public';
import { generateId } from '../../id_generator';
import { fetchDataFromAggregateQuery } from './fetch_data_from_aggregate_query';
@ -129,17 +129,7 @@ export async function getStateFromAggregateQuery(
}
export function getIndexPatternFromTextBasedQuery(query: AggregateQuery): string {
let indexPattern = '';
// sql queries
if ('sql' in query) {
indexPattern = getIndexPatternFromSQLQuery(query.sql);
}
if ('esql' in query) {
indexPattern = getIndexPatternFromESQLQuery(query.esql);
}
// other textbased queries....
return indexPattern;
return getIndexPatternFromESQLQuery(query.esql);
}
export const isNumeric = (column: TextBasedLayerColumn | DatatableColumn) =>

View file

@ -419,11 +419,7 @@ describe('ConfigPanel', () => {
datasourceMap.testDatasource.initializeDimension = jest.fn();
const props = getDefaultProps({ datasourceMap, visualizationMap });
const { instance } = await prepareAndMountComponent(
props,
{},
{ sql: 'SELECT * from "foo"' }
);
const { instance } = await prepareAndMountComponent(props, {}, { esql: 'from "foo"' });
expect(instance.find(AddLayerButton).exists()).toBe(false);
});
});

View file

@ -65,7 +65,7 @@ describe('suggestionsApi', () => {
fieldName: '',
textBasedColumns: textBasedQueryColumns,
query: {
sql: 'SELECT field1, field2 FROM "index1"',
esql: 'FROM "index1" | keep field1, field2',
},
};
const suggestions = suggestionsApi({ context, dataView, datasourceMap, visualizationMap });
@ -112,7 +112,7 @@ describe('suggestionsApi', () => {
fieldName: '',
textBasedColumns: textBasedQueryColumns,
query: {
sql: 'SELECT field1, field2 FROM "index1"',
esql: 'FROM "index1" | keep field1, field2',
},
};
const suggestions = suggestionsApi({ context, dataView, datasourceMap, visualizationMap });
@ -161,7 +161,7 @@ describe('suggestionsApi', () => {
fieldName: '',
textBasedColumns: textBasedQueryColumns,
query: {
sql: 'SELECT field1, field2 FROM "index1"',
esql: 'FROM "index1" | keep field1, field2',
},
};
const suggestions = suggestionsApi({ context, dataView, datasourceMap, visualizationMap });
@ -210,7 +210,7 @@ describe('suggestionsApi', () => {
fieldName: '',
textBasedColumns: textBasedQueryColumns,
query: {
sql: 'SELECT field1, field2 FROM "index1"',
esql: 'FROM "index1" | keep field1, field2',
},
};
const suggestions = suggestionsApi({
@ -273,7 +273,7 @@ describe('suggestionsApi', () => {
fieldName: '',
textBasedColumns: textBasedQueryColumns,
query: {
sql: 'SELECT field1, field2 FROM "index1"',
esql: 'FROM "index1" | keep field1, field2',
},
};
const suggestions = suggestionsApi({
@ -340,7 +340,7 @@ describe('suggestionsApi', () => {
fieldName: '',
textBasedColumns: textBasedQueryColumns,
query: {
sql: 'SELECT field1, field2 FROM "index1"',
esql: 'FROM "index1" | keep field1, field2',
},
};
const suggestions = suggestionsApi({

View file

@ -8,7 +8,6 @@
import type * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
import type { AggregateQuery, Filter, Query } from '@kbn/es-query';
import { isOfAggregateQueryType } from '@kbn/es-query';
import { isOfEsqlQueryType } from '@kbn/es-query';
import { fromKueryExpression, luceneStringToDsl, toElasticsearchQuery } from '@kbn/es-query';
import { getDefaultQuery } from '@kbn/data-plugin/public';
@ -22,7 +21,7 @@ export function processFilters(
// We do not support esql yet
let inputQuery: estypes.QueryDslQueryContainer = {};
if (!isOfEsqlQueryType(query) && !isOfAggregateQueryType(query)) {
if (!isOfAggregateQueryType(query)) {
inputQuery =
query.language === 'kuery'
? toElasticsearchQuery(fromKueryExpression(query.query as string))

View file

@ -257,9 +257,6 @@ export const filterStateInUrlRT = rt.partial({
language: rt.string,
query: rt.union([rt.string, rt.record(rt.string, rt.unknown)]),
}),
rt.strict({
sql: rt.string,
}),
rt.strict({
esql: rt.string,
}),
@ -280,9 +277,6 @@ export const legacyFilterStateInUrlRT = rt.union([
language: rt.string,
query: rt.union([rt.string, rt.record(rt.string, rt.unknown)]),
}),
rt.strict({
sql: rt.string,
}),
rt.strict({
esql: rt.string,
}),

View file

@ -101,9 +101,6 @@ export const queryRT = rt.union([
language: rt.string,
query: rt.union([rt.string, rt.record(rt.string, rt.unknown)]),
}),
rt.strict({
sql: rt.string,
}),
rt.strict({
esql: rt.string,
}),

View file

@ -18,13 +18,5 @@ export const convertToQueryType = (query: Query | AggregateQuery): Query => {
language: 'esql',
};
}
if ('sql' in query) {
return {
query: query.sql,
language: 'sql',
};
}
return query;
};

View file

@ -82,7 +82,7 @@ export const EsqlQueryExpression: React.FC<
const setDefaultExpressionValues = async () => {
setRuleProperty('params', currentRuleParams);
setQuery(esqlQuery ?? { esql: '' });
if (esqlQuery && 'esql' in esqlQuery) {
if (esqlQuery) {
if (esqlQuery.esql) {
refreshTimeFields(esqlQuery);
refreshEsFields(esqlQuery, false);