-
Notifications
You must be signed in to change notification settings - Fork 606
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
Enable COUNT in view queries #6820
Conversation
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
@@ -0,0 +1,9 @@ | |||
CREATE VIEW `/Root/count_episodes` WITH (security_invoker = TRUE) AS |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do these tests check? Do you have a validation for the results of these queries?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, these tests are a non-standard way to test views. They are functional tests, but written in C++. A test case is a single folder in ydb/core/kqp/ut/view/input/cases
(like count_rows
folder, or count_episodes
folder). Each test case is executed in the following order:
- execute
create_view.sql
- execute
etalon_query.sql
- execute
select_from_view.sql
- execute
drop_view.sql
Results of step (2) and step (3) are compared as YSON strings here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This particular test (count_episodes
) is a way to test COUNT
inside a view, but with a bit more complex query than just SELECT COUNT(*) FROM some_table
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's an intresting approach. Thank you for exlanation :)
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
- add ModuleResolver from KQP host - use TKqpTranslationSettingsBuilder like KQP Host does to compile queries
9eca87a
to
fee0d0d
Compare
⚪
🟢
*please be aware that the difference is based on comparing your commit and the last completed build from the post-commit, check comparation |
⚪ ⚪
🟢
*please be aware that the difference is based on comparing your commit and the last completed build from the post-commit, check comparation |
cluster, | ||
query, | ||
SessionCtx->Config().BindingsMode, | ||
GUCSettings |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
GUCSettings are needed here. That is why we pass them in CreateKikimrDataSource.
We cannot, unfortunately, pass the KQP translation settings builder itself from the KQP host to the Kikimr DataSource, because it needs a query
to be built.
@@ -1,7 +1,8 @@ | |||
#pragma once | |||
|
|||
#include <ydb/core/kqp/provider/yql_kikimr_results.h> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here I remove unnecessary includes and add only the explicitly needed ones. It needs to be done to eliminate dependency loop between kqp/provider
and kqp/host
@@ -0,0 +1,43 @@ | |||
CREATE VIEW `/Root/aggregates_and_window` WITH (security_invoker = TRUE) AS | |||
SELECT |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test might be an overkill, but it uses SUM, AVG and COUNT aggregate functions as well as a WINDOW clause
#6394
KIKIMR-21731
Add ModuleResolver from KQP host.
It seems that
COUNT
and other aggregate functions are implemented as imported modules. See, for example, AST of the following query:Note the following line:
Aggregate module
count_traits_factory
is implemented here.Add
ExpandApplyForLambdas
transformation step afterRewriteReadFromView
.The same is done to rewrite reads from views in YT. The necessity could be well understood by studying the differences in:
transformations of
(Note how
Apply
of a lambda disappears due to some graph transformation between the first and the second debug printout of the TExprNode graph of the pureSELECT
.)transformations of the same query written inside a view
Both (ModuleResolver addition and ExpandApplyForLambdas step repetition) are necessary to enable aggregate functions in views.
Copying default KQP host's translation settings is done to make view compilation more similar to a pure
SELECT
compilation. It is not a necessary part of the fix.