Skip to content

Conversation

wmoustafa
Copy link
Contributor

Currently, UDF state in Trino's StdUdfWrapper is initialized in the specialize() method, and is updated in eval() on certain conditions. State initialization in specialize() is not reliable since specialize() result can be cached across multiple UDF invocations, and hence one invocation can use the initialized state from another, leading to issues like query contamination. This patch moves away from manipulating state through the specialize() method in Trino UDFs, and instead uses a State class to keep track of state (in an object conventionally called instance factory). A key property of the State class is that is constructor is parameterless. To enable State class to be parameterless while having it contain a reference to the enclosing StdUDF (see the patch for why the reference is needed), we resort to code generation to create a custom State class for each StdUDF, along with the expected StdUDF reference. All state manipulation now moves to the eval() function.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant