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

[DAPHNE-#494] SQLParser: Group by without aggregation clause not working #543

Merged
merged 7 commits into from
Jun 17, 2023

Conversation

tomschw
Copy link
Contributor

@tomschw tomschw commented Jun 12, 2023

Fixed problem:

  • Grouping in SQL statements is only possible when having an aggregation in the outputs

Changes:

  • Add tests to reproduce the problem.
  • Fix the shape inference, which had problems, when no aggregation columns where used.
  • Create a workaround in the Kernel lowering for the group op, when no aggregations are used.

Other possible solutions instead of the current workaround:

  • Split up the GroupOp into a GroupOp with and without aggregations, handled by the SQLParser.
  • Create a NoneOp as an aggregation function which occurs, when no aggregations where used (would need additional work in the shape inference and in the Group-Kernel).

As the Kernel lowering should be reworked in the future anyway, the current workaround should work fine for the moment.

Fixes #494.

@pdamme pdamme self-requested a review June 17, 2023 13:06
- The shape inference for GroupOp did indeed have a bug, but this was not the right fix (using inferNumColsFromArgs() was generally wrong).
- Simplified the new test case for GROUP BY without aggregation.
Copy link
Collaborator

@pdamme pdamme left a comment

Choose a reason for hiding this comment

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

Thanks @tomschw, this contribution fixes the bug. I polished it just a bit.

There was indeed also a bug in the shape inference of GroupOp, but the problem there was not to check if the list of aggregation columns is empty. The actual problem was the use of inferNumColsFromArgs(), a shape inference helper function not suitable for this case. Instead, one should just take the size() of the list of key columns and aggregation columns. I adjusted it accordingly.

@pdamme pdamme merged commit c2433df into daphne-eu:main Jun 17, 2023
pdamme added a commit that referenced this pull request Apr 8, 2024
…teToCallKernelOpPass.

- Some DaphneIR operations have variadic operands, i.e., operands which can occur an arbitrary number of times (including zero).
- When lowering DaphneIR operations to the DaphneIR CallKernelOp, this poses a problem as the C++ kernels cannot be pre-compiled for any number of operands.
- Thus, the kernels expect an array of operands (pointer plus size); in DaphneIR this is represented by a value of type daphne::VariadicPack, which stores all occurrences of a variadic operand.
- So RewriteToCallKernelOpPass needs to convert variadic operands of DaphneIR operations to DaphneIR's VariadicPack.
- In the past there have been problems in case of variadic operands with zero occurrences.
- As GroupOp was the only problematic op so far, a workaround has been provided in PRs #564 and #543.
- This commit improves the treatment of variadic operands with zero occurrences in RewriteToCallKernelOpPass:
  - First, the code is more general now and clearly expresses that this problem is not about GroupOp, but about instances of ops with variadic operands with zero occurrences, in general.
  - Second, the code for treating individual such ops is significantly simpler and more extensible now, since one only has to provide a default MLIR type for the variadic operand.
- Furthermore, a simplified version of the example DaphneDSL code mentioned in issue #562, that failed before PR #564, was added as a test case now.
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.

SQLParser: Group by without aggregation clause not working
2 participants