diff --git a/src/Storages/StorageView.cpp b/src/Storages/StorageView.cpp index 75bd4b2967f..113cd0b6233 100644 --- a/src/Storages/StorageView.cpp +++ b/src/Storages/StorageView.cpp @@ -33,8 +33,10 @@ namespace ErrorCodes StorageView::StorageView( const StorageID & table_id_, const ASTCreateQuery & query, - const ColumnsDescription & columns_) + const ColumnsDescription & columns_, + const Settings & settings) : IStorage(table_id_) + , settings_changes{{"join_use_nulls", Field(settings.join_use_nulls)}} { StorageInMemoryMetadata storage_metadata; storage_metadata.setColumns(columns_); @@ -85,7 +87,10 @@ void StorageView::read( current_inner_query = query_info.view_query->clone(); } - InterpreterSelectWithUnionQuery interpreter(current_inner_query, context, {}, column_names); + auto modified_context = Context::createCopy(context); + modified_context->applySettingsChanges(settings_changes); + + InterpreterSelectWithUnionQuery interpreter(current_inner_query, modified_context, {}, column_names); interpreter.buildQueryPlan(query_plan); /// It's expected that the columns read from storage are not constant. @@ -173,7 +178,7 @@ void registerStorageView(StorageFactory & factory) if (args.query.storage) throw Exception("Specifying ENGINE is not allowed for a View", ErrorCodes::INCORRECT_QUERY); - return StorageView::create(args.table_id, args.query, args.columns); + return StorageView::create(args.table_id, args.query, args.columns, args.getLocalContext()->getSettingsRef()); }); } diff --git a/src/Storages/StorageView.h b/src/Storages/StorageView.h index fa11472218d..b2a22544559 100644 --- a/src/Storages/StorageView.h +++ b/src/Storages/StorageView.h @@ -52,7 +52,10 @@ protected: StorageView( const StorageID & table_id_, const ASTCreateQuery & query, - const ColumnsDescription & columns_); + const ColumnsDescription & columns_, + const Settings & settings); + + SettingsChanges settings_changes; }; } diff --git a/src/TableFunctions/TableFunctionView.cpp b/src/TableFunctions/TableFunctionView.cpp index 3f51e0bbc95..d31592832bd 100644 --- a/src/TableFunctions/TableFunctionView.cpp +++ b/src/TableFunctions/TableFunctionView.cpp @@ -42,7 +42,7 @@ StoragePtr TableFunctionView::executeImpl( const ASTPtr & /*ast_function*/, ContextPtr context, const std::string & table_name, ColumnsDescription /*cached_columns*/) const { auto columns = getActualTableStructure(context); - auto res = StorageView::create(StorageID(getDatabaseName(), table_name), create, columns); + auto res = StorageView::create(StorageID(getDatabaseName(), table_name), create, columns, context->getSettingsRef()); res->startup(); return res; } diff --git a/tests/queries/0_stateless/01866_view_persist_settings.reference b/tests/queries/0_stateless/01866_view_persist_settings.reference new file mode 100644 index 00000000000..a51c6e2617d --- /dev/null +++ b/tests/queries/0_stateless/01866_view_persist_settings.reference @@ -0,0 +1,8 @@ +1 11 0 +1 12 0 +2 11 22 +2 11 23 +2 12 22 +2 12 23 +3 0 22 +3 0 23 diff --git a/tests/queries/0_stateless/01866_view_persist_settings.sql b/tests/queries/0_stateless/01866_view_persist_settings.sql new file mode 100644 index 00000000000..3e2dfb65dd2 --- /dev/null +++ b/tests/queries/0_stateless/01866_view_persist_settings.sql @@ -0,0 +1,16 @@ +DROP TABLE IF EXISTS some_test_view; + +SET join_use_nulls = 0; + +CREATE OR REPLACE VIEW some_test_view +AS +SELECT * FROM ( SELECT arrayJoin([1, 2]) AS a, arrayJoin([11, 12]) AS b ) AS t1 +FULL JOIN ( SELECT arrayJoin([2, 3]) AS a, arrayJoin([22, 23]) AS c ) AS t2 +USING a +ORDER BY a; + +SET join_use_nulls = 1; + +SELECT * from some_test_view; + +DROP TABLE some_test_view;