Skip to content

Capture TablePathPrefix (and other parts of the parser context) in CREATE VIEW #8991

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

Merged
merged 8 commits into from
Sep 17, 2024

Conversation

jepett0
Copy link
Collaborator

@jepett0 jepett0 commented Sep 9, 2024

#8992

We need to capture the parser context in order to use it later during a SELECT from the view to ensure that the results of the compilation of the view query text are the same as they were during CREATE VIEW. Postgres achieves the same by persisting AST of the view query, but our parser cannot handle this. More details on the problem can be found in the RFC.

…EATE VIEW

The captured context is used later to compile the view query in order to rewrite the read from the view node during a select from the view.

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.

return TStatus::Error;
Y_UNUSED(node);
Y_UNUSED(ctx);
return TStatus::Ok;
Copy link
Collaborator Author

@jepett0 jepett0 Sep 10, 2024

Choose a reason for hiding this comment

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

This change is needed for the intent determination transformer to be able to handle the following query:

DROP VIEW some_view;
CREATE VIEW some_other_view ...;

The same (i.e. nothing) is done in HandleCreateObject 12 lines above.

@@ -408,6 +408,46 @@ Y_UNIT_TEST_SUITE(TSelectFromViewTest) {
CompareResults(etalonResults, selectFromViewResults);
}

Y_UNIT_TEST(OneTableUsingRelativeName) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I would like to write an extensive test suite for views after this PR, so I add only a basic test of the new feature.

@@ -1239,8 +1239,12 @@ bool TSqlQuery::Statement(TVector<TNodePtr>& blocks, const TRule_sql_stmt_core&
}

std::map<TString, TDeferredAtom> features;
ParseViewOptions(features, node.GetRule_with_table_settings4());
ParseViewQuery(features, node.GetRule_select_stmt6());
if (!ParseViewOptions(features, node.GetRule_with_table_settings4())) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Here I fix a pretty impactful bug: the results of the view query verification by building an AST of the query text were discarded previously. Early validation of the queries stored in views didn't work.

@jepett0 jepett0 marked this pull request as ready for review September 10, 2024 10:47
@jepett0 jepett0 requested a review from a team as a code owner September 10, 2024 10:47
@jepett0 jepett0 requested a review from ijon September 10, 2024 11:05
@@ -1,6 +1,7 @@
#pragma once

#include <ydb/library/yql/core/pg_settings/guc_settings.h>
#include <ydb/library/yql/sql/settings/protos/translation_settings.pb.h>
Copy link
Collaborator

Choose a reason for hiding this comment

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

не надо ссылаться на protobuf-ы в основной либе

сделайте отдельную library, в которой будет save/load в protobuf классы

и вообще этот protobuf и library унесите в ydb

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Не знаю, как унести в YDB, учитывая, что эта библиотека нужна в sql_translation.cpp для валидации текста запроса view.

В отдельную библиотеку выделил, но она по-прежнему лежит в YQL юрисдикции: ydb/library/yql/sql/settings/serializer/serializer.h.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Унёс всё в YDB. Мотивация следующая:

  • KQP создаёт TTransltaionSettings, с которыми будет запущен парсер. Парсер не меняет эти настройки.
  • Сериализация нужна в KQP в момент создания TModifyScheme для CreateView.
  • Раз translation settings и создаются, и используются вне парсера, то логично их там и сериализовывать. Парсер в таком подходе ничего не знает об этой части сохранения контекста для view.

Важно отметить, что теперь, когда мы сериализуем контекст в KQP, этот процесс становится по смыслу равен сохранению применённых дефолтных настроек парсера в теле view. Query replay для тех же целей запоминает query type, с которым был выполнен запрос. Мы могли бы делать так же (query type было бы вполне достаточно), но поскольку view - это объект из мира парсера, то мы выбрали формат более подходящий для объекта из парсера.

- Inject dependencies on translation settings serializer to TSqlTranslation class.
- Move translation settings serializer to a separate library.

This comment was marked as outdated.

