Skip to content
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

Fix to #29638 - GroupBy generates invalid SQL when using custom database function #30617

Merged
merged 1 commit into from
Apr 14, 2023

Conversation

maumar
Copy link
Contributor

@maumar maumar commented Apr 4, 2023

Problem is that CloningExpressionVisitor doesn't have proper handling for TableValuedFunctionExpression, and therefore goes through default expression visitor pattern (visit all children, check if there are any changes, if there are return new, if not return the same). Since there are no changes, the same instance is returned from cloning, and causes the problem. Fix is to add proper handling of TVFExpression in the CloningExpressionVisitor so that it produces a proper copy.

Fixes #29638

@maumar maumar force-pushed the fix29638 branch 2 times, most recently from 44ae8d4 to c171b90 Compare April 5, 2023 21:21
Copy link
Member

@roji roji left a comment

Choose a reason for hiding this comment

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

LGTM, see proposal below about moving the code into TableValuedFunctionExpression.

More generally, it's a bit worrying that forgetting to add cloning logic to a new expression type could cause subtle bugs in this way... Should we think about having this fail-fast if an expression should implement cloning logic but doesn't? I'm not sure exactly which expression types must be cloned; TVFExpression clearly does, is it about TableExpressionBases?

…ase function

Problem is that CloningExpressionVisitor doesn't have proper handling for TableValuedFunctionExpression, and therefore goes through default expression visitor pattern (visit all children, check if there are any changes, if there are return new, if not return the same). Since there are no changes, the same instance is returned from cloning, and causes the problem.
Fix is to add proper handling of TVFExpression in the CloningExpressionVisitor so that it produces a proper copy. Also added defensive check that throws if we encounter TableExpressionBase that doesn't implement the cloning logic, so that this never happens again.

Fixes #29638
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.

GroupBy generates invalid SQL when using custom database function
2 participants