Skip to content

Commit d78e4a2

Browse files
authored
[ES|QL] Update function scripts for 8.19 (elastic#219779)
## Summary Part of elastic#219221 This updates the function metadata sync scripts to work against the Elasticsearch 8.19 branch. Review not only the code changes in this PR, but also the result of running the CI job: elastic#219854
1 parent d7a6fdc commit d78e4a2

File tree

4 files changed

+65
-60
lines changed

4 files changed

+65
-60
lines changed

.buildkite/pipelines/esql_grammar_sync.yml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
steps:
2-
- command: .buildkite/scripts/steps/esql_grammar_sync.sh
3-
label: Grammar Sync
4-
timeout_in_minutes: 10
5-
agents:
6-
image: family/kibana-ubuntu-2004
7-
imageProject: elastic-images-prod
8-
provider: gcp
9-
machineType: n2-standard-2
10-
preemptible: true
2+
# - command: .buildkite/scripts/steps/esql_grammar_sync.sh
3+
# label: Grammar Sync
4+
# timeout_in_minutes: 10
5+
# agents:
6+
# image: family/kibana-ubuntu-2004
7+
# imageProject: elastic-images-prod
8+
# provider: gcp
9+
# machineType: n2-standard-2
10+
# preemptible: true
1111
- command: .buildkite/scripts/steps/esql_generate_function_metadata.sh
1212
label: Generate Function Metadata
1313
timeout_in_minutes: 15

.buildkite/scripts/steps/esql_generate_function_metadata.sh

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,13 @@ main () {
1616

1717
rm -rf elasticsearch
1818
git clone https://github.com/elastic/elasticsearch --depth 1
19+
cd "$PARENT_DIR/elasticsearch"
20+
21+
echo "FETCHING 8.19 branch"
22+
git fetch origin 8.19
23+
24+
echo "CHECKING OUT 8.19 branch"
25+
git checkout FETCH_HEAD -b 8.19
1926

2027
report_main_step "Bootstrapping Kibana"
2128

@@ -56,18 +63,18 @@ main () {
5663
git config --global user.name "$KIBANA_MACHINE_USERNAME"
5764
git config --global user.email '[email protected]'
5865

59-
PR_TITLE='[ES|QL] Update function metadata'
66+
PR_TITLE='[ES|QL] Update function metadata for 8.19'
6067
PR_BODY='This PR updates the function definitions and inline docs based on the latest metadata from Elasticsearch.'
6168

62-
# Check if a PR already exists
63-
pr_search_result=$(gh pr list --search "$PR_TITLE" --state open --author "$KIBANA_MACHINE_USERNAME" --limit 1 --json title -q ".[].title")
69+
# # Check if a PR already exists
70+
# pr_search_result=$(gh pr list --search "$PR_TITLE" --state open --author "$KIBANA_MACHINE_USERNAME" --limit 1 --json title -q ".[].title")
6471

65-
if [ "$pr_search_result" == "$PR_TITLE" ]; then
66-
echo "PR already exists. Exiting."
67-
exit
68-
fi
72+
# if [ "$pr_search_result" == "$PR_TITLE" ]; then
73+
# echo "PR already exists. Exiting."
74+
# exit
75+
# fi
6976

70-
echo "No existing PR found. Committing changes."
77+
# echo "No existing PR found. Committing changes."
7178

7279
# Make a commit
7380
BRANCH_NAME="esql_generate_function_metadata_$(date +%s)"
@@ -82,7 +89,7 @@ main () {
8289
git push origin "$BRANCH_NAME"
8390

8491
# Create a PR
85-
gh pr create --title "$PR_TITLE" --body "$PR_BODY" --base main --head "${BRANCH_NAME}" --label 'release_note:skip' --label 'Team:ESQL'
92+
gh pr create --title "$PR_TITLE" --body "$PR_BODY" --base 8.19 --head "${BRANCH_NAME}" --label 'release_note:skip' --label 'Team:ESQL' --label 'backport:skip'
8693
}
8794

8895
main

src/platform/packages/private/kbn-language-documentation/scripts/generate_esql_docs.ts

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,26 @@ interface DocsSectionContent {
2222
const pathToElasticsearch = process.argv[2];
2323
const { scalarFunctions, aggregationFunctions, groupingFunctions } =
2424
loadFunctionDocs(pathToElasticsearch);
25+
26+
const allFunctionNames = Array.from(scalarFunctions.keys()).concat(
27+
Array.from(aggregationFunctions.keys()),
28+
Array.from(groupingFunctions.keys())
29+
);
30+
2531
writeFunctionDocs(
2632
scalarFunctions,
27-
path.join(__dirname, '../src/sections/generated/scalar_functions.tsx')
33+
path.join(__dirname, '../src/sections/generated/scalar_functions.tsx'),
34+
allFunctionNames
2835
);
2936
writeFunctionDocs(
3037
aggregationFunctions,
31-
path.join(__dirname, '../src/sections/generated/aggregation_functions.tsx')
38+
path.join(__dirname, '../src/sections/generated/aggregation_functions.tsx'),
39+
allFunctionNames
3240
);
3341
writeFunctionDocs(
3442
groupingFunctions,
35-
path.join(__dirname, '../src/sections/generated/grouping_functions.tsx')
43+
path.join(__dirname, '../src/sections/generated/grouping_functions.tsx'),
44+
allFunctionNames
3645
);
3746
})();
3847

@@ -74,20 +83,18 @@ function loadFunctionDocs(pathToElasticsearch: string) {
7483
const functionName = path.basename(file, '.md');
7584

7685
// Add the function name and content to the map
77-
if (functionDefinition.type === 'scalar') {
78-
scalarFunctions.set(functionName, {
86+
if (['bucket', 'categorize'].includes(functionDefinition.name)) {
87+
groupingFunctions.set(functionName, {
7988
description: content,
8089
preview: functionDefinition.preview,
8190
});
82-
}
83-
if (functionDefinition.type === 'agg') {
91+
} else if (functionDefinition.type === 'agg') {
8492
aggregationFunctions.set(functionName, {
8593
description: content,
8694
preview: functionDefinition.preview,
8795
});
88-
}
89-
if (functionDefinition.type === 'grouping') {
90-
groupingFunctions.set(functionName, {
96+
} else if (functionDefinition.type === 'eval') {
97+
scalarFunctions.set(functionName, {
9198
description: content,
9299
preview: functionDefinition.preview,
93100
});
@@ -98,13 +105,25 @@ function loadFunctionDocs(pathToElasticsearch: string) {
98105
return { scalarFunctions, aggregationFunctions, groupingFunctions };
99106
}
100107

101-
function writeFunctionDocs(functionDocs: Map<string, DocsSectionContent>, pathToDocsFile: string) {
108+
function replaceCodeBlocksForESQLFormatting(text: string) {
109+
return text.replace(/```(\n[\s\S]*?\n)```/g, '```esql$1```');
110+
}
111+
112+
function writeFunctionDocs(
113+
functionDocs: Map<string, DocsSectionContent>,
114+
pathToDocsFile: string,
115+
allFunctionNames: string[]
116+
) {
102117
const codeStrings = Array.from(functionDocs.entries()).map(([name, doc]) => {
103118
const docWithoutLinks = removeAsciiDocInternalCrossReferences(
104119
doc.description,
105-
Array.from(functionDocs.keys())
120+
allFunctionNames
121+
);
122+
const defaultMessage = replaceCodeBlocksForESQLFormatting(docWithoutLinks).replaceAll(
123+
'`',
124+
'\\`'
106125
);
107-
const defaultMessage = docWithoutLinks.replaceAll('`', '\\`');
126+
108127
return `
109128
const foo =
110129
// Do not edit manually... automatically generated by scripts/generate_esql_docs.ts

src/platform/packages/shared/kbn-esql-validation-autocomplete/scripts/generate_function_definitions.ts

Lines changed: 8 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ const convertDateTime = (s: string) => (s === 'datetime' ? 'date' : s);
311311
*/
312312
function getFunctionDefinition(ESFunctionDefinition: Record<string, any>): FunctionDefinition {
313313
let locationsAvailable =
314-
ESFunctionDefinition.type === FunctionDefinitionTypes.SCALAR
314+
ESFunctionDefinition.type === 'eval'
315315
? defaultScalarFunctionLocations
316316
: defaultAggFunctionLocations;
317317

@@ -320,7 +320,11 @@ function getFunctionDefinition(ESFunctionDefinition: Record<string, any>): Funct
320320
locationsAvailable = [Location.WHERE];
321321
}
322322
const ret = {
323-
type: ESFunctionDefinition.type,
323+
type: ['bucket', 'categorize'].includes(ESFunctionDefinition.name)
324+
? 'grouping'
325+
: ESFunctionDefinition.type === 'eval'
326+
? 'scalar'
327+
: ESFunctionDefinition.type,
324328
name: ESFunctionDefinition.name,
325329
operator: ESFunctionDefinition.operator,
326330
locationsAvailable,
@@ -688,13 +692,13 @@ const enrichGrouping = (
688692
];
689693
return {
690694
...op,
691-
locationsAvailable: [...op.locationsAvailable, Location.STATS_BY],
695+
locationsAvailable: [Location.STATS, Location.STATS_BY],
692696
signatures,
693697
};
694698
}
695699
return {
696700
...op,
697-
locationsAvailable: [...op.locationsAvailable, Location.STATS_BY],
701+
locationsAvailable: [Location.STATS, Location.STATS_BY],
698702
};
699703
});
700704
};
@@ -951,7 +955,6 @@ ${
951955

952956
const functionDefinition = getFunctionDefinition(ESDefinition);
953957
const isLikeOperator = functionDefinition.name.toLowerCase().includes('like');
954-
const arePredicates = functionDefinition.name.toLowerCase().includes('predicates');
955958

956959
if (functionDefinition.name.toLowerCase() === 'match') {
957960
scalarFunctionDefinitions.push({
@@ -961,30 +964,6 @@ ${
961964
continue;
962965
}
963966

964-
if (arePredicates) {
965-
const nullFunctions: FunctionDefinition[] = [
966-
{
967-
name: 'is null',
968-
description: 'Predicate for NULL comparison: returns true if the value is NULL',
969-
operator: 'is null',
970-
},
971-
{
972-
name: 'is not null',
973-
description: 'Predicate for NULL comparison: returns true if the value is not NULL',
974-
operator: 'is not null',
975-
},
976-
].map<FunctionDefinition>(({ name, description, operator }) => {
977-
return {
978-
...functionDefinition,
979-
name,
980-
operator,
981-
description,
982-
};
983-
});
984-
operatorDefinitions.push(...nullFunctions);
985-
continue;
986-
}
987-
988967
if (functionDefinition.type === FunctionDefinitionTypes.OPERATOR || isLikeOperator) {
989968
operatorDefinitions.push(functionDefinition);
990969
}

0 commit comments

Comments
 (0)