Skip to content

Conversation

@ivancea
Copy link
Contributor

@ivancea ivancea commented Feb 26, 2025

Fixes #123430

There were 2 problems here:

  • We were filling a static field (used to auto-cast string literals) within a constructor, which is also called in multiple places
  • The field was only filled with non-snapshot functions, so snapshot function auto-casting wasn't possible

Fixed both bugs by making the field non-static instead, and a fix to use the snapshot registry (if available) in the string casting rule.

@ivancea ivancea added >bug Team:Analytics Meta label for analytical engine team (ESQL/Aggs/Geo) auto-backport Automatically create backport pull requests when merged :Analytics/ES|QL AKA ESQL v8.19.0 v9.0.1 v9.1.0 labels Feb 26, 2025
@elasticsearchmachine
Copy link
Collaborator

Hi @ivancea, I've created a changelog YAML for you.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is there a reason for this class to not be "static", and the instance getter to not always return the corresponding registry (snapshot or non-snapshot)?
Could be a fairly simple improvement, avoiding recreating those maps again and again

);
}

protected void buildDataTypesForStringLiteralConversion(FunctionDefinition[]... groupFunctions) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was just moved, as it's now protected, with the "register()" functions

public class Delay extends UnaryScalarFunction {
public static final NamedWriteableRegistry.Entry ENTRY = new NamedWriteableRegistry.Entry(Expression.class, "Delay", Delay::new);

@FunctionInfo(returnType = { "boolean" }, description = "Sleeps for a duration for every row. For debug purposes only.")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is needed within the buildDataTypesForStringLiteralConversion() -> description() chain.
It won't be used for anything, as this function has no documentation, but I'd rather have it here than changing the registry code for this case

@ivancea ivancea marked this pull request as ready for review February 26, 2025 12:40
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/es-analytical-engine (Team:Analytics)

private final Map<String, FunctionDefinition> defs = new LinkedHashMap<>();
private final Map<String, String> aliases = new HashMap<>();
private final Map<Class<? extends Function>, String> names = new HashMap<>();
private final Map<Class<? extends Function>, List<DataType>> dataTypesForStringLiteralConversions = new LinkedHashMap<>();
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

Copy link
Member

@fang-xing-esql fang-xing-esql left a comment

Choose a reason for hiding this comment

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

LGTM, thank you @ivancea ! Just to be extra cautious, perhaps add test-releases label, as a call to snapshotRegistry is added.

@ivancea ivancea added the test-release Trigger CI checks against release build label Feb 26, 2025
@ivancea ivancea merged commit ca5d251 into elastic:main Feb 27, 2025
18 checks passed
@ivancea ivancea deleted the esql-function-registry-literals-concurrency branch February 27, 2025 10:05
@elasticsearchmachine
Copy link
Collaborator

💚 Backport successful

Status Branch Result
8.x
9.0
ivancea added a commit to ivancea/elasticsearch that referenced this pull request Feb 27, 2025
…c#123492) Fixes elastic#123430 There were 2 problems here: - We were filling a static field (used to auto-cast string literals) within a constructor, which is also called in multiple places - The field was only filled with non-snapshot functions, so snapshot function auto-casting wasn't possible Fixed both bugs by making the field non-static instead, and a fix to use the snapshot registry (if available) in the string casting rule.
ivancea added a commit to ivancea/elasticsearch that referenced this pull request Feb 27, 2025
…c#123492) Fixes elastic#123430 There were 2 problems here: - We were filling a static field (used to auto-cast string literals) within a constructor, which is also called in multiple places - The field was only filled with non-snapshot functions, so snapshot function auto-casting wasn't possible Fixed both bugs by making the field non-static instead, and a fix to use the snapshot registry (if available) in the string casting rule.
elasticsearchmachine pushed a commit that referenced this pull request Feb 27, 2025
… (#123584) Fixes #123430 There were 2 problems here: - We were filling a static field (used to auto-cast string literals) within a constructor, which is also called in multiple places - The field was only filled with non-snapshot functions, so snapshot function auto-casting wasn't possible Fixed both bugs by making the field non-static instead, and a fix to use the snapshot registry (if available) in the string casting rule.
elasticsearchmachine pushed a commit that referenced this pull request Feb 27, 2025
… (#123583) Fixes #123430 There were 2 problems here: - We were filling a static field (used to auto-cast string literals) within a constructor, which is also called in multiple places - The field was only filled with non-snapshot functions, so snapshot function auto-casting wasn't possible Fixed both bugs by making the field non-static instead, and a fix to use the snapshot registry (if available) in the string casting rule.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

:Analytics/ES|QL AKA ESQL auto-backport Automatically create backport pull requests when merged >bug Team:Analytics Meta label for analytical engine team (ESQL/Aggs/Geo) test-release Trigger CI checks against release build v8.19.0 v9.0.1 v9.1.0

4 participants