From 96c4b6bc35ee818afd2d2963dec7afdb5583969c Mon Sep 17 00:00:00 2001 From: Smita Kulkarni Date: Mon, 20 Nov 2023 14:41:14 +0100 Subject: [PATCH] Updated to not analyze create parameterized view for analyzer & old analyzer --- src/Interpreters/InterpreterCreateQuery.cpp | 48 +++++-------------- src/Storages/StorageView.cpp | 3 +- .../0_stateless/02428_parameterized_view.sh | 2 +- 3 files changed, 14 insertions(+), 39 deletions(-) diff --git a/src/Interpreters/InterpreterCreateQuery.cpp b/src/Interpreters/InterpreterCreateQuery.cpp index 747c0be009e..4ee666e2a9a 100644 --- a/src/Interpreters/InterpreterCreateQuery.cpp +++ b/src/Interpreters/InterpreterCreateQuery.cpp @@ -649,6 +649,7 @@ ColumnsDescription InterpreterCreateQuery::getColumnsDescription( if (!attach && !is_restore_from_backup && context_->getSettingsRef().flatten_nested) res.flattenNested(); + if (res.getAllPhysical().empty()) throw Exception(ErrorCodes::EMPTY_LIST_OF_COLUMNS_PASSED, "Cannot CREATE table without physical columns"); @@ -755,49 +756,22 @@ InterpreterCreateQuery::TableProperties InterpreterCreateQuery::getTableProperti { Block as_select_sample; - if (getContext()->getSettingsRef().allow_experimental_analyzer) + if (!create.isParameterizedView()) { - if (create.isParameterizedView()) - { - auto select = create.select->clone(); - - ///Get all query parameters - const auto parameters = analyzeReceiveQueryParamsWithType(select); - NameToNameMap parameter_values; - - for (const auto & parameter : parameters) - { - const auto data_type = DataTypeFactory::instance().get(parameter.second); - /// Todo improve getting default values & include more datatypes - if (data_type->isValueRepresentedByNumber() || parameter.second == "String") - parameter_values[parameter.first] = "1"; - else if (parameter.second.starts_with("Array") || parameter.second.starts_with("Map")) - parameter_values[parameter.first] = "[]"; - else - parameter_values[parameter.first] = " "; - } - - /// Replace with default parameters - ReplaceQueryParameterVisitor visitor(parameter_values); - visitor.visit(select); - - as_select_sample = InterpreterSelectQueryAnalyzer::getSampleBlock(select, getContext()); - } - else + if (getContext()->getSettingsRef().allow_experimental_analyzer) { as_select_sample = InterpreterSelectQueryAnalyzer::getSampleBlock(create.select->clone(), getContext()); } + else + { + as_select_sample = InterpreterSelectWithUnionQuery::getSampleBlock(create.select->clone(), + getContext(), + false /* is_subquery */, + create.isParameterizedView()); + } + properties.columns = ColumnsDescription(as_select_sample.getNamesAndTypesList()); } - else - { - as_select_sample = InterpreterSelectWithUnionQuery::getSampleBlock(create.select->clone(), - getContext(), - false /* is_subquery */, - create.isParameterizedView()); - } - - properties.columns = ColumnsDescription(as_select_sample.getNamesAndTypesList()); } else if (create.as_table_function) { diff --git a/src/Storages/StorageView.cpp b/src/Storages/StorageView.cpp index f0f9b9540de..2f7267e3701 100644 --- a/src/Storages/StorageView.cpp +++ b/src/Storages/StorageView.cpp @@ -112,7 +112,8 @@ StorageView::StorageView( : IStorage(table_id_) { StorageInMemoryMetadata storage_metadata; - storage_metadata.setColumns(columns_); + if (is_parameterized_view_ && !query.isParameterizedView()) + storage_metadata.setColumns(columns_); storage_metadata.setComment(comment); if (!query.select) diff --git a/tests/queries/0_stateless/02428_parameterized_view.sh b/tests/queries/0_stateless/02428_parameterized_view.sh index ad9c672f4c5..499b8697ffc 100755 --- a/tests/queries/0_stateless/02428_parameterized_view.sh +++ b/tests/queries/0_stateless/02428_parameterized_view.sh @@ -37,7 +37,7 @@ $CLICKHOUSE_CLIENT -q "CREATE VIEW test_02428_pv1 AS SELECT * FROM test_02428_Ca $CLICKHOUSE_CLIENT -q "SELECT Price FROM test_02428_pv1(price=20)" $CLICKHOUSE_CLIENT -q "SELECT Price FROM \`test_02428_pv1\`(price=20)" -$CLICKHOUSE_CLIENT -q "SELECT Price FROM test_02428_pv1" 2>&1 | grep -Fq "UNKNOWN_QUERY_PARAMETER" && echo 'ERROR' || echo 'OK' +$CLICKHOUSE_CLIENT -q "SELECT Price FROM test_02428_pv1" 2>&1 | grep -q "UNKNOWN_QUERY_PARAMETER\|UNKNOWN_IDENTIFIER" && echo 'ERROR' || echo 'OK' $CLICKHOUSE_CLIENT --param_p 10 -q "SELECT Price FROM test_02428_pv1(price={p:UInt64})" $CLICKHOUSE_CLIENT --param_l 1 -q "SELECT Price FROM test_02428_pv1(price=50) LIMIT ({l:UInt64})"