-
Notifications
You must be signed in to change notification settings - Fork 24.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ES|QL: ReplaceMissingFieldWithNull could lead to ClassCastException #110150
Comments
Pinging @elastic/es-analytical-engine (Team:Analytics) |
IMO this is a bug, so I marked this accordingly. This piece of code performs a wild, unchecked cast without any safeguards; this is bound to break again in the future, especially since we plan to add new logical plan nodes (and evolve existing ones). |
It is important to have a test case for this. The original fix addressed the problem at theoretical level and based on assumptions, without a test that demonstrates the problem is actually fixed. @luigidellaquila I know this happened in a setup that's not easy to reproduce (multi-node I assume), but please look into a more concret, non-theoretical, and reproduceable scenario. Update this issue when you have more info about this. |
@astefan the specific problem with MV_EXPAND was easily reproducible at planning time with a unit test. The test is included in the PR, so we are pretty confident that it's fixed. This issue is tracking a more general problem: in the base case, this rule is blindly replacing FieldAttributes with Literals, without considering the actual field type declared in the command (ie. without considering that a With currently supported commands there are no concrete failing scenarios, so the only thing I can do is demonstrate the problem in a unit test with a mock command #110373 |
IMHO the default case of Not optimizing per default forces us to actually think about this (annoying, but not incorrect) and adding new logical plan nodes explicitly to the rule. Alternatively, we could extract the info "I'm a logical plan node whose fieldattributes can be replaced by literals, no problem!" into an interface or abstract function, but that may be overkill, too. |
An easy way to fix it would be to explicitly list all the commands that we know we want to optimize that way, and as you say, just do nothing by default. |
ReplaceMissingFieldWithNull local logical optimization rule replaces expressions with a NULL
Literal
when a field is not mapped on local node.This is dangerous because a
Literal
could not match the type of the expressions that are being replaced (eg. if the command expects aNamedExpression
like in this case), and it can trigger a ClassCastException.With current feature set this optimization is safe, but we could miss the problem when we add new commands.
Notice that this optimization triggers a few other downstream optimizations that can be quite important, see
LocalLogicalPlanOptimizerTests.testMissingField*
The text was updated successfully, but these errors were encountered: