Updated to not analyze create parameterized view for analyzer & old analyzer

This commit is contained in:
Smita Kulkarni 2023-11-20 14:41:14 +01:00
parent ba4a266d5b
commit 96c4b6bc35
3 changed files with 14 additions and 39 deletions

View File

@ -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)
{

View File

@ -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)

View File

@ -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})"