提交 67eefa7b 编写于 作者: I Ivan Lezhankin

Revert wrong replacements of dynamic_cast.

dynamic_cast to intermediate type is not equivalent to typeid_cast
上级 a3a8b2bb
......@@ -1228,7 +1228,8 @@ private:
String current_format = format;
/// The query can specify output format or output file.
if (const auto * query_with_output = parsed_query->as<ASTQueryWithOutput>())
/// FIXME: try to prettify this cast using `as<>()`
if (const auto * query_with_output = dynamic_cast<const ASTQueryWithOutput *>(parsed_query.get()))
{
if (query_with_output->out_file)
{
......
......@@ -501,7 +501,7 @@ static ASTPtr extractPartitionKey(const ASTPtr & storage_ast)
}
ASTPtr arguments_ast = engine->arguments->clone();
ASTs & arguments = arguments_ast->as<ASTExpressionList>()->children; // FIXME: what' the point of casting?
ASTs & arguments = arguments_ast->children;
if (isExtendedDefinitionStorage(storage_ast))
{
......
......@@ -35,8 +35,15 @@ std::enable_if_t<std::is_reference_v<To>, To> typeid_cast(From & from)
template <typename To, typename From>
To typeid_cast(From * from)
{
if (typeid(*from) == typeid(std::remove_pointer_t<To>))
return static_cast<To>(from);
else
return nullptr;
try
{
if (typeid(*from) == typeid(std::remove_pointer_t<To>))
return static_cast<To>(from);
else
return nullptr;
}
catch (const std::exception & e)
{
throw DB::Exception(e.what(), DB::ErrorCodes::BAD_CAST);
}
}
......@@ -42,7 +42,8 @@ Block InterpreterShowCreateQuery::getSampleBlock()
BlockInputStreamPtr InterpreterShowCreateQuery::executeImpl()
{
const auto * ast = query_ptr->as<ASTQueryWithTableAndOutput>();
/// FIXME: try to prettify this cast using `as<>()`
const auto * ast = dynamic_cast<const ASTQueryWithTableAndOutput *>(query_ptr.get());
if (ast->temporary && !ast->database.empty())
throw Exception("Temporary databases are not possible.", ErrorCodes::SYNTAX_ERROR);
......
......@@ -359,11 +359,10 @@ void optimizeLimitBy(const ASTSelectQuery * select_query)
/// Remove duplicated columns from USING(...).
void optimizeUsing(const ASTSelectQuery * select_query)
{
const auto * node = select_query->join()->as<ASTTablesInSelectQueryElement>();
if (!node)
if (!select_query->join())
return;
const auto * table_join = node->table_join->as<ASTTableJoin>();
const auto * table_join = select_query->join()->table_join->as<ASTTableJoin>();
if (!(table_join && table_join->using_expression_list))
return;
......
......@@ -506,7 +506,8 @@ void executeQuery(
if (streams.in)
{
const auto * ast_query_with_output = ast->as<ASTQueryWithOutput>();
/// FIXME: try to prettify this cast using `as<>()`
const auto * ast_query_with_output = dynamic_cast<const ASTQueryWithOutput *>(ast.get());
WriteBuffer * out_buf = &ostr;
std::optional<WriteBufferFromFile> out_file_buf;
......
......@@ -49,7 +49,8 @@ void ASTQueryWithOutput::formatImpl(const FormatSettings & s, FormatState & stat
bool ASTQueryWithOutput::resetOutputASTIfExist(IAST & ast)
{
if (auto * ast_with_output = ast.as<ASTQueryWithOutput>())
/// FIXME: try to prettify this cast using `as<>()`
if (auto * ast_with_output = dynamic_cast<ASTQueryWithOutput *>(&ast))
{
ast_with_output->format.reset();
ast_with_output->out_file.reset();
......
......@@ -1254,7 +1254,8 @@ bool ParserWithOptionalAlias::parseImpl(Pos & pos, ASTPtr & node, Expected & exp
ASTPtr alias_node;
if (ParserAlias(allow_alias_without_as_keyword_now).parse(pos, alias_node, expected))
{
if (auto * ast_with_alias = node->as<ASTWithAlias>())
/// FIXME: try to prettify this cast using `as<>()`
if (auto * ast_with_alias = dynamic_cast<ASTWithAlias *>(node.get()))
{
getIdentifierName(alias_node, ast_with_alias->alias);
ast_with_alias->prefer_alias_to_column_name = prefer_alias_to_column_name;
......
......@@ -45,12 +45,14 @@ public:
template <class Derived>
Derived * as()
{
// TODO: check, if we downcasting to base type, then just return |this|.
return typeid_cast<Derived *>(this);
}
template <class Derived>
const Derived * as() const
{
// TODO: check, if we downcasting to base type, then just return |this|.
return typeid_cast<const Derived *>(this);
}
......
......@@ -62,7 +62,8 @@ bool ParserQueryWithOutput::parseImpl(Pos & pos, ASTPtr & node, Expected & expec
if (!parsed)
return false;
auto * query_with_output = query->as<ASTQueryWithOutput>();
/// FIXME: try to prettify this cast using `as<>()`
auto * query_with_output = dynamic_cast<ASTQueryWithOutput *>(query.get());
ParserKeyword s_into_outfile("INTO OUTFILE");
if (s_into_outfile.ignore(pos, expected))
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册