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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions examples/esql_validation_example/public/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ import {

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 { CodeSnippet } from './code_snippet';

Expand Down Expand Up @@ -56,7 +60,7 @@ export const App = (props: { core: CoreStart; plugins: StartDependencies }) => {
[
{ name: 'doubleField', type: 'double' },
{ name: 'keywordField', type: 'keyword' },
] as ESQLRealField[]
] as ESQLFieldWithMetadata[]
: undefined,
getPolicies: callbacksEnabled.policies
? async () => [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import { fixESQLQueryWithVariables } from '@kbn/esql-utils';
import { createPortal } from 'react-dom';
import { css } from '@emotion/react';
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 { EditorFooter } from './editor_footer';
import { fetchFieldsFromESQL } from './fetch_fields_from_esql';
Expand Down Expand Up @@ -472,7 +472,7 @@ export const ESQLEditor = memo(function ESQLEditor({
undefined,
variablesService?.esqlVariables
).result;
const columns: ESQLRealField[] =
const columns: ESQLFieldWithMetadata[] =
table?.columns.map((c) => {
return {
name: c.name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export { suggest } from './src/autocomplete/autocomplete';
export type {
ValidationErrors,
ESQLUserDefinedColumn,
ESQLRealField,
ESQLFieldWithMetadata,
ESQLPolicy,
ErrorTypes as ESQLValidationErrorTypes,
} from './src/validation/types';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,24 @@
*/

import { camelCase } from 'lodash';
import { ESQLRealField, JoinIndexAutocompleteItem } from '../validation/types';
import { ESQLFieldWithMetadata, JoinIndexAutocompleteItem } from '../validation/types';
import { fieldTypes } from '../definitions/types';
import { ESQLCallbacks } from '../shared/types';

export const fields: ESQLRealField[] = [
export const fields: ESQLFieldWithMetadata[] = [
...fieldTypes.map((type) => ({ name: `${camelCase(type)}Field`, type })),
{ name: 'any#Char$Field', type: 'double' },
{ name: 'kubernetes.something.something', type: 'double' },
{ name: '@timestamp', type: 'date' },
];

export const enrichFields: ESQLRealField[] = [
export const enrichFields: ESQLFieldWithMetadata[] = [
{ name: 'otherField', type: 'text' },
{ name: 'yetAnotherField', type: 'double' },
];

// eslint-disable-next-line @typescript-eslint/naming-convention
export const unsupported_field: ESQLRealField[] = [
export const unsupported_field: ESQLFieldWithMetadata[] = [
{ name: 'unsupported_field', type: 'unsupported' },
];

Expand Down Expand Up @@ -81,7 +81,7 @@ export function getCallbackMocks(): ESQLCallbacks {
return unsupported_field;
}
if (/join_index/.test(query)) {
const field: ESQLRealField = {
const field: ESQLFieldWithMetadata = {
name: 'keywordField',
type: 'unsupported',
hasConflict: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import * as autocomplete from '../autocomplete';
import type { ESQLCallbacks } from '../../shared/types';
import type { EditorContext, SuggestionRawDefinition } from '../types';
import { TIME_SYSTEM_PARAMS, TRIGGER_SUGGESTION_COMMAND, getSafeInsertText } from '../factories';
import { ESQLRealField } from '../../validation/types';
import { ESQLFieldWithMetadata } from '../../validation/types';
import {
FieldType,
fieldTypes,
Expand Down Expand Up @@ -52,7 +52,7 @@ export const TIME_PICKER_SUGGESTION: PartialSuggestionWithText = {

export const triggerCharacters = [',', '(', '=', ' '];

export type TestField = ESQLRealField & { suggestedAs?: string };
export type TestField = ESQLFieldWithMetadata & { suggestedAs?: string };

export const fields: TestField[] = [
...fieldTypes.map((type) => ({
Expand Down Expand Up @@ -278,7 +278,7 @@ export function createCustomCallbackMocks(
* `FROM index | EVAL foo = 1 | LIMIT 0` will be used to fetch columns. The response
* will include "foo" as a column.
*/
customColumnsSinceLastCommand?: ESQLRealField[],
customColumnsSinceLastCommand?: ESQLFieldWithMetadata[],
customSources?: Array<{ name: string; hidden: boolean }>,
customPolicies?: Array<{
name: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ import {
collectUserDefinedColumns,
excludeUserDefinedColumnsFromCurrentCommand,
} from '../shared/user_defined_columns';
import type { ESQLRealField, ESQLUserDefinedColumn } from '../validation/types';
import type { ESQLFieldWithMetadata, ESQLUserDefinedColumn } from '../validation/types';
import {
allStarConstant,
commaCompleteItem,
Expand Down Expand Up @@ -84,7 +84,7 @@ import {
import { comparisonFunctions } from '../definitions/all_operators';
import { getRecommendedQueriesSuggestions } from './recommended_queries/suggestions';

type GetFieldsMapFn = () => Promise<Map<string, ESQLRealField>>;
type GetFieldsMapFn = () => Promise<Map<string, ESQLFieldWithMetadata>>;
type GetPoliciesFn = () => Promise<SuggestionRawDefinition[]>;

export async function suggest(
Expand Down Expand Up @@ -279,7 +279,7 @@ async function getSuggestionsWithinCommandExpression(
const commandDef = getCommandDefinition(astContext.command.name);

// 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 references = { fields: fieldsMap, userDefinedColumns: anyUserDefinedColumns };
Expand Down Expand Up @@ -366,7 +366,7 @@ async function getFunctionArgsSuggestions(
if (!fnDefinition) {
return [];
}
const fieldsMap: Map<string, ESQLRealField> = await getFieldsMap();
const fieldsMap: Map<string, ESQLFieldWithMetadata> = await getFieldsMap();
const anyUserDefinedColumns = collectUserDefinedColumns(commands, fieldsMap, innerText);

const references = {
Expand Down Expand Up @@ -604,7 +604,7 @@ async function getListArgsSuggestions(
// 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
if (node && isFunctionItem(node)) {
const fieldsMap: Map<string, ESQLRealField> = await getFieldsMaps();
const fieldsMap: Map<string, ESQLFieldWithMetadata> = await getFieldsMaps();
const anyUserDefinedColumns = collectUserDefinedColumns(commands, fieldsMap, innerText);
// extract the current node from the userDefinedColumns inferred
anyUserDefinedColumns.forEach((values, key) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@
* License v3.0 only", or the "Server Side Public License, v 1".
*/
import { synth } from '@kbn/esql-ast';
import type { ESQLRealField } from '../../../validation/types';
import type { ESQLFieldWithMetadata } from '../../../validation/types';
import { fieldsSuggestionsAfter } from './fields_suggestions_after';

describe('CHANGE_POINT', () => {
it('adds "type" and "pvalue" fields, when AS option not specified', () => {
const previousCommandFields = [
{ name: 'field1', type: 'keyword' },
{ name: 'count', type: 'double' },
] as ESQLRealField[];
] as ESQLFieldWithMetadata[];

const userDefinedColumns = [] as ESQLRealField[];
const userDefinedColumns = [] as ESQLFieldWithMetadata[];

const result = fieldsSuggestionsAfter(
synth.cmd`CHANGE_POINT count ON field1`,
Expand All @@ -37,9 +37,9 @@ describe('CHANGE_POINT', () => {
const previousCommandFields = [
{ name: 'field1', type: 'keyword' },
{ name: 'count', type: 'double' },
] as ESQLRealField[];
] as ESQLFieldWithMetadata[];

const userDefinedColumns = [] as ESQLRealField[];
const userDefinedColumns = [] as ESQLFieldWithMetadata[];

const result = fieldsSuggestionsAfter(
synth.cmd`CHANGE_POINT count ON field1 AS changePointType, pValue`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
* License v3.0 only", or the "Server Side Public License, v 1".
*/
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 = (
command: ESQLAstCommand,
previousCommandFields: ESQLRealField[],
userDefinedColumns: ESQLRealField[]
previousCommandFields: ESQLFieldWithMetadata[],
userDefinedColumns: ESQLFieldWithMetadata[]
) => {
const { target } = command as ESQLAstChangePointCommand;
previousCommandFields.push(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* License v3.0 only", or the "Server Side Public License, v 1".
*/
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';

describe('DISSECT', () => {
Expand Down Expand Up @@ -73,9 +73,9 @@ describe('DISSECT', () => {
const previousCommandFields = [
{ name: 'field1', type: 'keyword' },
{ name: 'field2', type: 'double' },
] as ESQLRealField[];
] as ESQLFieldWithMetadata[];

const userDefinedColumns = [] as ESQLRealField[];
const userDefinedColumns = [] as ESQLFieldWithMetadata[];

const result = fieldsSuggestionsAfter(
synth.cmd`DISSECT agent "%{firstWord}"`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* License v3.0 only", or the "Server Side Public License, v 1".
*/
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 {
if (inputString.startsWith('"') && inputString.endsWith('"') && inputString.length >= 2) {
Expand All @@ -33,8 +33,8 @@ export function extractDissectColumnNames(pattern: string): string[] {

export const fieldsSuggestionsAfter = (
command: ESQLAstCommand,
previousCommandFields: ESQLRealField[],
userDefinedColumns: ESQLRealField[]
previousCommandFields: ESQLFieldWithMetadata[],
userDefinedColumns: ESQLFieldWithMetadata[]
) => {
const columns: string[] = [];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@
* License v3.0 only", or the "Server Side Public License, v 1".
*/
import { synth } from '@kbn/esql-ast';
import type { ESQLRealField } from '../../../validation/types';
import type { ESQLFieldWithMetadata } from '../../../validation/types';
import { fieldsSuggestionsAfter } from './fields_suggestions_after';

describe('DROP', () => {
it('removes the columns defined in the command', () => {
const previousCommandFields = [
{ name: 'field1', type: 'keyword' },
{ name: 'field2', type: 'double' },
] as ESQLRealField[];
] as ESQLFieldWithMetadata[];

const userDefinedColumns = [] as ESQLRealField[];
const userDefinedColumns = [] as ESQLFieldWithMetadata[];

const result = fieldsSuggestionsAfter(
synth.cmd`DROP field1`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
* License v3.0 only", or the "Server Side Public License, v 1".
*/
import { type ESQLAstCommand, walk } from '@kbn/esql-ast';
import type { ESQLRealField } from '../../../validation/types';
import type { ESQLFieldWithMetadata } from '../../../validation/types';

export const fieldsSuggestionsAfter = (
command: ESQLAstCommand,
previousCommandFields: ESQLRealField[],
userDefinedColumns: ESQLRealField[]
previousCommandFields: ESQLFieldWithMetadata[],
userDefinedColumns: ESQLFieldWithMetadata[]
) => {
const columnsToDrop: string[] = [];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@
* License v3.0 only", or the "Server Side Public License, v 1".
*/
import { synth } from '@kbn/esql-ast';
import type { ESQLRealField } from '../../../validation/types';
import type { ESQLFieldWithMetadata } from '../../../validation/types';
import { fieldsSuggestionsAfter } from './fields_suggestions_after';

describe('FORK', () => {
it('adds the _fork in the list of fields', () => {
const previousCommandFields = [
{ name: 'field1', type: 'keyword' },
{ name: 'field2', type: 'double' },
] as ESQLRealField[];
] as ESQLFieldWithMetadata[];

const userDefinedColumns = [] as ESQLRealField[];
const userDefinedColumns = [] as ESQLFieldWithMetadata[];

const result = fieldsSuggestionsAfter(
synth.cmd`FORK (LIMIT 10 ) (LIMIT 1000 ) `,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
* License v3.0 only", or the "Server Side Public License, v 1".
*/
import { type ESQLAstCommand } from '@kbn/esql-ast';
import type { ESQLRealField } from '../../../validation/types';
import type { ESQLFieldWithMetadata } from '../../../validation/types';

export const fieldsSuggestionsAfter = (
command: ESQLAstCommand,
previousCommandFields: ESQLRealField[],
userDefinedColumns: ESQLRealField[]
previousCommandFields: ESQLFieldWithMetadata[],
userDefinedColumns: ESQLFieldWithMetadata[]
) => {
return [
...previousCommandFields,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* License v3.0 only", or the "Server Side Public License, v 1".
*/
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';

describe('GROK', () => {
Expand All @@ -32,9 +32,9 @@ describe('GROK', () => {
const previousCommandFields = [
{ name: 'field1', type: 'keyword' },
{ name: 'field2', type: 'double' },
] as ESQLRealField[];
] as ESQLFieldWithMetadata[];

const userDefinedColumns = [] as ESQLRealField[];
const userDefinedColumns = [] as ESQLFieldWithMetadata[];

const result = fieldsSuggestionsAfter(
synth.cmd`GROK agent "%{WORD:firstWord}"`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* License v3.0 only", or the "Server Side Public License, v 1".
*/
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 {
if (inputString.startsWith('"') && inputString.endsWith('"') && inputString.length >= 2) {
Expand All @@ -30,8 +30,8 @@ export function extractSemanticsFromGrok(pattern: string): string[] {

export const fieldsSuggestionsAfter = (
command: ESQLAstCommand,
previousCommandFields: ESQLRealField[],
userDefinedColumns: ESQLRealField[]
previousCommandFields: ESQLFieldWithMetadata[],
userDefinedColumns: ESQLFieldWithMetadata[]
) => {
const columns: string[] = [];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@
* License v3.0 only", or the "Server Side Public License, v 1".
*/
import { synth } from '@kbn/esql-ast';
import type { ESQLRealField } from '../../../validation/types';
import type { ESQLFieldWithMetadata } from '../../../validation/types';
import { fieldsSuggestionsAfter } from './fields_suggestions_after';

describe('fieldsSuggestionsAfterKeep', () => {
it('should return the correct fields after the command', () => {
const previousCommandFields = [
{ name: 'field1', type: 'keyword' },
{ name: 'field2', type: 'double' },
] as ESQLRealField[];
] as ESQLFieldWithMetadata[];

const userDefinedColumns = [] as ESQLRealField[];
const userDefinedColumns = [] as ESQLFieldWithMetadata[];

const result = fieldsSuggestionsAfter(
synth.cmd`KEEP field1`,
Expand Down
Loading