This comment was marked as outdated.

This comment was marked as outdated.

@jepett0 jepett0 requested a review from vitstn September 10, 2024 22:33

This comment was marked as outdated.

This comment was marked as outdated.

This comment was marked as outdated.

- capture TTranslationSettings in KQP
- runtime TContext parts as a view query text

This comment was marked as outdated.

This comment was marked as outdated.

This comment was marked as outdated.

@github-actions github-actions bot removed the rebase-and-check Rebase PR with the current base branch and check label Sep 13, 2024

This comment was marked as outdated.

This comment was marked as outdated.

This comment was marked as outdated.

Copy link

github-actions bot commented Sep 13, 2024

2024-09-13 14:36:24 UTC Pre-commit check linux-x86_64-release-asan for a24078c has started.
2024-09-13 14:37:53 UTC Artifacts will be uploaded here
2024-09-13 14:41:45 UTC ya make is running...
🔴 2024-09-13 16:51:51 UTC Some tests failed, follow the links below.

Test history | Ya make output

TESTS PASSED ERRORS FAILED SKIPPED MUTED?
14961 14640 0 17 38 266

🟢 2024-09-13 16:53:09 UTC Build successful.
🔴 2024-09-13 16:53:39 UTC ydbd size 5.6 GiB changed* by +2.0 MiB, which is >= 2.0 MiB vs main: Alert

ydbd size dash main: 7dd3efc merge: a24078c diff diff %
ydbd size 6 052 854 520 Bytes 6 054 986 848 Bytes +2.0 MiB +0.035%
ydbd stripped size 1 514 782 160 Bytes 1 514 841 264 Bytes +57.7 KiB +0.004%

*please be aware that the difference is based on comparing your commit and the last completed build from the post-commit, check comparation

Copy link

github-actions bot commented Sep 13, 2024

2024-09-13 14:49:44 UTC Pre-commit check linux-x86_64-release-clang14 for a24078c has started.
2024-09-13 14:50:03 UTC Artifacts will be uploaded here
2024-09-13 14:53:19 UTC ya make is running...
🟢 2024-09-13 15:39:14 UTC Build successful.

Copy link

github-actions bot commented Sep 13, 2024

2024-09-13 14:54:42 UTC Pre-commit check linux-x86_64-relwithdebinfo for a24078c has started.
2024-09-13 14:55:29 UTC Artifacts will be uploaded here
2024-09-13 14:59:05 UTC ya make is running...
🟡 2024-09-13 16:42:48 UTC Some tests failed, follow the links below. Going to retry failed tests...

Test history | Ya make output

TESTS PASSED ERRORS FAILED SKIPPED MUTED?
77374 63271 0 18 14049 36

2024-09-13 16:50:29 UTC ya make is running... (failed tests rerun, try 2)
🟢 2024-09-13 17:01:51 UTC Tests successful.

Test history | Ya make output

TESTS PASSED ERRORS FAILED SKIPPED MUTED?
301 (only retried tests) 206 0 0 7 88

🟢 2024-09-13 17:02:00 UTC Build successful.
🔴 2024-09-13 17:02:38 UTC ydbd size 8.4 GiB changed* by +2.5 MiB, which is >= 2.0 MiB vs main: Alert

ydbd size dash main: 7dd3efc merge: a24078c diff diff %
ydbd size 9 043 910 216 Bytes 9 046 504 032 Bytes +2.5 MiB +0.029%
ydbd stripped size 488 900 424 Bytes 488 916 392 Bytes +15.6 KiB +0.003%

*please be aware that the difference is based on comparing your commit and the last completed build from the post-commit, check comparation

@jepett0 jepett0 merged commit f25098d into ydb-platform:main Sep 17, 2024
10 of 12 checks passed
@shnikd shnikd mentioned this pull request Sep 19, 2024
jepett0 added a commit to jepett0/ydb that referenced this pull request Sep 26, 2024
jepett0 added a commit that referenced this pull request Sep 27, 2024
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.

3 participants