mirror of
https://github.com/elastic/kibana.git
synced 2025-06-28 11:05:39 -04:00
[ES|QL] Renames the ESQLRealField type to ESQLFieldWithMetadata (#219894)
## Summary Improves the naming of the `ESQLRealField` type --------- Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
parent
1a923ddd40
commit
c89c1ee30d
37 changed files with 139 additions and 131 deletions
|
@ -24,7 +24,11 @@ import {
|
||||||
|
|
||||||
import type { CoreStart } from '@kbn/core/public';
|
import type { CoreStart } from '@kbn/core/public';
|
||||||
|
|
||||||
import { ESQLCallbacks, ESQLRealField, validateQuery } from '@kbn/esql-validation-autocomplete';
|
import {
|
||||||
|
ESQLCallbacks,
|
||||||
|
ESQLFieldWithMetadata,
|
||||||
|
validateQuery,
|
||||||
|
} from '@kbn/esql-validation-autocomplete';
|
||||||
import type { StartDependencies } from './plugin';
|
import type { StartDependencies } from './plugin';
|
||||||
import { CodeSnippet } from './code_snippet';
|
import { CodeSnippet } from './code_snippet';
|
||||||
|
|
||||||
|
@ -56,7 +60,7 @@ export const App = (props: { core: CoreStart; plugins: StartDependencies }) => {
|
||||||
[
|
[
|
||||||
{ name: 'doubleField', type: 'double' },
|
{ name: 'doubleField', type: 'double' },
|
||||||
{ name: 'keywordField', type: 'keyword' },
|
{ name: 'keywordField', type: 'keyword' },
|
||||||
] as ESQLRealField[]
|
] as ESQLFieldWithMetadata[]
|
||||||
: undefined,
|
: undefined,
|
||||||
getPolicies: callbacksEnabled.policies
|
getPolicies: callbacksEnabled.policies
|
||||||
? async () => [
|
? async () => [
|
||||||
|
|
|
@ -34,7 +34,7 @@ import { fixESQLQueryWithVariables } from '@kbn/esql-utils';
|
||||||
import { createPortal } from 'react-dom';
|
import { createPortal } from 'react-dom';
|
||||||
import { css } from '@emotion/react';
|
import { css } from '@emotion/react';
|
||||||
import { ESQLVariableType, type ESQLControlVariable } from '@kbn/esql-types';
|
import { ESQLVariableType, type ESQLControlVariable } from '@kbn/esql-types';
|
||||||
import { type ESQLRealField } from '@kbn/esql-validation-autocomplete';
|
import { type ESQLFieldWithMetadata } from '@kbn/esql-validation-autocomplete';
|
||||||
import { FieldType } from '@kbn/esql-validation-autocomplete/src/definitions/types';
|
import { FieldType } from '@kbn/esql-validation-autocomplete/src/definitions/types';
|
||||||
import { EditorFooter } from './editor_footer';
|
import { EditorFooter } from './editor_footer';
|
||||||
import { fetchFieldsFromESQL } from './fetch_fields_from_esql';
|
import { fetchFieldsFromESQL } from './fetch_fields_from_esql';
|
||||||
|
@ -472,7 +472,7 @@ export const ESQLEditor = memo(function ESQLEditor({
|
||||||
undefined,
|
undefined,
|
||||||
variablesService?.esqlVariables
|
variablesService?.esqlVariables
|
||||||
).result;
|
).result;
|
||||||
const columns: ESQLRealField[] =
|
const columns: ESQLFieldWithMetadata[] =
|
||||||
table?.columns.map((c) => {
|
table?.columns.map((c) => {
|
||||||
return {
|
return {
|
||||||
name: c.name,
|
name: c.name,
|
||||||
|
|
|
@ -26,7 +26,7 @@ export { suggest } from './src/autocomplete/autocomplete';
|
||||||
export type {
|
export type {
|
||||||
ValidationErrors,
|
ValidationErrors,
|
||||||
ESQLUserDefinedColumn,
|
ESQLUserDefinedColumn,
|
||||||
ESQLRealField,
|
ESQLFieldWithMetadata,
|
||||||
ESQLPolicy,
|
ESQLPolicy,
|
||||||
ErrorTypes as ESQLValidationErrorTypes,
|
ErrorTypes as ESQLValidationErrorTypes,
|
||||||
} from './src/validation/types';
|
} from './src/validation/types';
|
||||||
|
|
|
@ -8,24 +8,24 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { camelCase } from 'lodash';
|
import { camelCase } from 'lodash';
|
||||||
import { ESQLRealField, JoinIndexAutocompleteItem } from '../validation/types';
|
import { ESQLFieldWithMetadata, JoinIndexAutocompleteItem } from '../validation/types';
|
||||||
import { fieldTypes } from '../definitions/types';
|
import { fieldTypes } from '../definitions/types';
|
||||||
import { ESQLCallbacks } from '../shared/types';
|
import { ESQLCallbacks } from '../shared/types';
|
||||||
|
|
||||||
export const fields: ESQLRealField[] = [
|
export const fields: ESQLFieldWithMetadata[] = [
|
||||||
...fieldTypes.map((type) => ({ name: `${camelCase(type)}Field`, type })),
|
...fieldTypes.map((type) => ({ name: `${camelCase(type)}Field`, type })),
|
||||||
{ name: 'any#Char$Field', type: 'double' },
|
{ name: 'any#Char$Field', type: 'double' },
|
||||||
{ name: 'kubernetes.something.something', type: 'double' },
|
{ name: 'kubernetes.something.something', type: 'double' },
|
||||||
{ name: '@timestamp', type: 'date' },
|
{ name: '@timestamp', type: 'date' },
|
||||||
];
|
];
|
||||||
|
|
||||||
export const enrichFields: ESQLRealField[] = [
|
export const enrichFields: ESQLFieldWithMetadata[] = [
|
||||||
{ name: 'otherField', type: 'text' },
|
{ name: 'otherField', type: 'text' },
|
||||||
{ name: 'yetAnotherField', type: 'double' },
|
{ name: 'yetAnotherField', type: 'double' },
|
||||||
];
|
];
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/naming-convention
|
// eslint-disable-next-line @typescript-eslint/naming-convention
|
||||||
export const unsupported_field: ESQLRealField[] = [
|
export const unsupported_field: ESQLFieldWithMetadata[] = [
|
||||||
{ name: 'unsupported_field', type: 'unsupported' },
|
{ name: 'unsupported_field', type: 'unsupported' },
|
||||||
];
|
];
|
||||||
|
|
||||||
|
@ -81,7 +81,7 @@ export function getCallbackMocks(): ESQLCallbacks {
|
||||||
return unsupported_field;
|
return unsupported_field;
|
||||||
}
|
}
|
||||||
if (/join_index/.test(query)) {
|
if (/join_index/.test(query)) {
|
||||||
const field: ESQLRealField = {
|
const field: ESQLFieldWithMetadata = {
|
||||||
name: 'keywordField',
|
name: 'keywordField',
|
||||||
type: 'unsupported',
|
type: 'unsupported',
|
||||||
hasConflict: true,
|
hasConflict: true,
|
||||||
|
|
|
@ -23,7 +23,7 @@ import * as autocomplete from '../autocomplete';
|
||||||
import type { ESQLCallbacks } from '../../shared/types';
|
import type { ESQLCallbacks } from '../../shared/types';
|
||||||
import type { EditorContext, SuggestionRawDefinition } from '../types';
|
import type { EditorContext, SuggestionRawDefinition } from '../types';
|
||||||
import { TIME_SYSTEM_PARAMS, TRIGGER_SUGGESTION_COMMAND, getSafeInsertText } from '../factories';
|
import { TIME_SYSTEM_PARAMS, TRIGGER_SUGGESTION_COMMAND, getSafeInsertText } from '../factories';
|
||||||
import { ESQLRealField } from '../../validation/types';
|
import { ESQLFieldWithMetadata } from '../../validation/types';
|
||||||
import {
|
import {
|
||||||
FieldType,
|
FieldType,
|
||||||
fieldTypes,
|
fieldTypes,
|
||||||
|
@ -52,7 +52,7 @@ export const TIME_PICKER_SUGGESTION: PartialSuggestionWithText = {
|
||||||
|
|
||||||
export const triggerCharacters = [',', '(', '=', ' '];
|
export const triggerCharacters = [',', '(', '=', ' '];
|
||||||
|
|
||||||
export type TestField = ESQLRealField & { suggestedAs?: string };
|
export type TestField = ESQLFieldWithMetadata & { suggestedAs?: string };
|
||||||
|
|
||||||
export const fields: TestField[] = [
|
export const fields: TestField[] = [
|
||||||
...fieldTypes.map((type) => ({
|
...fieldTypes.map((type) => ({
|
||||||
|
@ -278,7 +278,7 @@ export function createCustomCallbackMocks(
|
||||||
* `FROM index | EVAL foo = 1 | LIMIT 0` will be used to fetch columns. The response
|
* `FROM index | EVAL foo = 1 | LIMIT 0` will be used to fetch columns. The response
|
||||||
* will include "foo" as a column.
|
* will include "foo" as a column.
|
||||||
*/
|
*/
|
||||||
customColumnsSinceLastCommand?: ESQLRealField[],
|
customColumnsSinceLastCommand?: ESQLFieldWithMetadata[],
|
||||||
customSources?: Array<{ name: string; hidden: boolean }>,
|
customSources?: Array<{ name: string; hidden: boolean }>,
|
||||||
customPolicies?: Array<{
|
customPolicies?: Array<{
|
||||||
name: string;
|
name: string;
|
||||||
|
|
|
@ -40,7 +40,7 @@ import {
|
||||||
collectUserDefinedColumns,
|
collectUserDefinedColumns,
|
||||||
excludeUserDefinedColumnsFromCurrentCommand,
|
excludeUserDefinedColumnsFromCurrentCommand,
|
||||||
} from '../shared/user_defined_columns';
|
} from '../shared/user_defined_columns';
|
||||||
import type { ESQLRealField, ESQLUserDefinedColumn } from '../validation/types';
|
import type { ESQLFieldWithMetadata, ESQLUserDefinedColumn } from '../validation/types';
|
||||||
import {
|
import {
|
||||||
allStarConstant,
|
allStarConstant,
|
||||||
commaCompleteItem,
|
commaCompleteItem,
|
||||||
|
@ -84,7 +84,7 @@ import {
|
||||||
import { comparisonFunctions } from '../definitions/all_operators';
|
import { comparisonFunctions } from '../definitions/all_operators';
|
||||||
import { getRecommendedQueriesSuggestions } from './recommended_queries/suggestions';
|
import { getRecommendedQueriesSuggestions } from './recommended_queries/suggestions';
|
||||||
|
|
||||||
type GetFieldsMapFn = () => Promise<Map<string, ESQLRealField>>;
|
type GetFieldsMapFn = () => Promise<Map<string, ESQLFieldWithMetadata>>;
|
||||||
type GetPoliciesFn = () => Promise<SuggestionRawDefinition[]>;
|
type GetPoliciesFn = () => Promise<SuggestionRawDefinition[]>;
|
||||||
|
|
||||||
export async function suggest(
|
export async function suggest(
|
||||||
|
@ -279,7 +279,7 @@ async function getSuggestionsWithinCommandExpression(
|
||||||
const commandDef = getCommandDefinition(astContext.command.name);
|
const commandDef = getCommandDefinition(astContext.command.name);
|
||||||
|
|
||||||
// collect all fields + userDefinedColumns to suggest
|
// collect all fields + userDefinedColumns to suggest
|
||||||
const fieldsMap: Map<string, ESQLRealField> = await getFieldsMap();
|
const fieldsMap: Map<string, ESQLFieldWithMetadata> = await getFieldsMap();
|
||||||
const anyUserDefinedColumns = collectUserDefinedColumns(commands, fieldsMap, innerText);
|
const anyUserDefinedColumns = collectUserDefinedColumns(commands, fieldsMap, innerText);
|
||||||
|
|
||||||
const references = { fields: fieldsMap, userDefinedColumns: anyUserDefinedColumns };
|
const references = { fields: fieldsMap, userDefinedColumns: anyUserDefinedColumns };
|
||||||
|
@ -366,7 +366,7 @@ async function getFunctionArgsSuggestions(
|
||||||
if (!fnDefinition) {
|
if (!fnDefinition) {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
const fieldsMap: Map<string, ESQLRealField> = await getFieldsMap();
|
const fieldsMap: Map<string, ESQLFieldWithMetadata> = await getFieldsMap();
|
||||||
const anyUserDefinedColumns = collectUserDefinedColumns(commands, fieldsMap, innerText);
|
const anyUserDefinedColumns = collectUserDefinedColumns(commands, fieldsMap, innerText);
|
||||||
|
|
||||||
const references = {
|
const references = {
|
||||||
|
@ -604,7 +604,7 @@ async function getListArgsSuggestions(
|
||||||
// node is supposed to be the function who support a list argument (like the "in" operator)
|
// node is supposed to be the function who support a list argument (like the "in" operator)
|
||||||
// so extract the type of the first argument and suggest fields of that type
|
// so extract the type of the first argument and suggest fields of that type
|
||||||
if (node && isFunctionItem(node)) {
|
if (node && isFunctionItem(node)) {
|
||||||
const fieldsMap: Map<string, ESQLRealField> = await getFieldsMaps();
|
const fieldsMap: Map<string, ESQLFieldWithMetadata> = await getFieldsMaps();
|
||||||
const anyUserDefinedColumns = collectUserDefinedColumns(commands, fieldsMap, innerText);
|
const anyUserDefinedColumns = collectUserDefinedColumns(commands, fieldsMap, innerText);
|
||||||
// extract the current node from the userDefinedColumns inferred
|
// extract the current node from the userDefinedColumns inferred
|
||||||
anyUserDefinedColumns.forEach((values, key) => {
|
anyUserDefinedColumns.forEach((values, key) => {
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
* License v3.0 only", or the "Server Side Public License, v 1".
|
* License v3.0 only", or the "Server Side Public License, v 1".
|
||||||
*/
|
*/
|
||||||
import { synth } from '@kbn/esql-ast';
|
import { synth } from '@kbn/esql-ast';
|
||||||
import type { ESQLRealField } from '../../../validation/types';
|
import type { ESQLFieldWithMetadata } from '../../../validation/types';
|
||||||
import { fieldsSuggestionsAfter } from './fields_suggestions_after';
|
import { fieldsSuggestionsAfter } from './fields_suggestions_after';
|
||||||
|
|
||||||
describe('CHANGE_POINT', () => {
|
describe('CHANGE_POINT', () => {
|
||||||
|
@ -15,9 +15,9 @@ describe('CHANGE_POINT', () => {
|
||||||
const previousCommandFields = [
|
const previousCommandFields = [
|
||||||
{ name: 'field1', type: 'keyword' },
|
{ name: 'field1', type: 'keyword' },
|
||||||
{ name: 'count', type: 'double' },
|
{ name: 'count', type: 'double' },
|
||||||
] as ESQLRealField[];
|
] as ESQLFieldWithMetadata[];
|
||||||
|
|
||||||
const userDefinedColumns = [] as ESQLRealField[];
|
const userDefinedColumns = [] as ESQLFieldWithMetadata[];
|
||||||
|
|
||||||
const result = fieldsSuggestionsAfter(
|
const result = fieldsSuggestionsAfter(
|
||||||
synth.cmd`CHANGE_POINT count ON field1`,
|
synth.cmd`CHANGE_POINT count ON field1`,
|
||||||
|
@ -37,9 +37,9 @@ describe('CHANGE_POINT', () => {
|
||||||
const previousCommandFields = [
|
const previousCommandFields = [
|
||||||
{ name: 'field1', type: 'keyword' },
|
{ name: 'field1', type: 'keyword' },
|
||||||
{ name: 'count', type: 'double' },
|
{ name: 'count', type: 'double' },
|
||||||
] as ESQLRealField[];
|
] as ESQLFieldWithMetadata[];
|
||||||
|
|
||||||
const userDefinedColumns = [] as ESQLRealField[];
|
const userDefinedColumns = [] as ESQLFieldWithMetadata[];
|
||||||
|
|
||||||
const result = fieldsSuggestionsAfter(
|
const result = fieldsSuggestionsAfter(
|
||||||
synth.cmd`CHANGE_POINT count ON field1 AS changePointType, pValue`,
|
synth.cmd`CHANGE_POINT count ON field1 AS changePointType, pValue`,
|
||||||
|
|
|
@ -7,12 +7,12 @@
|
||||||
* License v3.0 only", or the "Server Side Public License, v 1".
|
* License v3.0 only", or the "Server Side Public License, v 1".
|
||||||
*/
|
*/
|
||||||
import { type ESQLAstCommand, type ESQLAstChangePointCommand, LeafPrinter } from '@kbn/esql-ast';
|
import { type ESQLAstCommand, type ESQLAstChangePointCommand, LeafPrinter } from '@kbn/esql-ast';
|
||||||
import type { ESQLRealField } from '../../../validation/types';
|
import type { ESQLFieldWithMetadata } from '../../../validation/types';
|
||||||
|
|
||||||
export const fieldsSuggestionsAfter = (
|
export const fieldsSuggestionsAfter = (
|
||||||
command: ESQLAstCommand,
|
command: ESQLAstCommand,
|
||||||
previousCommandFields: ESQLRealField[],
|
previousCommandFields: ESQLFieldWithMetadata[],
|
||||||
userDefinedColumns: ESQLRealField[]
|
userDefinedColumns: ESQLFieldWithMetadata[]
|
||||||
) => {
|
) => {
|
||||||
const { target } = command as ESQLAstChangePointCommand;
|
const { target } = command as ESQLAstChangePointCommand;
|
||||||
previousCommandFields.push(
|
previousCommandFields.push(
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
* License v3.0 only", or the "Server Side Public License, v 1".
|
* License v3.0 only", or the "Server Side Public License, v 1".
|
||||||
*/
|
*/
|
||||||
import { synth } from '@kbn/esql-ast';
|
import { synth } from '@kbn/esql-ast';
|
||||||
import type { ESQLRealField } from '../../../validation/types';
|
import type { ESQLFieldWithMetadata } from '../../../validation/types';
|
||||||
import { extractDissectColumnNames, fieldsSuggestionsAfter } from './fields_suggestions_after';
|
import { extractDissectColumnNames, fieldsSuggestionsAfter } from './fields_suggestions_after';
|
||||||
|
|
||||||
describe('DISSECT', () => {
|
describe('DISSECT', () => {
|
||||||
|
@ -73,9 +73,9 @@ describe('DISSECT', () => {
|
||||||
const previousCommandFields = [
|
const previousCommandFields = [
|
||||||
{ name: 'field1', type: 'keyword' },
|
{ name: 'field1', type: 'keyword' },
|
||||||
{ name: 'field2', type: 'double' },
|
{ name: 'field2', type: 'double' },
|
||||||
] as ESQLRealField[];
|
] as ESQLFieldWithMetadata[];
|
||||||
|
|
||||||
const userDefinedColumns = [] as ESQLRealField[];
|
const userDefinedColumns = [] as ESQLFieldWithMetadata[];
|
||||||
|
|
||||||
const result = fieldsSuggestionsAfter(
|
const result = fieldsSuggestionsAfter(
|
||||||
synth.cmd`DISSECT agent "%{firstWord}"`,
|
synth.cmd`DISSECT agent "%{firstWord}"`,
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
* License v3.0 only", or the "Server Side Public License, v 1".
|
* License v3.0 only", or the "Server Side Public License, v 1".
|
||||||
*/
|
*/
|
||||||
import { type ESQLAstCommand, walk } from '@kbn/esql-ast';
|
import { type ESQLAstCommand, walk } from '@kbn/esql-ast';
|
||||||
import type { ESQLRealField } from '../../../validation/types';
|
import type { ESQLFieldWithMetadata } from '../../../validation/types';
|
||||||
|
|
||||||
function unquoteTemplate(inputString: string): string {
|
function unquoteTemplate(inputString: string): string {
|
||||||
if (inputString.startsWith('"') && inputString.endsWith('"') && inputString.length >= 2) {
|
if (inputString.startsWith('"') && inputString.endsWith('"') && inputString.length >= 2) {
|
||||||
|
@ -33,8 +33,8 @@ export function extractDissectColumnNames(pattern: string): string[] {
|
||||||
|
|
||||||
export const fieldsSuggestionsAfter = (
|
export const fieldsSuggestionsAfter = (
|
||||||
command: ESQLAstCommand,
|
command: ESQLAstCommand,
|
||||||
previousCommandFields: ESQLRealField[],
|
previousCommandFields: ESQLFieldWithMetadata[],
|
||||||
userDefinedColumns: ESQLRealField[]
|
userDefinedColumns: ESQLFieldWithMetadata[]
|
||||||
) => {
|
) => {
|
||||||
const columns: string[] = [];
|
const columns: string[] = [];
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
* License v3.0 only", or the "Server Side Public License, v 1".
|
* License v3.0 only", or the "Server Side Public License, v 1".
|
||||||
*/
|
*/
|
||||||
import { synth } from '@kbn/esql-ast';
|
import { synth } from '@kbn/esql-ast';
|
||||||
import type { ESQLRealField } from '../../../validation/types';
|
import type { ESQLFieldWithMetadata } from '../../../validation/types';
|
||||||
import { fieldsSuggestionsAfter } from './fields_suggestions_after';
|
import { fieldsSuggestionsAfter } from './fields_suggestions_after';
|
||||||
|
|
||||||
describe('DROP', () => {
|
describe('DROP', () => {
|
||||||
|
@ -15,9 +15,9 @@ describe('DROP', () => {
|
||||||
const previousCommandFields = [
|
const previousCommandFields = [
|
||||||
{ name: 'field1', type: 'keyword' },
|
{ name: 'field1', type: 'keyword' },
|
||||||
{ name: 'field2', type: 'double' },
|
{ name: 'field2', type: 'double' },
|
||||||
] as ESQLRealField[];
|
] as ESQLFieldWithMetadata[];
|
||||||
|
|
||||||
const userDefinedColumns = [] as ESQLRealField[];
|
const userDefinedColumns = [] as ESQLFieldWithMetadata[];
|
||||||
|
|
||||||
const result = fieldsSuggestionsAfter(
|
const result = fieldsSuggestionsAfter(
|
||||||
synth.cmd`DROP field1`,
|
synth.cmd`DROP field1`,
|
||||||
|
|
|
@ -7,12 +7,12 @@
|
||||||
* License v3.0 only", or the "Server Side Public License, v 1".
|
* License v3.0 only", or the "Server Side Public License, v 1".
|
||||||
*/
|
*/
|
||||||
import { type ESQLAstCommand, walk } from '@kbn/esql-ast';
|
import { type ESQLAstCommand, walk } from '@kbn/esql-ast';
|
||||||
import type { ESQLRealField } from '../../../validation/types';
|
import type { ESQLFieldWithMetadata } from '../../../validation/types';
|
||||||
|
|
||||||
export const fieldsSuggestionsAfter = (
|
export const fieldsSuggestionsAfter = (
|
||||||
command: ESQLAstCommand,
|
command: ESQLAstCommand,
|
||||||
previousCommandFields: ESQLRealField[],
|
previousCommandFields: ESQLFieldWithMetadata[],
|
||||||
userDefinedColumns: ESQLRealField[]
|
userDefinedColumns: ESQLFieldWithMetadata[]
|
||||||
) => {
|
) => {
|
||||||
const columnsToDrop: string[] = [];
|
const columnsToDrop: string[] = [];
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
* License v3.0 only", or the "Server Side Public License, v 1".
|
* License v3.0 only", or the "Server Side Public License, v 1".
|
||||||
*/
|
*/
|
||||||
import { synth } from '@kbn/esql-ast';
|
import { synth } from '@kbn/esql-ast';
|
||||||
import type { ESQLRealField } from '../../../validation/types';
|
import type { ESQLFieldWithMetadata } from '../../../validation/types';
|
||||||
import { fieldsSuggestionsAfter } from './fields_suggestions_after';
|
import { fieldsSuggestionsAfter } from './fields_suggestions_after';
|
||||||
|
|
||||||
describe('FORK', () => {
|
describe('FORK', () => {
|
||||||
|
@ -15,9 +15,9 @@ describe('FORK', () => {
|
||||||
const previousCommandFields = [
|
const previousCommandFields = [
|
||||||
{ name: 'field1', type: 'keyword' },
|
{ name: 'field1', type: 'keyword' },
|
||||||
{ name: 'field2', type: 'double' },
|
{ name: 'field2', type: 'double' },
|
||||||
] as ESQLRealField[];
|
] as ESQLFieldWithMetadata[];
|
||||||
|
|
||||||
const userDefinedColumns = [] as ESQLRealField[];
|
const userDefinedColumns = [] as ESQLFieldWithMetadata[];
|
||||||
|
|
||||||
const result = fieldsSuggestionsAfter(
|
const result = fieldsSuggestionsAfter(
|
||||||
synth.cmd`FORK (LIMIT 10 ) (LIMIT 1000 ) `,
|
synth.cmd`FORK (LIMIT 10 ) (LIMIT 1000 ) `,
|
||||||
|
|
|
@ -8,12 +8,12 @@
|
||||||
*/
|
*/
|
||||||
import { uniqBy } from 'lodash';
|
import { uniqBy } from 'lodash';
|
||||||
import { type ESQLAstCommand } from '@kbn/esql-ast';
|
import { type ESQLAstCommand } from '@kbn/esql-ast';
|
||||||
import type { ESQLRealField } from '../../../validation/types';
|
import type { ESQLFieldWithMetadata } from '../../../validation/types';
|
||||||
|
|
||||||
export const fieldsSuggestionsAfter = (
|
export const fieldsSuggestionsAfter = (
|
||||||
command: ESQLAstCommand,
|
command: ESQLAstCommand,
|
||||||
previousCommandFields: ESQLRealField[],
|
previousCommandFields: ESQLFieldWithMetadata[],
|
||||||
userDefinedColumns: ESQLRealField[]
|
userDefinedColumns: ESQLFieldWithMetadata[]
|
||||||
) => {
|
) => {
|
||||||
return uniqBy(
|
return uniqBy(
|
||||||
[
|
[
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
* License v3.0 only", or the "Server Side Public License, v 1".
|
* License v3.0 only", or the "Server Side Public License, v 1".
|
||||||
*/
|
*/
|
||||||
import { synth } from '@kbn/esql-ast';
|
import { synth } from '@kbn/esql-ast';
|
||||||
import type { ESQLRealField } from '../../../validation/types';
|
import type { ESQLFieldWithMetadata } from '../../../validation/types';
|
||||||
import { extractSemanticsFromGrok, fieldsSuggestionsAfter } from './fields_suggestions_after';
|
import { extractSemanticsFromGrok, fieldsSuggestionsAfter } from './fields_suggestions_after';
|
||||||
|
|
||||||
describe('GROK', () => {
|
describe('GROK', () => {
|
||||||
|
@ -32,9 +32,9 @@ describe('GROK', () => {
|
||||||
const previousCommandFields = [
|
const previousCommandFields = [
|
||||||
{ name: 'field1', type: 'keyword' },
|
{ name: 'field1', type: 'keyword' },
|
||||||
{ name: 'field2', type: 'double' },
|
{ name: 'field2', type: 'double' },
|
||||||
] as ESQLRealField[];
|
] as ESQLFieldWithMetadata[];
|
||||||
|
|
||||||
const userDefinedColumns = [] as ESQLRealField[];
|
const userDefinedColumns = [] as ESQLFieldWithMetadata[];
|
||||||
|
|
||||||
const result = fieldsSuggestionsAfter(
|
const result = fieldsSuggestionsAfter(
|
||||||
synth.cmd`GROK agent "%{WORD:firstWord}"`,
|
synth.cmd`GROK agent "%{WORD:firstWord}"`,
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
* License v3.0 only", or the "Server Side Public License, v 1".
|
* License v3.0 only", or the "Server Side Public License, v 1".
|
||||||
*/
|
*/
|
||||||
import { type ESQLAstCommand, walk } from '@kbn/esql-ast';
|
import { type ESQLAstCommand, walk } from '@kbn/esql-ast';
|
||||||
import type { ESQLRealField } from '../../../validation/types';
|
import type { ESQLFieldWithMetadata } from '../../../validation/types';
|
||||||
|
|
||||||
function unquoteTemplate(inputString: string): string {
|
function unquoteTemplate(inputString: string): string {
|
||||||
if (inputString.startsWith('"') && inputString.endsWith('"') && inputString.length >= 2) {
|
if (inputString.startsWith('"') && inputString.endsWith('"') && inputString.length >= 2) {
|
||||||
|
@ -30,8 +30,8 @@ export function extractSemanticsFromGrok(pattern: string): string[] {
|
||||||
|
|
||||||
export const fieldsSuggestionsAfter = (
|
export const fieldsSuggestionsAfter = (
|
||||||
command: ESQLAstCommand,
|
command: ESQLAstCommand,
|
||||||
previousCommandFields: ESQLRealField[],
|
previousCommandFields: ESQLFieldWithMetadata[],
|
||||||
userDefinedColumns: ESQLRealField[]
|
userDefinedColumns: ESQLFieldWithMetadata[]
|
||||||
) => {
|
) => {
|
||||||
const columns: string[] = [];
|
const columns: string[] = [];
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
* License v3.0 only", or the "Server Side Public License, v 1".
|
* License v3.0 only", or the "Server Side Public License, v 1".
|
||||||
*/
|
*/
|
||||||
import { synth } from '@kbn/esql-ast';
|
import { synth } from '@kbn/esql-ast';
|
||||||
import type { ESQLRealField } from '../../../validation/types';
|
import type { ESQLFieldWithMetadata } from '../../../validation/types';
|
||||||
import { fieldsSuggestionsAfter } from './fields_suggestions_after';
|
import { fieldsSuggestionsAfter } from './fields_suggestions_after';
|
||||||
|
|
||||||
describe('fieldsSuggestionsAfterKeep', () => {
|
describe('fieldsSuggestionsAfterKeep', () => {
|
||||||
|
@ -15,9 +15,9 @@ describe('fieldsSuggestionsAfterKeep', () => {
|
||||||
const previousCommandFields = [
|
const previousCommandFields = [
|
||||||
{ name: 'field1', type: 'keyword' },
|
{ name: 'field1', type: 'keyword' },
|
||||||
{ name: 'field2', type: 'double' },
|
{ name: 'field2', type: 'double' },
|
||||||
] as ESQLRealField[];
|
] as ESQLFieldWithMetadata[];
|
||||||
|
|
||||||
const userDefinedColumns = [] as ESQLRealField[];
|
const userDefinedColumns = [] as ESQLFieldWithMetadata[];
|
||||||
|
|
||||||
const result = fieldsSuggestionsAfter(
|
const result = fieldsSuggestionsAfter(
|
||||||
synth.cmd`KEEP field1`,
|
synth.cmd`KEEP field1`,
|
||||||
|
|
|
@ -7,12 +7,12 @@
|
||||||
* License v3.0 only", or the "Server Side Public License, v 1".
|
* License v3.0 only", or the "Server Side Public License, v 1".
|
||||||
*/
|
*/
|
||||||
import { type ESQLAstCommand, walk } from '@kbn/esql-ast';
|
import { type ESQLAstCommand, walk } from '@kbn/esql-ast';
|
||||||
import type { ESQLRealField } from '../../../validation/types';
|
import type { ESQLFieldWithMetadata } from '../../../validation/types';
|
||||||
|
|
||||||
export const fieldsSuggestionsAfter = (
|
export const fieldsSuggestionsAfter = (
|
||||||
command: ESQLAstCommand,
|
command: ESQLAstCommand,
|
||||||
previousCommandFields: ESQLRealField[],
|
previousCommandFields: ESQLFieldWithMetadata[],
|
||||||
userDefinedColumns: ESQLRealField[]
|
userDefinedColumns: ESQLFieldWithMetadata[]
|
||||||
) => {
|
) => {
|
||||||
const columnsToKeep: string[] = [];
|
const columnsToKeep: string[] = [];
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
* License v3.0 only", or the "Server Side Public License, v 1".
|
* License v3.0 only", or the "Server Side Public License, v 1".
|
||||||
*/
|
*/
|
||||||
import { synth } from '@kbn/esql-ast';
|
import { synth } from '@kbn/esql-ast';
|
||||||
import type { ESQLRealField } from '../../../validation/types';
|
import type { ESQLFieldWithMetadata } from '../../../validation/types';
|
||||||
import { fieldsSuggestionsAfter } from './fields_suggestions_after';
|
import { fieldsSuggestionsAfter } from './fields_suggestions_after';
|
||||||
|
|
||||||
describe('RENAME', () => {
|
describe('RENAME', () => {
|
||||||
|
@ -15,9 +15,9 @@ describe('RENAME', () => {
|
||||||
const previousCommandFields = [
|
const previousCommandFields = [
|
||||||
{ name: 'field1', type: 'keyword' },
|
{ name: 'field1', type: 'keyword' },
|
||||||
{ name: 'field2', type: 'double' },
|
{ name: 'field2', type: 'double' },
|
||||||
] as ESQLRealField[];
|
] as ESQLFieldWithMetadata[];
|
||||||
|
|
||||||
const userDefinedColumns = [] as ESQLRealField[];
|
const userDefinedColumns = [] as ESQLFieldWithMetadata[];
|
||||||
|
|
||||||
const result = fieldsSuggestionsAfter(
|
const result = fieldsSuggestionsAfter(
|
||||||
synth.cmd`RENAME field1 as meow`,
|
synth.cmd`RENAME field1 as meow`,
|
||||||
|
|
|
@ -12,13 +12,13 @@ import {
|
||||||
type ESQLAstRenameExpression,
|
type ESQLAstRenameExpression,
|
||||||
type ESQLAstBaseItem,
|
type ESQLAstBaseItem,
|
||||||
} from '@kbn/esql-ast';
|
} from '@kbn/esql-ast';
|
||||||
import type { ESQLRealField } from '../../../validation/types';
|
import type { ESQLFieldWithMetadata } from '../../../validation/types';
|
||||||
import { isOptionItem } from '../../../shared/helpers';
|
import { isOptionItem } from '../../../shared/helpers';
|
||||||
|
|
||||||
export const fieldsSuggestionsAfter = (
|
export const fieldsSuggestionsAfter = (
|
||||||
command: ESQLAstCommand,
|
command: ESQLAstCommand,
|
||||||
previousCommandFields: ESQLRealField[],
|
previousCommandFields: ESQLFieldWithMetadata[],
|
||||||
userDefinedColumns: ESQLRealField[]
|
userDefinedColumns: ESQLFieldWithMetadata[]
|
||||||
) => {
|
) => {
|
||||||
const currentColumns: string[] = [];
|
const currentColumns: string[] = [];
|
||||||
const renamePairs: ESQLAstRenameExpression[] = [];
|
const renamePairs: ESQLAstRenameExpression[] = [];
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
* License v3.0 only", or the "Server Side Public License, v 1".
|
* License v3.0 only", or the "Server Side Public License, v 1".
|
||||||
*/
|
*/
|
||||||
import { synth } from '@kbn/esql-ast';
|
import { synth } from '@kbn/esql-ast';
|
||||||
import type { ESQLRealField } from '../../../validation/types';
|
import type { ESQLFieldWithMetadata } from '../../../validation/types';
|
||||||
import { fieldsSuggestionsAfter } from './fields_suggestions_after';
|
import { fieldsSuggestionsAfter } from './fields_suggestions_after';
|
||||||
|
|
||||||
describe('STATS', () => {
|
describe('STATS', () => {
|
||||||
|
@ -15,9 +15,9 @@ describe('STATS', () => {
|
||||||
const previousCommandFields = [
|
const previousCommandFields = [
|
||||||
{ name: 'field1', type: 'keyword' },
|
{ name: 'field1', type: 'keyword' },
|
||||||
{ name: 'field2', type: 'double' },
|
{ name: 'field2', type: 'double' },
|
||||||
] as ESQLRealField[];
|
] as ESQLFieldWithMetadata[];
|
||||||
|
|
||||||
const userDefinedColumns = [{ name: 'var0', type: 'double' }] as ESQLRealField[];
|
const userDefinedColumns = [{ name: 'var0', type: 'double' }] as ESQLFieldWithMetadata[];
|
||||||
|
|
||||||
const result = fieldsSuggestionsAfter(
|
const result = fieldsSuggestionsAfter(
|
||||||
synth.cmd`STATS var0=AVG(field2)`,
|
synth.cmd`STATS var0=AVG(field2)`,
|
||||||
|
@ -32,9 +32,9 @@ describe('STATS', () => {
|
||||||
const previousCommandFields = [
|
const previousCommandFields = [
|
||||||
{ name: 'field1', type: 'keyword' },
|
{ name: 'field1', type: 'keyword' },
|
||||||
{ name: 'field2', type: 'double' },
|
{ name: 'field2', type: 'double' },
|
||||||
] as ESQLRealField[];
|
] as ESQLFieldWithMetadata[];
|
||||||
|
|
||||||
const userDefinedColumns = [{ name: 'AVG(field2)', type: 'double' }] as ESQLRealField[];
|
const userDefinedColumns = [{ name: 'AVG(field2)', type: 'double' }] as ESQLFieldWithMetadata[];
|
||||||
|
|
||||||
const result = fieldsSuggestionsAfter(
|
const result = fieldsSuggestionsAfter(
|
||||||
synth.cmd`STATS AVG(field2)`,
|
synth.cmd`STATS AVG(field2)`,
|
||||||
|
@ -49,9 +49,9 @@ describe('STATS', () => {
|
||||||
const previousCommandFields = [
|
const previousCommandFields = [
|
||||||
{ name: 'field1', type: 'keyword' },
|
{ name: 'field1', type: 'keyword' },
|
||||||
{ name: 'field2', type: 'double' },
|
{ name: 'field2', type: 'double' },
|
||||||
] as ESQLRealField[];
|
] as ESQLFieldWithMetadata[];
|
||||||
|
|
||||||
const userDefinedColumns = [{ name: 'AVG(field2)', type: 'double' }] as ESQLRealField[];
|
const userDefinedColumns = [{ name: 'AVG(field2)', type: 'double' }] as ESQLFieldWithMetadata[];
|
||||||
|
|
||||||
const result = fieldsSuggestionsAfter(
|
const result = fieldsSuggestionsAfter(
|
||||||
synth.cmd`STATS AVG(field2) BY field1`,
|
synth.cmd`STATS AVG(field2) BY field1`,
|
||||||
|
@ -70,12 +70,12 @@ describe('STATS', () => {
|
||||||
{ name: 'field1', type: 'keyword' },
|
{ name: 'field1', type: 'keyword' },
|
||||||
{ name: 'field2', type: 'double' },
|
{ name: 'field2', type: 'double' },
|
||||||
{ name: '@timestamp', type: 'date' },
|
{ name: '@timestamp', type: 'date' },
|
||||||
] as ESQLRealField[];
|
] as ESQLFieldWithMetadata[];
|
||||||
|
|
||||||
const userDefinedColumns = [
|
const userDefinedColumns = [
|
||||||
{ name: 'AVG(field2)', type: 'double' },
|
{ name: 'AVG(field2)', type: 'double' },
|
||||||
{ name: 'buckets', type: 'unknown' },
|
{ name: 'buckets', type: 'unknown' },
|
||||||
] as ESQLRealField[];
|
] as ESQLFieldWithMetadata[];
|
||||||
|
|
||||||
const result = fieldsSuggestionsAfter(
|
const result = fieldsSuggestionsAfter(
|
||||||
synth.cmd`STATS AVG(field2) BY buckets=BUCKET(@timestamp,50,?_tstart,?_tend)`,
|
synth.cmd`STATS AVG(field2) BY buckets=BUCKET(@timestamp,50,?_tstart,?_tend)`,
|
||||||
|
|
|
@ -8,13 +8,13 @@
|
||||||
*/
|
*/
|
||||||
import { uniqBy } from 'lodash';
|
import { uniqBy } from 'lodash';
|
||||||
import { type ESQLAstCommand, walk } from '@kbn/esql-ast';
|
import { type ESQLAstCommand, walk } from '@kbn/esql-ast';
|
||||||
import type { ESQLRealField } from '../../../validation/types';
|
import type { ESQLFieldWithMetadata } from '../../../validation/types';
|
||||||
import { isColumnItem } from '../../../shared/helpers';
|
import { isColumnItem } from '../../../shared/helpers';
|
||||||
|
|
||||||
export const fieldsSuggestionsAfter = (
|
export const fieldsSuggestionsAfter = (
|
||||||
command: ESQLAstCommand,
|
command: ESQLAstCommand,
|
||||||
previousCommandFields: ESQLRealField[],
|
previousCommandFields: ESQLFieldWithMetadata[],
|
||||||
userDefinedColumns: ESQLRealField[]
|
userDefinedColumns: ESQLFieldWithMetadata[]
|
||||||
) => {
|
) => {
|
||||||
const columns: string[] = [];
|
const columns: string[] = [];
|
||||||
|
|
||||||
|
|
|
@ -25,7 +25,7 @@ import {
|
||||||
import { shouldBeQuotedSource, shouldBeQuotedText } from '../shared/helpers';
|
import { shouldBeQuotedSource, shouldBeQuotedText } from '../shared/helpers';
|
||||||
import { buildFunctionDocumentation } from './documentation_util';
|
import { buildFunctionDocumentation } from './documentation_util';
|
||||||
import { DOUBLE_BACKTICK, SINGLE_TICK_REGEX } from '../shared/constants';
|
import { DOUBLE_BACKTICK, SINGLE_TICK_REGEX } from '../shared/constants';
|
||||||
import { ESQLRealField } from '../validation/types';
|
import { ESQLFieldWithMetadata } from '../validation/types';
|
||||||
import { getTestFunctions } from '../shared/test_functions';
|
import { getTestFunctions } from '../shared/test_functions';
|
||||||
import { operatorsDefinitions } from '../definitions/all_operators';
|
import { operatorsDefinitions } from '../definitions/all_operators';
|
||||||
|
|
||||||
|
@ -199,7 +199,7 @@ export const getSuggestionsAfterNot = (): SuggestionRawDefinition[] => {
|
||||||
};
|
};
|
||||||
|
|
||||||
export const buildFieldsDefinitionsWithMetadata = (
|
export const buildFieldsDefinitionsWithMetadata = (
|
||||||
fields: ESQLRealField[],
|
fields: ESQLFieldWithMetadata[],
|
||||||
options?: {
|
options?: {
|
||||||
advanceCursor?: boolean;
|
advanceCursor?: boolean;
|
||||||
openSuggestions?: boolean;
|
openSuggestions?: boolean;
|
||||||
|
|
|
@ -47,7 +47,7 @@ import {
|
||||||
isLiteralItem,
|
isLiteralItem,
|
||||||
isTimeIntervalItem,
|
isTimeIntervalItem,
|
||||||
} from '../shared/helpers';
|
} from '../shared/helpers';
|
||||||
import { ESQLRealField, ESQLUserDefinedColumn, ReferenceMaps } from '../validation/types';
|
import { ESQLFieldWithMetadata, ESQLUserDefinedColumn, ReferenceMaps } from '../validation/types';
|
||||||
import { listCompleteItem } from './complete_items';
|
import { listCompleteItem } from './complete_items';
|
||||||
import {
|
import {
|
||||||
TIME_SYSTEM_PARAMS,
|
TIME_SYSTEM_PARAMS,
|
||||||
|
@ -267,7 +267,7 @@ export function isLiteralDateItem(nodeArg: ESQLAstItem): boolean {
|
||||||
export function getValidSignaturesAndTypesToSuggestNext(
|
export function getValidSignaturesAndTypesToSuggestNext(
|
||||||
node: ESQLFunction,
|
node: ESQLFunction,
|
||||||
references: {
|
references: {
|
||||||
fields: Map<string, ESQLRealField>;
|
fields: Map<string, ESQLFieldWithMetadata>;
|
||||||
userDefinedColumns: Map<string, ESQLUserDefinedColumn[]>;
|
userDefinedColumns: Map<string, ESQLUserDefinedColumn[]>;
|
||||||
},
|
},
|
||||||
fnDefinition: FunctionDefinition,
|
fnDefinition: FunctionDefinition,
|
||||||
|
|
|
@ -7,12 +7,12 @@
|
||||||
* License v3.0 only", or the "Server Side Public License, v 1".
|
* License v3.0 only", or the "Server Side Public License, v 1".
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import type { ESQLRealField } from '../../validation/types';
|
import type { ESQLFieldWithMetadata } from '../../validation/types';
|
||||||
import { type ECSMetadata, enrichFieldsWithECSInfo } from './ecs_metadata_helper';
|
import { type ECSMetadata, enrichFieldsWithECSInfo } from './ecs_metadata_helper';
|
||||||
|
|
||||||
describe('enrichFieldsWithECSInfo', () => {
|
describe('enrichFieldsWithECSInfo', () => {
|
||||||
it('should return original columns if fieldsMetadata is not provided', async () => {
|
it('should return original columns if fieldsMetadata is not provided', async () => {
|
||||||
const columns: ESQLRealField[] = [
|
const columns: ESQLFieldWithMetadata[] = [
|
||||||
{ name: 'ecs.version', type: 'keyword' },
|
{ name: 'ecs.version', type: 'keyword' },
|
||||||
{ name: 'field1', type: 'text' },
|
{ name: 'field1', type: 'text' },
|
||||||
{ name: 'field2', type: 'double' },
|
{ name: 'field2', type: 'double' },
|
||||||
|
@ -23,7 +23,7 @@ describe('enrichFieldsWithECSInfo', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return columns with metadata if both name and type match with ECS fields', async () => {
|
it('should return columns with metadata if both name and type match with ECS fields', async () => {
|
||||||
const columns: ESQLRealField[] = [
|
const columns: ESQLFieldWithMetadata[] = [
|
||||||
{ name: 'ecs.field', type: 'text' },
|
{ name: 'ecs.field', type: 'text' },
|
||||||
{ name: 'ecs.fakeBooleanField', type: 'boolean' },
|
{ name: 'ecs.fakeBooleanField', type: 'boolean' },
|
||||||
{ name: 'field2', type: 'double' },
|
{ name: 'field2', type: 'double' },
|
||||||
|
@ -65,7 +65,7 @@ describe('enrichFieldsWithECSInfo', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should handle keyword suffix correctly', async () => {
|
it('should handle keyword suffix correctly', async () => {
|
||||||
const columns: ESQLRealField[] = [
|
const columns: ESQLFieldWithMetadata[] = [
|
||||||
{ name: 'ecs.version', type: 'keyword' },
|
{ name: 'ecs.version', type: 'keyword' },
|
||||||
{ name: 'ecs.version.keyword', type: 'keyword' },
|
{ name: 'ecs.version.keyword', type: 'keyword' },
|
||||||
{ name: 'field2', type: 'double' },
|
{ name: 'field2', type: 'double' },
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
* License v3.0 only", or the "Server Side Public License, v 1".
|
* License v3.0 only", or the "Server Side Public License, v 1".
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import type { ESQLRealField } from '../../validation/types';
|
import type { ESQLFieldWithMetadata } from '../../validation/types';
|
||||||
|
|
||||||
const removeKeywordSuffix = (name: string) => {
|
const removeKeywordSuffix = (name: string) => {
|
||||||
return name.endsWith('.keyword') ? name.slice(0, -8) : name;
|
return name.endsWith('.keyword') ? name.slice(0, -8) : name;
|
||||||
|
@ -29,9 +29,9 @@ export interface ECSMetadata {
|
||||||
* @returns
|
* @returns
|
||||||
*/
|
*/
|
||||||
export function enrichFieldsWithECSInfo(
|
export function enrichFieldsWithECSInfo(
|
||||||
columns: Array<Omit<ESQLRealField, 'metadata'>>,
|
columns: Array<Omit<ESQLFieldWithMetadata, 'metadata'>>,
|
||||||
ecsMetadataCache?: ECSMetadata
|
ecsMetadataCache?: ECSMetadata
|
||||||
): ESQLRealField[] {
|
): ESQLFieldWithMetadata[] {
|
||||||
if (!ecsMetadataCache) return columns;
|
if (!ecsMetadataCache) return columns;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -24,7 +24,7 @@ import {
|
||||||
} from '../shared/helpers';
|
} from '../shared/helpers';
|
||||||
import { FieldType, FunctionDefinitionTypes } from './types';
|
import { FieldType, FunctionDefinitionTypes } from './types';
|
||||||
import { getMessageFromId } from '../validation/errors';
|
import { getMessageFromId } from '../validation/errors';
|
||||||
import { ESQLRealField } from '../validation/types';
|
import { ESQLFieldWithMetadata } from '../validation/types';
|
||||||
|
|
||||||
function isAggregation(arg: ESQLAstItem): arg is ESQLFunction {
|
function isAggregation(arg: ESQLAstItem): arg is ESQLFunction {
|
||||||
return (
|
return (
|
||||||
|
@ -112,7 +112,7 @@ export const ENRICH_MODES = [
|
||||||
|
|
||||||
export const validateColumnForGrokDissect = (
|
export const validateColumnForGrokDissect = (
|
||||||
command: ESQLCommand,
|
command: ESQLCommand,
|
||||||
{ fields }: { fields: Map<string, ESQLRealField> }
|
{ fields }: { fields: Map<string, ESQLFieldWithMetadata> }
|
||||||
) => {
|
) => {
|
||||||
const acceptedColumnTypes: FieldType[] = ['keyword', 'text'];
|
const acceptedColumnTypes: FieldType[] = ['keyword', 'text'];
|
||||||
const astCol = command.args[0] as ESQLColumn;
|
const astCol = command.args[0] as ESQLColumn;
|
||||||
|
|
|
@ -16,7 +16,7 @@ import type {
|
||||||
} from '@kbn/esql-ast';
|
} from '@kbn/esql-ast';
|
||||||
import { ESQLControlVariable } from '@kbn/esql-types';
|
import { ESQLControlVariable } from '@kbn/esql-types';
|
||||||
import { GetColumnsByTypeFn, SuggestionRawDefinition } from '../autocomplete/types';
|
import { GetColumnsByTypeFn, SuggestionRawDefinition } from '../autocomplete/types';
|
||||||
import type { ESQLPolicy, ReferenceMaps, ESQLRealField } from '../validation/types';
|
import type { ESQLPolicy, ReferenceMaps, ESQLFieldWithMetadata } from '../validation/types';
|
||||||
import { ESQLCallbacks, ESQLSourceResult } from '../shared/types';
|
import { ESQLCallbacks, ESQLSourceResult } from '../shared/types';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -427,9 +427,9 @@ export interface CommandDefinition<CommandName extends string> {
|
||||||
*/
|
*/
|
||||||
fieldsSuggestionsAfter?: (
|
fieldsSuggestionsAfter?: (
|
||||||
lastCommand: ESQLAstCommand,
|
lastCommand: ESQLAstCommand,
|
||||||
previousCommandFields: ESQLRealField[],
|
previousCommandFields: ESQLFieldWithMetadata[],
|
||||||
userDefinedColumns: ESQLRealField[]
|
userDefinedColumns: ESQLFieldWithMetadata[]
|
||||||
) => ESQLRealField[];
|
) => ESQLFieldWithMetadata[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface CommandTypeDefinition {
|
export interface CommandTypeDefinition {
|
||||||
|
|
|
@ -48,7 +48,11 @@ import {
|
||||||
FunctionDefinitionTypes,
|
FunctionDefinitionTypes,
|
||||||
getLocationFromCommandOrOptionName,
|
getLocationFromCommandOrOptionName,
|
||||||
} from '../definitions/types';
|
} from '../definitions/types';
|
||||||
import type { ESQLRealField, ESQLUserDefinedColumn, ReferenceMaps } from '../validation/types';
|
import type {
|
||||||
|
ESQLFieldWithMetadata,
|
||||||
|
ESQLUserDefinedColumn,
|
||||||
|
ReferenceMaps,
|
||||||
|
} from '../validation/types';
|
||||||
import { removeMarkerArgFromArgsList } from './context';
|
import { removeMarkerArgFromArgsList } from './context';
|
||||||
import type { ReasonTypes, ESQLCallbacks } from './types';
|
import type { ReasonTypes, ESQLCallbacks } from './types';
|
||||||
import { DOUBLE_TICKS_REGEX, EDITOR_MARKER, SINGLE_BACKTICK } from './constants';
|
import { DOUBLE_TICKS_REGEX, EDITOR_MARKER, SINGLE_BACKTICK } from './constants';
|
||||||
|
@ -259,7 +263,7 @@ function doesLiteralMatchParameterType(argType: FunctionParameterType, item: ESQ
|
||||||
export function getColumnForASTNode(
|
export function getColumnForASTNode(
|
||||||
node: ESQLColumn | ESQLIdentifier,
|
node: ESQLColumn | ESQLIdentifier,
|
||||||
{ fields, userDefinedColumns }: Pick<ReferenceMaps, 'fields' | 'userDefinedColumns'>
|
{ fields, userDefinedColumns }: Pick<ReferenceMaps, 'fields' | 'userDefinedColumns'>
|
||||||
): ESQLRealField | ESQLUserDefinedColumn | undefined {
|
): ESQLFieldWithMetadata | ESQLUserDefinedColumn | undefined {
|
||||||
const formatted = node.type === 'identifier' ? node.name : node.parts.join('.');
|
const formatted = node.type === 'identifier' ? node.name : node.parts.join('.');
|
||||||
return getColumnByName(formatted, { fields, userDefinedColumns });
|
return getColumnByName(formatted, { fields, userDefinedColumns });
|
||||||
}
|
}
|
||||||
|
@ -282,7 +286,7 @@ export function unescapeColumnName(columnName: string) {
|
||||||
export function getColumnByName(
|
export function getColumnByName(
|
||||||
columnName: string,
|
columnName: string,
|
||||||
{ fields, userDefinedColumns }: Pick<ReferenceMaps, 'fields' | 'userDefinedColumns'>
|
{ fields, userDefinedColumns }: Pick<ReferenceMaps, 'fields' | 'userDefinedColumns'>
|
||||||
): ESQLRealField | ESQLUserDefinedColumn | undefined {
|
): ESQLFieldWithMetadata | ESQLUserDefinedColumn | undefined {
|
||||||
const unescaped = unescapeColumnName(columnName);
|
const unescaped = unescapeColumnName(columnName);
|
||||||
return fields.get(unescaped) || userDefinedColumns.get(unescaped)?.[0];
|
return fields.get(unescaped) || userDefinedColumns.get(unescaped)?.[0];
|
||||||
}
|
}
|
||||||
|
@ -549,7 +553,7 @@ export function hasWildcard(name: string) {
|
||||||
return /\*/.test(name);
|
return /\*/.test(name);
|
||||||
}
|
}
|
||||||
export function isUserDefinedColumn(
|
export function isUserDefinedColumn(
|
||||||
column: ESQLRealField | ESQLUserDefinedColumn | undefined
|
column: ESQLFieldWithMetadata | ESQLUserDefinedColumn | undefined
|
||||||
): column is ESQLUserDefinedColumn {
|
): column is ESQLUserDefinedColumn {
|
||||||
return Boolean(column && 'location' in column);
|
return Boolean(column && 'location' in column);
|
||||||
}
|
}
|
||||||
|
@ -813,7 +817,7 @@ export function getParamAtPosition(
|
||||||
*/
|
*/
|
||||||
export function getExpressionType(
|
export function getExpressionType(
|
||||||
root: ESQLAstItem | undefined,
|
root: ESQLAstItem | undefined,
|
||||||
fields?: Map<string, ESQLRealField>,
|
fields?: Map<string, ESQLFieldWithMetadata>,
|
||||||
userDefinedColumns?: Map<string, ESQLUserDefinedColumn[]>
|
userDefinedColumns?: Map<string, ESQLUserDefinedColumn[]>
|
||||||
): SupportedDataType | 'unknown' {
|
): SupportedDataType | 'unknown' {
|
||||||
if (!root) {
|
if (!root) {
|
||||||
|
@ -933,16 +937,16 @@ export function getExpressionType(
|
||||||
return 'unknown';
|
return 'unknown';
|
||||||
}
|
}
|
||||||
|
|
||||||
export function transformMapToRealFields(
|
export function transformMapToESQLFields(
|
||||||
inputMap: Map<string, ESQLUserDefinedColumn[]>
|
inputMap: Map<string, ESQLUserDefinedColumn[]>
|
||||||
): ESQLRealField[] {
|
): ESQLFieldWithMetadata[] {
|
||||||
const realFields: ESQLRealField[] = [];
|
const esqlFields: ESQLFieldWithMetadata[] = [];
|
||||||
|
|
||||||
for (const [, userDefinedColumns] of inputMap) {
|
for (const [, userDefinedColumns] of inputMap) {
|
||||||
for (const userDefinedColumn of userDefinedColumns) {
|
for (const userDefinedColumn of userDefinedColumns) {
|
||||||
// Only include userDefinedColumns that have a known type
|
// Only include userDefinedColumns that have a known type
|
||||||
if (userDefinedColumn.type) {
|
if (userDefinedColumn.type) {
|
||||||
realFields.push({
|
esqlFields.push({
|
||||||
name: userDefinedColumn.name,
|
name: userDefinedColumn.name,
|
||||||
type: userDefinedColumn.type as FieldType,
|
type: userDefinedColumn.type as FieldType,
|
||||||
});
|
});
|
||||||
|
@ -950,7 +954,7 @@ export function transformMapToRealFields(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return realFields;
|
return esqlFields;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getEcsMetadata(resourceRetriever?: ESQLCallbacks) {
|
async function getEcsMetadata(resourceRetriever?: ESQLCallbacks) {
|
||||||
|
@ -982,9 +986,9 @@ export async function getFieldsFromES(query: string, resourceRetriever?: ESQLCal
|
||||||
export async function getCurrentQueryAvailableFields(
|
export async function getCurrentQueryAvailableFields(
|
||||||
query: string,
|
query: string,
|
||||||
commands: ESQLAstCommand[],
|
commands: ESQLAstCommand[],
|
||||||
previousPipeFields: ESQLRealField[]
|
previousPipeFields: ESQLFieldWithMetadata[]
|
||||||
) {
|
) {
|
||||||
const cacheCopy = new Map<string, ESQLRealField>();
|
const cacheCopy = new Map<string, ESQLFieldWithMetadata>();
|
||||||
previousPipeFields?.forEach((field) => cacheCopy.set(field.name, field));
|
previousPipeFields?.forEach((field) => cacheCopy.set(field.name, field));
|
||||||
const lastCommand = commands[commands.length - 1];
|
const lastCommand = commands[commands.length - 1];
|
||||||
const commandDef = getCommandDefinition(lastCommand.name);
|
const commandDef = getCommandDefinition(lastCommand.name);
|
||||||
|
@ -992,7 +996,7 @@ export async function getCurrentQueryAvailableFields(
|
||||||
// If the command has a fieldsSuggestionsAfter function, use it to get the fields
|
// If the command has a fieldsSuggestionsAfter function, use it to get the fields
|
||||||
if (commandDef.fieldsSuggestionsAfter) {
|
if (commandDef.fieldsSuggestionsAfter) {
|
||||||
const userDefinedColumns = collectUserDefinedColumns([lastCommand], cacheCopy, query);
|
const userDefinedColumns = collectUserDefinedColumns([lastCommand], cacheCopy, query);
|
||||||
const arrayOfUserDefinedColumns: ESQLRealField[] = transformMapToRealFields(
|
const arrayOfUserDefinedColumns: ESQLFieldWithMetadata[] = transformMapToESQLFields(
|
||||||
userDefinedColumns ?? new Map<string, ESQLUserDefinedColumn[]>()
|
userDefinedColumns ?? new Map<string, ESQLUserDefinedColumn[]>()
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -1004,7 +1008,7 @@ export async function getCurrentQueryAvailableFields(
|
||||||
} else {
|
} else {
|
||||||
// If the command doesn't have a fieldsSuggestionsAfter function, use the default behavior
|
// If the command doesn't have a fieldsSuggestionsAfter function, use the default behavior
|
||||||
const userDefinedColumns = collectUserDefinedColumns(commands, cacheCopy, query);
|
const userDefinedColumns = collectUserDefinedColumns(commands, cacheCopy, query);
|
||||||
const arrayOfUserDefinedColumns: ESQLRealField[] = transformMapToRealFields(
|
const arrayOfUserDefinedColumns: ESQLFieldWithMetadata[] = transformMapToESQLFields(
|
||||||
userDefinedColumns ?? new Map<string, ESQLUserDefinedColumn[]>()
|
userDefinedColumns ?? new Map<string, ESQLUserDefinedColumn[]>()
|
||||||
);
|
);
|
||||||
const allFields = uniqBy([...(previousPipeFields ?? []), ...arrayOfUserDefinedColumns], 'name');
|
const allFields = uniqBy([...(previousPipeFields ?? []), ...arrayOfUserDefinedColumns], 'name');
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
*/
|
*/
|
||||||
import { type ESQLAst, parse } from '@kbn/esql-ast';
|
import { type ESQLAst, parse } from '@kbn/esql-ast';
|
||||||
import type { ESQLCallbacks } from './types';
|
import type { ESQLCallbacks } from './types';
|
||||||
import type { ESQLRealField } from '../validation/types';
|
import type { ESQLFieldWithMetadata } from '../validation/types';
|
||||||
import { getFieldsFromES, getCurrentQueryAvailableFields } from './helpers';
|
import { getFieldsFromES, getCurrentQueryAvailableFields } from './helpers';
|
||||||
import {
|
import {
|
||||||
removeLastPipe,
|
removeLastPipe,
|
||||||
|
@ -24,7 +24,7 @@ export function buildQueryUntilPreviousCommand(ast: ESQLAst, queryString: string
|
||||||
return prevCommand ? queryString.substring(0, prevCommand.location.max + 1) : queryString;
|
return prevCommand ? queryString.substring(0, prevCommand.location.max + 1) : queryString;
|
||||||
}
|
}
|
||||||
|
|
||||||
const cache = new Map<string, ESQLRealField[]>();
|
const cache = new Map<string, ESQLFieldWithMetadata[]>();
|
||||||
|
|
||||||
// Function to check if a key exists in the cache, ignoring case
|
// Function to check if a key exists in the cache, ignoring case
|
||||||
function checkCacheInsensitive(keyToCheck: string) {
|
function checkCacheInsensitive(keyToCheck: string) {
|
||||||
|
@ -96,7 +96,7 @@ export function getFieldsByTypeHelper(queryText: string, resourceRetriever?: ESQ
|
||||||
getFieldsByType: async (
|
getFieldsByType: async (
|
||||||
expectedType: Readonly<string> | Readonly<string[]> = 'any',
|
expectedType: Readonly<string> | Readonly<string[]> = 'any',
|
||||||
ignored: string[] = []
|
ignored: string[] = []
|
||||||
): Promise<ESQLRealField[]> => {
|
): Promise<ESQLFieldWithMetadata[]> => {
|
||||||
const types = Array.isArray(expectedType) ? expectedType : [expectedType];
|
const types = Array.isArray(expectedType) ? expectedType : [expectedType];
|
||||||
await getFields();
|
await getFields();
|
||||||
const queryTextForCacheSearch = toSingleLine(queryText);
|
const queryTextForCacheSearch = toSingleLine(queryText);
|
||||||
|
@ -116,7 +116,7 @@ export function getFieldsByTypeHelper(queryText: string, resourceRetriever?: ESQ
|
||||||
await getFields();
|
await getFields();
|
||||||
const queryTextForCacheSearch = toSingleLine(queryText);
|
const queryTextForCacheSearch = toSingleLine(queryText);
|
||||||
const cachedFields = getValueInsensitive(queryTextForCacheSearch);
|
const cachedFields = getValueInsensitive(queryTextForCacheSearch);
|
||||||
const cacheCopy = new Map<string, ESQLRealField>();
|
const cacheCopy = new Map<string, ESQLFieldWithMetadata>();
|
||||||
cachedFields?.forEach((field) => cacheCopy.set(field.name, field));
|
cachedFields?.forEach((field) => cacheCopy.set(field.name, field));
|
||||||
return cacheCopy;
|
return cacheCopy;
|
||||||
},
|
},
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
* License v3.0 only", or the "Server Side Public License, v 1".
|
* License v3.0 only", or the "Server Side Public License, v 1".
|
||||||
*/
|
*/
|
||||||
import type { ESQLControlVariable } from '@kbn/esql-types';
|
import type { ESQLControlVariable } from '@kbn/esql-types';
|
||||||
import type { ESQLRealField, JoinIndexAutocompleteItem } from '../validation/types';
|
import type { ESQLFieldWithMetadata, JoinIndexAutocompleteItem } from '../validation/types';
|
||||||
|
|
||||||
/** @internal **/
|
/** @internal **/
|
||||||
type CallbackFn<Options = {}, Result = string> = (ctx?: Options) => Result[] | Promise<Result[]>;
|
type CallbackFn<Options = {}, Result = string> = (ctx?: Options) => Result[] | Promise<Result[]>;
|
||||||
|
@ -39,7 +39,7 @@ export interface ESQLSourceResult {
|
||||||
|
|
||||||
export interface ESQLCallbacks {
|
export interface ESQLCallbacks {
|
||||||
getSources?: CallbackFn<{}, ESQLSourceResult>;
|
getSources?: CallbackFn<{}, ESQLSourceResult>;
|
||||||
getColumnsFor?: CallbackFn<{ query: string }, ESQLRealField>;
|
getColumnsFor?: CallbackFn<{ query: string }, ESQLFieldWithMetadata>;
|
||||||
getPolicies?: CallbackFn<
|
getPolicies?: CallbackFn<
|
||||||
{},
|
{},
|
||||||
{ name: string; sourceIndices: string[]; matchField: string; enrichFields: string[] }
|
{ name: string; sourceIndices: string[]; matchField: string; enrichFields: string[] }
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
|
|
||||||
import type { ESQLAst, ESQLAstItem, ESQLCommand, ESQLFunction } from '@kbn/esql-ast';
|
import type { ESQLAst, ESQLAstItem, ESQLCommand, ESQLFunction } from '@kbn/esql-ast';
|
||||||
import { Visitor } from '@kbn/esql-ast/src/visitor';
|
import { Visitor } from '@kbn/esql-ast/src/visitor';
|
||||||
import type { ESQLUserDefinedColumn, ESQLRealField } from '../validation/types';
|
import type { ESQLUserDefinedColumn, ESQLFieldWithMetadata } from '../validation/types';
|
||||||
import { EDITOR_MARKER } from './constants';
|
import { EDITOR_MARKER } from './constants';
|
||||||
import { isColumnItem, isFunctionItem, getExpressionType } from './helpers';
|
import { isColumnItem, isFunctionItem, getExpressionType } from './helpers';
|
||||||
|
|
||||||
|
@ -27,7 +27,7 @@ function addToUserDefinedColumnOccurrences(
|
||||||
function addToUserDefinedColumns(
|
function addToUserDefinedColumns(
|
||||||
oldArg: ESQLAstItem,
|
oldArg: ESQLAstItem,
|
||||||
newArg: ESQLAstItem,
|
newArg: ESQLAstItem,
|
||||||
fields: Map<string, ESQLRealField>,
|
fields: Map<string, ESQLFieldWithMetadata>,
|
||||||
userDefinedColumns: Map<string, ESQLUserDefinedColumn[]>
|
userDefinedColumns: Map<string, ESQLUserDefinedColumn[]>
|
||||||
) {
|
) {
|
||||||
if (isColumnItem(oldArg) && isColumnItem(newArg)) {
|
if (isColumnItem(oldArg) && isColumnItem(newArg)) {
|
||||||
|
@ -50,7 +50,7 @@ function addToUserDefinedColumns(
|
||||||
export function excludeUserDefinedColumnsFromCurrentCommand(
|
export function excludeUserDefinedColumnsFromCurrentCommand(
|
||||||
commands: ESQLCommand[],
|
commands: ESQLCommand[],
|
||||||
currentCommand: ESQLCommand,
|
currentCommand: ESQLCommand,
|
||||||
fieldsMap: Map<string, ESQLRealField>,
|
fieldsMap: Map<string, ESQLFieldWithMetadata>,
|
||||||
queryString: string
|
queryString: string
|
||||||
) {
|
) {
|
||||||
const anyUserDefinedColumns = collectUserDefinedColumns(commands, fieldsMap, queryString);
|
const anyUserDefinedColumns = collectUserDefinedColumns(commands, fieldsMap, queryString);
|
||||||
|
@ -71,7 +71,7 @@ export function excludeUserDefinedColumnsFromCurrentCommand(
|
||||||
function addUserDefinedColumnFromAssignment(
|
function addUserDefinedColumnFromAssignment(
|
||||||
assignOperation: ESQLFunction,
|
assignOperation: ESQLFunction,
|
||||||
userDefinedColumns: Map<string, ESQLUserDefinedColumn[]>,
|
userDefinedColumns: Map<string, ESQLUserDefinedColumn[]>,
|
||||||
fields: Map<string, ESQLRealField>
|
fields: Map<string, ESQLFieldWithMetadata>
|
||||||
) {
|
) {
|
||||||
if (isColumnItem(assignOperation.args[0])) {
|
if (isColumnItem(assignOperation.args[0])) {
|
||||||
const rightHandSideArgType = getExpressionType(
|
const rightHandSideArgType = getExpressionType(
|
||||||
|
@ -91,7 +91,7 @@ function addUserDefinedColumnFromExpression(
|
||||||
expressionOperation: ESQLFunction,
|
expressionOperation: ESQLFunction,
|
||||||
queryString: string,
|
queryString: string,
|
||||||
userDefinedColumns: Map<string, ESQLUserDefinedColumn[]>,
|
userDefinedColumns: Map<string, ESQLUserDefinedColumn[]>,
|
||||||
fields: Map<string, ESQLRealField>
|
fields: Map<string, ESQLFieldWithMetadata>
|
||||||
) {
|
) {
|
||||||
if (!expressionOperation.text.includes(EDITOR_MARKER)) {
|
if (!expressionOperation.text.includes(EDITOR_MARKER)) {
|
||||||
const expressionText = queryString.substring(
|
const expressionText = queryString.substring(
|
||||||
|
@ -109,7 +109,7 @@ function addUserDefinedColumnFromExpression(
|
||||||
|
|
||||||
export function collectUserDefinedColumns(
|
export function collectUserDefinedColumns(
|
||||||
ast: ESQLAst,
|
ast: ESQLAst,
|
||||||
fields: Map<string, ESQLRealField>,
|
fields: Map<string, ESQLFieldWithMetadata>,
|
||||||
queryString: string
|
queryString: string
|
||||||
): Map<string, ESQLUserDefinedColumn[]> {
|
): Map<string, ESQLUserDefinedColumn[]> {
|
||||||
const userDefinedColumns = new Map<string, ESQLUserDefinedColumn[]>();
|
const userDefinedColumns = new Map<string, ESQLUserDefinedColumn[]>();
|
||||||
|
|
|
@ -20,13 +20,13 @@ import {
|
||||||
buildQueryForFieldsFromSource,
|
buildQueryForFieldsFromSource,
|
||||||
buildQueryForFieldsInPolicies,
|
buildQueryForFieldsInPolicies,
|
||||||
} from './helpers';
|
} from './helpers';
|
||||||
import type { ESQLRealField, ESQLPolicy } from './types';
|
import type { ESQLFieldWithMetadata, ESQLPolicy } from './types';
|
||||||
|
|
||||||
export async function retrieveFields(
|
export async function retrieveFields(
|
||||||
queryString: string,
|
queryString: string,
|
||||||
commands: ESQLCommand[],
|
commands: ESQLCommand[],
|
||||||
callbacks?: ESQLCallbacks
|
callbacks?: ESQLCallbacks
|
||||||
): Promise<Map<string, ESQLRealField>> {
|
): Promise<Map<string, ESQLFieldWithMetadata>> {
|
||||||
if (!callbacks || commands.length < 1) {
|
if (!callbacks || commands.length < 1) {
|
||||||
return new Map();
|
return new Map();
|
||||||
}
|
}
|
||||||
|
@ -78,7 +78,7 @@ export async function retrievePoliciesFields(
|
||||||
commands: ESQLCommand[],
|
commands: ESQLCommand[],
|
||||||
policies: Map<string, ESQLPolicy>,
|
policies: Map<string, ESQLPolicy>,
|
||||||
callbacks?: ESQLCallbacks
|
callbacks?: ESQLCallbacks
|
||||||
): Promise<Map<string, ESQLRealField>> {
|
): Promise<Map<string, ESQLFieldWithMetadata>> {
|
||||||
if (!callbacks) {
|
if (!callbacks) {
|
||||||
return new Map();
|
return new Map();
|
||||||
}
|
}
|
||||||
|
@ -103,7 +103,7 @@ export async function retrieveFieldsFromStringSources(
|
||||||
queryString: string,
|
queryString: string,
|
||||||
commands: ESQLCommand[],
|
commands: ESQLCommand[],
|
||||||
callbacks?: ESQLCallbacks
|
callbacks?: ESQLCallbacks
|
||||||
): Promise<Map<string, ESQLRealField>> {
|
): Promise<Map<string, ESQLFieldWithMetadata>> {
|
||||||
if (!callbacks) {
|
if (!callbacks) {
|
||||||
return new Map();
|
return new Map();
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,7 +20,7 @@ export interface ESQLUserDefinedColumn {
|
||||||
location: ESQLLocation;
|
location: ESQLLocation;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ESQLRealField {
|
export interface ESQLFieldWithMetadata {
|
||||||
name: string;
|
name: string;
|
||||||
type: FieldType;
|
type: FieldType;
|
||||||
isEcs?: boolean;
|
isEcs?: boolean;
|
||||||
|
@ -40,7 +40,7 @@ export interface ESQLPolicy {
|
||||||
export interface ReferenceMaps {
|
export interface ReferenceMaps {
|
||||||
sources: Set<string>;
|
sources: Set<string>;
|
||||||
userDefinedColumns: Map<string, ESQLUserDefinedColumn[]>;
|
userDefinedColumns: Map<string, ESQLUserDefinedColumn[]>;
|
||||||
fields: Map<string, ESQLRealField>;
|
fields: Map<string, ESQLFieldWithMetadata>;
|
||||||
policies: Map<string, ESQLPolicy>;
|
policies: Map<string, ESQLPolicy>;
|
||||||
query: string;
|
query: string;
|
||||||
joinIndices: JoinIndexAutocompleteItem[];
|
joinIndices: JoinIndexAutocompleteItem[];
|
||||||
|
|
|
@ -46,7 +46,7 @@ import {
|
||||||
retrieveSources,
|
retrieveSources,
|
||||||
} from './resources';
|
} from './resources';
|
||||||
import type {
|
import type {
|
||||||
ESQLRealField,
|
ESQLFieldWithMetadata,
|
||||||
ESQLUserDefinedColumn,
|
ESQLUserDefinedColumn,
|
||||||
ErrorTypes,
|
ErrorTypes,
|
||||||
ReferenceMaps,
|
ReferenceMaps,
|
||||||
|
@ -335,7 +335,7 @@ function validateOption(
|
||||||
}
|
}
|
||||||
|
|
||||||
function validateFieldsShadowing(
|
function validateFieldsShadowing(
|
||||||
fields: Map<string, ESQLRealField>,
|
fields: Map<string, ESQLFieldWithMetadata>,
|
||||||
userDefinedColumns: Map<string, ESQLUserDefinedColumn[]>
|
userDefinedColumns: Map<string, ESQLUserDefinedColumn[]>
|
||||||
) {
|
) {
|
||||||
const messages: ESQLMessage[] = [];
|
const messages: ESQLMessage[] = [];
|
||||||
|
@ -370,7 +370,7 @@ function validateFieldsShadowing(
|
||||||
return messages;
|
return messages;
|
||||||
}
|
}
|
||||||
|
|
||||||
function validateUnsupportedTypeFields(fields: Map<string, ESQLRealField>, ast: ESQLAst) {
|
function validateUnsupportedTypeFields(fields: Map<string, ESQLFieldWithMetadata>, ast: ESQLAst) {
|
||||||
const usedColumnsInQuery: string[] = [];
|
const usedColumnsInQuery: string[] = [];
|
||||||
|
|
||||||
walk(ast, {
|
walk(ast, {
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {
|
import {
|
||||||
ESQLRealField,
|
ESQLFieldWithMetadata,
|
||||||
getFunctionDefinition,
|
getFunctionDefinition,
|
||||||
getFunctionSignatures,
|
getFunctionSignatures,
|
||||||
} from '@kbn/esql-validation-autocomplete';
|
} from '@kbn/esql-validation-autocomplete';
|
||||||
|
@ -20,7 +20,7 @@ import { getHoverItem } from './hover';
|
||||||
|
|
||||||
const types: FieldType[] = ['keyword', 'double', 'date', 'boolean', 'ip'];
|
const types: FieldType[] = ['keyword', 'double', 'date', 'boolean', 'ip'];
|
||||||
|
|
||||||
const fields: Array<ESQLRealField & { suggestedAs?: string }> = [
|
const fields: Array<ESQLFieldWithMetadata & { suggestedAs?: string }> = [
|
||||||
...types.map((type) => ({
|
...types.map((type) => ({
|
||||||
name: `${type}Field`,
|
name: `${type}Field`,
|
||||||
type,
|
type,
|
||||||
|
@ -61,7 +61,7 @@ const policies = [
|
||||||
];
|
];
|
||||||
|
|
||||||
function createCustomCallbackMocks(
|
function createCustomCallbackMocks(
|
||||||
customFields: ESQLRealField[] | undefined,
|
customFields: ESQLFieldWithMetadata[] | undefined,
|
||||||
customSources: Array<{ name: string; hidden: boolean }> | undefined,
|
customSources: Array<{ name: string; hidden: boolean }> | undefined,
|
||||||
customPolicies:
|
customPolicies:
|
||||||
| Array<{
|
| Array<{
|
||||||
|
|
|
@ -15,7 +15,7 @@ import {
|
||||||
isESQLNamedParamLiteral,
|
isESQLNamedParamLiteral,
|
||||||
} from '@kbn/esql-ast/src/types';
|
} from '@kbn/esql-ast/src/types';
|
||||||
import {
|
import {
|
||||||
ESQLRealField,
|
ESQLFieldWithMetadata,
|
||||||
collectUserDefinedColumns,
|
collectUserDefinedColumns,
|
||||||
getFunctionDefinition,
|
getFunctionDefinition,
|
||||||
getFunctionSignatures,
|
getFunctionSignatures,
|
||||||
|
@ -179,7 +179,7 @@ async function getHintForFunctionArg(
|
||||||
if (!fnDefinition) {
|
if (!fnDefinition) {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
const fieldsMap: Map<string, ESQLRealField> = await getFieldsMap();
|
const fieldsMap: Map<string, ESQLFieldWithMetadata> = await getFieldsMap();
|
||||||
const anyUserDefinedColumns = collectUserDefinedColumns(root.commands, fieldsMap, query);
|
const anyUserDefinedColumns = collectUserDefinedColumns(root.commands, fieldsMap, query);
|
||||||
|
|
||||||
const references = {
|
const references = {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue