From 45c58a0d48c0571de829b976535d39e2a9eaa602 Mon Sep 17 00:00:00 2001 From: Valerio Bartolini Date: Tue, 16 Dec 2025 16:13:07 +0100 Subject: [PATCH 1/2] lookup join columns wrong order --- .../src/commands/registry/join/utils.ts | 9 ++++++++- .../src/shared/sorting/priority_provider.ts | 2 ++ .../sorting/suggestion_ordering_engine.test.ts | 16 ++++++++++++++++ .../kbn-esql-ast/src/shared/sorting/types.ts | 2 ++ 4 files changed, 28 insertions(+), 1 deletion(-) diff --git a/src/platform/packages/shared/kbn-esql-ast/src/commands/registry/join/utils.ts b/src/platform/packages/shared/kbn-esql-ast/src/commands/registry/join/utils.ts index fae128b4336eb..858ce8a60e012 100644 --- a/src/platform/packages/shared/kbn-esql-ast/src/commands/registry/join/utils.ts +++ b/src/platform/packages/shared/kbn-esql-ast/src/commands/registry/join/utils.ts @@ -24,6 +24,7 @@ import type { import type { ICommand } from '../registry'; import type { GetColumnsByTypeFn, ICommandContext, ISuggestionItem } from '../types'; import type { JoinCommandPosition, JoinStaticPosition } from './types'; +import { SuggestionCategory } from '../../../shared/sorting/types'; const REGEX = /^(?\w+((?\s+((?(JOIN|JOI|JO|J)((?\s+((?\S+((?\s+(?(AS|A))?(?\s+(((?\S+)?(?\s+)?)?))?((?(ON|O))?))?))?))?))?))?))?/i; @@ -191,6 +192,7 @@ export const markCommonFields = ( ...suggestion, sortText: '1-' + (suggestion.sortText || suggestion.label), detail, + category: SuggestionCategory.LOOKUP_COMMON_FIELD, documentation: { value: i18n.translate('kbn-esql-ast.esql.autocomplete.join.sharedField', { defaultMessage: 'Field shared between the source and the lookup index', @@ -272,7 +274,12 @@ export const createEnrichedGetByType = async ( lookupSuggestions ); - return [...markedSourceSuggestions, ...uniqueLookupSuggestions]; + const categorizedLookupSuggestions = uniqueLookupSuggestions.map((suggestion) => ({ + ...suggestion, + category: SuggestionCategory.LOOKUP_INDEX_FIELD, + })); + + return [...markedSourceSuggestions, ...categorizedLookupSuggestions]; }; }; diff --git a/src/platform/packages/shared/kbn-esql-ast/src/shared/sorting/priority_provider.ts b/src/platform/packages/shared/kbn-esql-ast/src/shared/sorting/priority_provider.ts index 269c370109fc5..5dd3fef9fb3e3 100644 --- a/src/platform/packages/shared/kbn-esql-ast/src/shared/sorting/priority_provider.ts +++ b/src/platform/packages/shared/kbn-esql-ast/src/shared/sorting/priority_provider.ts @@ -27,7 +27,9 @@ const CATEGORY_PRIORITIES: Record = { [SuggestionCategory.USER_DEFINED_COLUMN]: 300, [SuggestionCategory.RECOMMENDED_FIELD]: 310, + [SuggestionCategory.LOOKUP_COMMON_FIELD]: 315, [SuggestionCategory.ECS_FIELD]: 330, + [SuggestionCategory.LOOKUP_INDEX_FIELD]: 350, [SuggestionCategory.TIME_FIELD]: 350, [SuggestionCategory.FIELD]: 350, diff --git a/src/platform/packages/shared/kbn-esql-ast/src/shared/sorting/suggestion_ordering_engine.test.ts b/src/platform/packages/shared/kbn-esql-ast/src/shared/sorting/suggestion_ordering_engine.test.ts index 06b815cac3cfb..69053b909c970 100644 --- a/src/platform/packages/shared/kbn-esql-ast/src/shared/sorting/suggestion_ordering_engine.test.ts +++ b/src/platform/packages/shared/kbn-esql-ast/src/shared/sorting/suggestion_ordering_engine.test.ts @@ -84,4 +84,20 @@ describe('SuggestionOrderingEngine', () => { expect(statsResult[1].label).toBe('count'); expect(statsResult[2].label).toBe('abs'); }); + + it('should sort LOOKUP_COMMON_FIELD first, then LOOKUP_INDEX_FIELD and FIELD alphabetically', () => { + const suggestions = [ + createSuggestion('sourceField', SuggestionCategory.FIELD), + createSuggestion('lookupOnlyField', SuggestionCategory.LOOKUP_INDEX_FIELD), + createSuggestion('commonField', SuggestionCategory.LOOKUP_COMMON_FIELD), + createSuggestion('anotherSourceField', SuggestionCategory.FIELD), + ]; + + const result = engine.sort(suggestions, { command: 'JOIN' }); + + expect(result[0].label).toBe('commonField'); + expect(result[1].label).toBe('anotherSourceField'); + expect(result[2].label).toBe('lookupOnlyField'); + expect(result[3].label).toBe('sourceField'); + }); }); diff --git a/src/platform/packages/shared/kbn-esql-ast/src/shared/sorting/types.ts b/src/platform/packages/shared/kbn-esql-ast/src/shared/sorting/types.ts index 80da9cbb83c6d..10bd01f48e921 100644 --- a/src/platform/packages/shared/kbn-esql-ast/src/shared/sorting/types.ts +++ b/src/platform/packages/shared/kbn-esql-ast/src/shared/sorting/types.ts @@ -14,6 +14,8 @@ export enum SuggestionCategory { USER_DEFINED_COLUMN = 'user_defined_column', TIME_PARAM = 'time_param', RECOMMENDED_FIELD = 'recommended_field', + LOOKUP_COMMON_FIELD = 'lookup_common_field', + LOOKUP_INDEX_FIELD = 'lookup_index_field', ECS_FIELD = 'ecs_field', TIME_FIELD = 'time_field', FIELD = 'field', From bc3d86e4fc2b90411450bf19fe7d70a462b3e2f5 Mon Sep 17 00:00:00 2001 From: Valerio Bartolini Date: Wed, 17 Dec 2025 07:44:32 +0100 Subject: [PATCH 2/2] remove lookup index field --- .../kbn-esql-ast/src/commands/registry/join/utils.ts | 7 +------ .../kbn-esql-ast/src/shared/sorting/priority_provider.ts | 1 - .../src/shared/sorting/suggestion_ordering_engine.test.ts | 4 ++-- .../shared/kbn-esql-ast/src/shared/sorting/types.ts | 1 - 4 files changed, 3 insertions(+), 10 deletions(-) diff --git a/src/platform/packages/shared/kbn-esql-ast/src/commands/registry/join/utils.ts b/src/platform/packages/shared/kbn-esql-ast/src/commands/registry/join/utils.ts index 858ce8a60e012..37ead28a2cecf 100644 --- a/src/platform/packages/shared/kbn-esql-ast/src/commands/registry/join/utils.ts +++ b/src/platform/packages/shared/kbn-esql-ast/src/commands/registry/join/utils.ts @@ -274,12 +274,7 @@ export const createEnrichedGetByType = async ( lookupSuggestions ); - const categorizedLookupSuggestions = uniqueLookupSuggestions.map((suggestion) => ({ - ...suggestion, - category: SuggestionCategory.LOOKUP_INDEX_FIELD, - })); - - return [...markedSourceSuggestions, ...categorizedLookupSuggestions]; + return [...markedSourceSuggestions, ...uniqueLookupSuggestions]; }; }; diff --git a/src/platform/packages/shared/kbn-esql-ast/src/shared/sorting/priority_provider.ts b/src/platform/packages/shared/kbn-esql-ast/src/shared/sorting/priority_provider.ts index 5dd3fef9fb3e3..0ab1fa6fa820f 100644 --- a/src/platform/packages/shared/kbn-esql-ast/src/shared/sorting/priority_provider.ts +++ b/src/platform/packages/shared/kbn-esql-ast/src/shared/sorting/priority_provider.ts @@ -29,7 +29,6 @@ const CATEGORY_PRIORITIES: Record = { [SuggestionCategory.RECOMMENDED_FIELD]: 310, [SuggestionCategory.LOOKUP_COMMON_FIELD]: 315, [SuggestionCategory.ECS_FIELD]: 330, - [SuggestionCategory.LOOKUP_INDEX_FIELD]: 350, [SuggestionCategory.TIME_FIELD]: 350, [SuggestionCategory.FIELD]: 350, diff --git a/src/platform/packages/shared/kbn-esql-ast/src/shared/sorting/suggestion_ordering_engine.test.ts b/src/platform/packages/shared/kbn-esql-ast/src/shared/sorting/suggestion_ordering_engine.test.ts index 69053b909c970..47272e27cfd27 100644 --- a/src/platform/packages/shared/kbn-esql-ast/src/shared/sorting/suggestion_ordering_engine.test.ts +++ b/src/platform/packages/shared/kbn-esql-ast/src/shared/sorting/suggestion_ordering_engine.test.ts @@ -85,10 +85,10 @@ describe('SuggestionOrderingEngine', () => { expect(statsResult[2].label).toBe('abs'); }); - it('should sort LOOKUP_COMMON_FIELD first, then LOOKUP_INDEX_FIELD and FIELD alphabetically', () => { + it('should sort LOOKUP_COMMON_FIELD first, then FIELD alphabetically', () => { const suggestions = [ createSuggestion('sourceField', SuggestionCategory.FIELD), - createSuggestion('lookupOnlyField', SuggestionCategory.LOOKUP_INDEX_FIELD), + createSuggestion('lookupOnlyField', SuggestionCategory.FIELD), createSuggestion('commonField', SuggestionCategory.LOOKUP_COMMON_FIELD), createSuggestion('anotherSourceField', SuggestionCategory.FIELD), ]; diff --git a/src/platform/packages/shared/kbn-esql-ast/src/shared/sorting/types.ts b/src/platform/packages/shared/kbn-esql-ast/src/shared/sorting/types.ts index 10bd01f48e921..e2933bfb21d80 100644 --- a/src/platform/packages/shared/kbn-esql-ast/src/shared/sorting/types.ts +++ b/src/platform/packages/shared/kbn-esql-ast/src/shared/sorting/types.ts @@ -15,7 +15,6 @@ export enum SuggestionCategory { TIME_PARAM = 'time_param', RECOMMENDED_FIELD = 'recommended_field', LOOKUP_COMMON_FIELD = 'lookup_common_field', - LOOKUP_INDEX_FIELD = 'lookup_index_field', ECS_FIELD = 'ecs_field', TIME_FIELD = 'time_field', FIELD = 'field',