Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 21 additions & 23 deletions src/Databases/DDLDependencyVisitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -387,34 +387,32 @@ namespace

const auto & arg = args[arg_idx];

if (evaluate)
if (const auto * id = arg->as<ASTIdentifier>())
return id->name();

if (const auto * literal = arg->as<ASTLiteral>())
{
try
{
/// We're just searching for dependencies here, it's not safe to execute subqueries now.
/// Use copy of the global_context and set current database, because expressions can contain currentDatabase() function.
ContextMutablePtr global_context_copy = Context::createCopy(global_context);
global_context_copy->setCurrentDatabase(current_database);
auto evaluated = evaluateConstantExpressionOrIdentifierAsLiteral(arg, global_context_copy);
const auto * literal = evaluated->as<ASTLiteral>();
if (!literal || (literal->value.getType() != Field::Types::String))
return {};
if (literal->value.getType() == Field::Types::String)
return literal->value.safeGet<String>();
}
catch (...)
{
}

if (!evaluate)
return {};

try
{
/// We're just searching for dependencies here, it's not safe to execute subqueries now.
/// Use copy of the global_context and set current database, because expressions can contain currentDatabase() function.
ContextMutablePtr global_context_copy = Context::createCopy(global_context);
global_context_copy->setCurrentDatabase(current_database);
auto evaluated = evaluateConstantExpressionOrIdentifierAsLiteral(arg, global_context_copy);
const auto * literal = evaluated->as<ASTLiteral>();
if (!literal || (literal->value.getType() != Field::Types::String))
return {};
}
return literal->value.safeGet<String>();
}
else
catch (...)
{
if (const auto * id = arg->as<ASTIdentifier>())
return id->name();
if (const auto * literal = arg->as<ASTLiteral>())
{
if (literal->value.getType() == Field::Types::String)
return literal->value.safeGet<String>();
}
return {};
}
}
Expand Down