Skip to content

feat: Add mutation functions for SETtings#84

Merged
sddonne merged 7 commits intomainfrom
setting-mutate
Apr 13, 2026
Merged

feat: Add mutation functions for SETtings#84
sddonne merged 7 commits intomainfrom
setting-mutate

Conversation

@sddonne
Copy link
Copy Markdown
Contributor

@sddonne sddonne commented Apr 10, 2026

Part of elastic/kibana#250172

Summary

This PR adds mutation helpers to safely add or modify query settings.

Details

The following methods were added:

  • .set
    • .list() — List all SET header commands.
    • .findBySettingName() — Find a SET command by its setting name.
    • .set() — Modify the value of an existing SET setting.
    • .upsert() — Modify a SET setting value, or add a new SET command if it does not exist.

The one needed for this task is .upsert() but as it needs the rest to be built they were also exposed.
This is a similar implementation to LIMIT and FROM commands.

Checklist

  • Unit tests have been added or updated.
  • The proper documentation has been added or updated.
  • If this PR contains breaking changes, you have explained them using the BREAKING CHANGE: change syntax.
  • The PR title has the correct conventional commit label in the title, this is crucial for the correct versioning of this package. Check the following cheat shit.
    Title Label Release
    breaking: true (!) major
    feat minor
    fix patch
    refactor patch
    perf patch
    build patch
    docs patch
    chore patch
    revert patch

(Built with the help of Cursor)

@sddonne sddonne marked this pull request as ready for review April 10, 2026 10:15
@sddonne sddonne requested a review from a team as a code owner April 10, 2026 10:15
Copy link
Copy Markdown
Contributor

@stratoula stratoula left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks nice Seb, added some comments from the code review

* @param value The new string value for the setting.
* @returns The modified SET header command, or undefined if not found.
*/
export const set = (
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

commands.set.set(root, 'unmapped_fields', 'LOAD') reads awkwardly

I know we are trying to keep consistent but honestly this seems very weird. Why dont we rename to update instead?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mm true, renamed.

export const set = (
ast: ESQLAstQueryExpression,
settingName: string,
value: string
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about boolean values? Like SET approximation = TRUE?? Same for the upsert

Copy link
Copy Markdown
Contributor Author

@sddonne sddonne Apr 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call, modified it so the value is taken as an expression query, in this way you can also set maps as values.
3bc75e8
Using Synth to transform it into the correct AST node.
Synth added a circular dependency so just parsing the value now.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok cool but type wise this value being string seems wrong no? As it can also be boolean or number

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can implement this in two ways, as it is now, it expects the value to be written as you want it to appear in the query.
commands.set.update(root, 'unmapped_fields', 'true'); -> SET unmapped_fields = true;
commands.set.update(root, 'unmapped_fields', '"LOAD"'); -> SET unmapped_fields = "LOAD";
commands.set.update(root, 'unmapped_fields', '{"key" : "value"}'); -> SET unmapped_fields = {"key": "value"};

The other would be to expect a ESQLNode, delegating the responsibility to client to build it.

Mm there is also a third way that would be to set the value type as string | number | boolean | object (I think this is what you meant) and we should have some logic to transform them into ESQLNodes, but seems complex for this use case..

I think the current one is like in a middle ground between offering functionality and keeping it simple.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, as long as it works prperly is ok but it is confusing that we are typing all the values as string. At least add a JSDoc comment on the value parameter explaining that it's parsed as an ES|QL expression (so 'true' → boolean, '"LOAD"' → string literal, etc.). That way future callers don't have to guess.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Contributor

@stratoula stratoula left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving with a comment, please at least add a comment on the value:string functions to explain what is going on as it is confusing 🙏

@sddonne sddonne merged commit 0aff9db into main Apr 13, 2026
3 checks passed
@sddonne sddonne deleted the setting-mutate branch April 13, 2026 07:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants