-
Notifications
You must be signed in to change notification settings - Fork 8k
Skip materialized view checking if source table does not exist #47975
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
kssenii
merged 7 commits into
ClickHouse:master
from
MikhailBurdukov:mburdukov_ignore_inacc_tables
Mar 28, 2023
Merged
Changes from 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
62c8eeb
Ignoring inaccessible tables for attaching to the materilized view
MikhailBurdukov f047e1b
Fixed new line
MikhailBurdukov 6811838
Rename opt key, added test and refactored code.
MikhailBurdukov abd9a5b
Fixed new lines in test
MikhailBurdukov cc92eac
Merged several tests into one and rm unnecessary func
MikhailBurdukov 57ceb34
Remove database from test
MikhailBurdukov c296c2e
Review changes
MikhailBurdukov File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -97,6 +97,7 @@ namespace ErrorCodes | |
| extern const int ILLEGAL_COLUMN; | ||
| extern const int LOGICAL_ERROR; | ||
| extern const int UNKNOWN_DATABASE; | ||
| extern const int UNKNOWN_TABLE; | ||
| extern const int PATH_ACCESS_DENIED; | ||
| extern const int NOT_IMPLEMENTED; | ||
| extern const int ENGINE_REQUIRED; | ||
|
|
@@ -1076,6 +1077,62 @@ void InterpreterCreateQuery::assertOrSetUUID(ASTCreateQuery & create, const Data | |
| } | ||
| } | ||
|
|
||
| void InterpreterCreateQuery::checkTypecompatibleForMaterializeView(const ASTCreateQuery & create) | ||
| { | ||
| if (StoragePtr to_table = DatabaseCatalog::instance().tryGetTable( | ||
| {create.to_table_id.database_name, create.to_table_id.table_name, create.to_table_id.uuid}, | ||
| getContext() | ||
| )) | ||
| { | ||
|
||
| Block input_block; | ||
| try | ||
| { | ||
| if (getContext()->getSettingsRef().allow_experimental_analyzer) | ||
| { | ||
| input_block = InterpreterSelectQueryAnalyzer::getSampleBlock(create.select->clone(), getContext()); | ||
| } | ||
| else | ||
| { | ||
| input_block = InterpreterSelectWithUnionQuery(create.select->clone(), | ||
| getContext(), | ||
| SelectQueryOptions().analyze()).getSampleBlock(); | ||
| } | ||
| } | ||
| catch (const Exception & e) | ||
| { | ||
| if (getContext()->getSettingsRef().skip_materialized_view_checking_if_source_table_not_exist && | ||
| e.code() == ErrorCodes::UNKNOWN_TABLE && create.attach | ||
| ) | ||
| { | ||
| LOG_WARNING(&Poco::Logger::get("InterpreterSelectQuery"), "{}", e.message()); | ||
| return; | ||
| } | ||
| else | ||
| { | ||
| throw; | ||
| } | ||
| } | ||
|
|
||
| Block output_block = to_table->getInMemoryMetadataPtr()->getSampleBlock(); | ||
|
|
||
| ColumnsWithTypeAndName input_columns; | ||
| ColumnsWithTypeAndName output_columns; | ||
| for (const auto & input_column : input_block) | ||
| { | ||
| if (const auto * output_column = output_block.findByName(input_column.name)) | ||
| { | ||
| input_columns.push_back(input_column.cloneEmpty()); | ||
| output_columns.push_back(output_column->cloneEmpty()); | ||
| } | ||
| } | ||
|
|
||
| ActionsDAG::makeConvertingActions( | ||
| input_columns, | ||
| output_columns, | ||
| ActionsDAG::MatchColumnsMode::Position | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| BlockIO InterpreterCreateQuery::createTable(ASTCreateQuery & create) | ||
| { | ||
|
|
@@ -1203,43 +1260,7 @@ BlockIO InterpreterCreateQuery::createTable(ASTCreateQuery & create) | |
| /// Check type compatible for materialized dest table and select columns | ||
| if (create.select && create.is_materialized_view && create.to_table_id) | ||
| { | ||
| if (StoragePtr to_table = DatabaseCatalog::instance().tryGetTable( | ||
| {create.to_table_id.database_name, create.to_table_id.table_name, create.to_table_id.uuid}, | ||
| getContext() | ||
| )) | ||
| { | ||
| Block input_block; | ||
|
|
||
| if (getContext()->getSettingsRef().allow_experimental_analyzer) | ||
| { | ||
| input_block = InterpreterSelectQueryAnalyzer::getSampleBlock(create.select->clone(), getContext()); | ||
| } | ||
| else | ||
| { | ||
| input_block = InterpreterSelectWithUnionQuery(create.select->clone(), | ||
| getContext(), | ||
| SelectQueryOptions().analyze()).getSampleBlock(); | ||
| } | ||
|
|
||
| Block output_block = to_table->getInMemoryMetadataPtr()->getSampleBlock(); | ||
|
|
||
| ColumnsWithTypeAndName input_columns; | ||
| ColumnsWithTypeAndName output_columns; | ||
| for (const auto & input_column : input_block) | ||
| { | ||
| if (const auto * output_column = output_block.findByName(input_column.name)) | ||
| { | ||
| input_columns.push_back(input_column.cloneEmpty()); | ||
| output_columns.push_back(output_column->cloneEmpty()); | ||
| } | ||
| } | ||
|
|
||
| ActionsDAG::makeConvertingActions( | ||
| input_columns, | ||
| output_columns, | ||
| ActionsDAG::MatchColumnsMode::Position | ||
| ); | ||
| } | ||
| checkTypecompatibleForMaterializeView(create); | ||
| } | ||
|
|
||
| DatabasePtr database; | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
tests/queries/0_stateless/02696_ignore_inacc_tables_mat_view_atttach.reference
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| 3 some_val | ||
| 3 9 |
29 changes: 29 additions & 0 deletions
29
tests/queries/0_stateless/02696_ignore_inacc_tables_mat_view_atttach.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| SET send_logs_level = 'fatal'; | ||
|
|
||
| CREATE TABLE test_table (n Int32, s String) ENGINE MergeTree PARTITION BY n ORDER BY n; | ||
|
|
||
| CREATE TABLE mview_backend (n Int32, n2 Int64) ENGINE MergeTree PARTITION BY n ORDER BY n; | ||
|
|
||
| CREATE MATERIALIZED VIEW mview TO mview_backend AS SELECT n, n * n AS "n2" FROM test_table; | ||
|
|
||
| DROP TABLE test_table; | ||
|
|
||
| DETACH TABLE mview; | ||
|
|
||
| /* Check that we get an exception with the option. */ | ||
|
|
||
| SET skip_materialized_view_checking_if_source_table_not_exist = 0; | ||
| ATTACH TABLE mview; --{serverError 60} | ||
|
|
||
| /* Check that we don't get an exception with the option. */ | ||
| SET skip_materialized_view_checking_if_source_table_not_exist = 1; | ||
| ATTACH TABLE mview; | ||
|
|
||
| /* Check if the data in the materialized view is updated after the restore.*/ | ||
| CREATE TABLE test_table (n Int32, s String) ENGINE MergeTree PARTITION BY n ORDER BY n; | ||
|
|
||
| INSERT INTO test_table VALUES (3,'some_val'); | ||
|
|
||
| SELECT n,s FROM test_table ORDER BY n; | ||
| SELECT n,n2 FROM mview ORDER by n; | ||
|
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Not sure that an additional setting is required. For me this PR a bug fix that makes behaviour of ATTACH query consistent for the both ordinary and materialized views.
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.
Agree that setting is probably redundant, ok to remove. (Though if not removing it - in my opinion its name should end with
_on_attach)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.
We should always skip the check on ATTACH query, the check makes sense for CREATE only
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.
If I understood you correctly, we should check type compatibility only in cases of
CREATE. I have reverted changes and added a simple check that the query is not attached.