Modify visitor

This commit is contained in:
Antonio Andelic 2022-11-23 10:27:38 +00:00
parent 84884df595
commit e84e05d849
3 changed files with 29 additions and 9 deletions

View File

@ -5,6 +5,7 @@
#include <stack> #include <stack>
#include <Parsers/ASTFunction.h> #include <Parsers/ASTFunction.h>
#include <Parsers/ASTColumnDeclaration.h>
#include <Parsers/ASTCreateFunctionQuery.h> #include <Parsers/ASTCreateFunctionQuery.h>
#include <Parsers/ASTExpressionList.h> #include <Parsers/ASTExpressionList.h>
#include <Parsers/ASTIdentifier.h> #include <Parsers/ASTIdentifier.h>

View File

@ -4,7 +4,9 @@
#include <vector> #include <vector>
#include <Common/typeid_cast.h> #include <Common/typeid_cast.h>
#include <Common/checkStackSize.h> #include <Common/checkStackSize.h>
#include <Parsers/IAST_fwd.h>
#include <Parsers/DumpASTNode.h> #include <Parsers/DumpASTNode.h>
#include <Parsers/ASTColumnDeclaration.h>
namespace DB namespace DB
@ -80,7 +82,7 @@ private:
template <bool with_dump> template <bool with_dump>
void visitChildren(T & ast) void visitChildren(T & ast)
{ {
for (auto & child : ast->children) const auto visit_child = [&](auto & child)
{ {
bool need_visit_child = false; bool need_visit_child = false;
if constexpr (need_child_accept_data) if constexpr (need_child_accept_data)
@ -90,6 +92,23 @@ private:
if (need_visit_child) if (need_visit_child)
visitImpl<with_dump>(child); visitImpl<with_dump>(child);
};
for (auto & child : ast->children)
{
visit_child(child);
}
if constexpr (std::same_as<T, ASTPtr>)
{
if (auto * col_decl = ast->template as<ASTColumnDeclaration>())
{
if (col_decl->default_expression)
visit_child(col_decl->default_expression);
if (col_decl->default_expression)
visit_child(col_decl->default_expression);
}
} }
} }
}; };

View File

@ -470,7 +470,7 @@ ColumnsDescription InterpreterCreateQuery::getColumnsDescription(
for (const auto & ast : columns_ast.children) for (const auto & ast : columns_ast.children)
{ {
auto & col_decl = ast->as<ASTColumnDeclaration &>(); const auto & col_decl = ast->as<ASTColumnDeclaration &>();
if (col_decl.collation && !context_->getSettingsRef().compatibility_ignore_collation_in_create_table) if (col_decl.collation && !context_->getSettingsRef().compatibility_ignore_collation_in_create_table)
{ {
@ -523,13 +523,6 @@ ColumnsDescription InterpreterCreateQuery::getColumnsDescription(
/// add column to postprocessing if there is a default_expression specified /// add column to postprocessing if there is a default_expression specified
if (col_decl.default_expression) if (col_decl.default_expression)
{ {
// substitute possible UDFs with their definitions
if (!UserDefinedSQLFunctionFactory::instance().empty())
{
UserDefinedSQLFunctionVisitor::Data data_user_defined_functions_visitor;
UserDefinedSQLFunctionVisitor(data_user_defined_functions_visitor).visit(col_decl.default_expression);
}
/** For columns with explicitly-specified type create two expressions: /** For columns with explicitly-specified type create two expressions:
* 1. default_expression aliased as column name with _tmp suffix * 1. default_expression aliased as column name with _tmp suffix
* 2. conversion of expression (1) to explicitly-specified type alias as column name * 2. conversion of expression (1) to explicitly-specified type alias as column name
@ -1166,6 +1159,13 @@ BlockIO InterpreterCreateQuery::createTable(ASTCreateQuery & create)
visitor.visit(*create.columns_list); visitor.visit(*create.columns_list);
} }
// substitute possible UDFs with their definitions
if (!UserDefinedSQLFunctionFactory::instance().empty())
{
UserDefinedSQLFunctionVisitor::Data data_user_defined_functions_visitor;
UserDefinedSQLFunctionVisitor(data_user_defined_functions_visitor).visit(query_ptr);
}
/// Set and retrieve list of columns, indices and constraints. Set table engine if needed. Rewrite query in canonical way. /// Set and retrieve list of columns, indices and constraints. Set table engine if needed. Rewrite query in canonical way.
TableProperties properties = getTablePropertiesAndNormalizeCreateQuery(create); TableProperties properties = getTablePropertiesAndNormalizeCreateQuery(create);