From d6121a8544abb8d81e69b554fcc697cfa8fa90ff Mon Sep 17 00:00:00 2001 From: Alexey Milovidov Date: Mon, 26 Feb 2018 06:40:20 +0300 Subject: [PATCH 1/4] Simplification of AST #1947 --- dbms/src/Analyzers/AnalyzeColumns.cpp | 9 ++- dbms/src/Core/iostream_debug_helpers.cpp | 4 +- dbms/src/Interpreters/Aggregator.cpp | 2 +- dbms/src/Interpreters/ExpressionAnalyzer.cpp | 27 +++++---- .../InJoinSubqueriesPreprocessor.cpp | 10 ++-- .../Interpreters/InterpreterAlterQuery.cpp | 8 +-- .../Interpreters/InterpreterCreateQuery.cpp | 10 ++-- .../Interpreters/InterpreterSelectQuery.cpp | 2 +- .../evaluateConstantExpression.cpp | 5 +- dbms/src/Parsers/ASTAlterQuery.cpp | 4 -- dbms/src/Parsers/ASTAlterQuery.h | 2 - dbms/src/Parsers/ASTAsterisk.h | 2 - dbms/src/Parsers/ASTCheckQuery.h | 2 - dbms/src/Parsers/ASTColumnDeclaration.h | 3 - dbms/src/Parsers/ASTCreateQuery.h | 5 -- dbms/src/Parsers/ASTDropQuery.h | 3 - dbms/src/Parsers/ASTEnumElement.h | 6 +- dbms/src/Parsers/ASTExpressionList.h | 3 - dbms/src/Parsers/ASTFunction.h | 23 +------- dbms/src/Parsers/ASTIdentifier.h | 5 +- dbms/src/Parsers/ASTInsertQuery.h | 3 - dbms/src/Parsers/ASTKillQueryQuery.h | 4 -- dbms/src/Parsers/ASTLiteral.h | 3 +- dbms/src/Parsers/ASTNameTypePair.h | 3 - dbms/src/Parsers/ASTOptimizeQuery.h | 3 - dbms/src/Parsers/ASTOrderByElement.h | 9 +-- dbms/src/Parsers/ASTPartition.h | 2 - dbms/src/Parsers/ASTQualifiedAsterisk.h | 2 - dbms/src/Parsers/ASTQueryWithOutput.h | 13 ++--- dbms/src/Parsers/ASTQueryWithTableAndOutput.h | 7 --- dbms/src/Parsers/ASTRenameQuery.h | 3 - dbms/src/Parsers/ASTSampleRatio.h | 4 +- dbms/src/Parsers/ASTSelectQuery.cpp | 20 +++---- dbms/src/Parsers/ASTSelectQuery.h | 3 - dbms/src/Parsers/ASTSetQuery.h | 3 - dbms/src/Parsers/ASTShowTablesQuery.h | 3 - dbms/src/Parsers/ASTSubquery.h | 4 +- dbms/src/Parsers/ASTSystemQuery.h | 3 - dbms/src/Parsers/ASTUseQuery.h | 3 - dbms/src/Parsers/ExpressionElementParsers.cpp | 58 ++++++------------- dbms/src/Parsers/ExpressionListParsers.cpp | 8 +-- dbms/src/Parsers/IAST.h | 8 +-- dbms/src/Parsers/IParserBase.cpp | 4 +- dbms/src/Parsers/ParserAlterQuery.cpp | 3 - dbms/src/Parsers/ParserCase.cpp | 11 ++-- dbms/src/Parsers/ParserCheckQuery.cpp | 6 +- dbms/src/Parsers/ParserCreateQuery.cpp | 20 ++----- dbms/src/Parsers/ParserCreateQuery.h | 8 +-- dbms/src/Parsers/ParserDescribeTableQuery.cpp | 3 - dbms/src/Parsers/ParserDropQuery.cpp | 4 +- dbms/src/Parsers/ParserInsertQuery.cpp | 4 +- dbms/src/Parsers/ParserKillQueryQuery.cpp | 3 - dbms/src/Parsers/ParserOptimizeQuery.cpp | 4 +- dbms/src/Parsers/ParserPartition.cpp | 1 - dbms/src/Parsers/ParserRenameQuery.cpp | 4 +- dbms/src/Parsers/ParserSampleRatio.cpp | 4 +- dbms/src/Parsers/ParserSelectQuery.cpp | 4 -- dbms/src/Parsers/ParserSetQuery.cpp | 4 +- dbms/src/Parsers/ParserShowProcesslistQuery.h | 3 - dbms/src/Parsers/ParserShowTablesQuery.cpp | 4 -- dbms/src/Parsers/ParserSystemQuery.cpp | 3 - .../Parsers/ParserTablePropertiesQuery.cpp | 4 -- dbms/src/Parsers/ParserUseQuery.cpp | 6 +- dbms/src/Parsers/StringRange.h | 6 +- dbms/src/Parsers/TablePropertiesQueriesASTs.h | 2 - .../parseIdentifierOrStringLiteral.cpp | 4 +- dbms/src/Parsers/queryToString.cpp | 1 - dbms/src/Server/ClusterCopier.cpp | 8 +-- dbms/src/Storages/AlterCommands.cpp | 10 ++-- .../MergeTree/MergeTreeDataSelectExecutor.cpp | 13 ++--- dbms/src/Storages/MergeTree/PKCondition.cpp | 3 +- dbms/src/Storages/StorageBuffer.cpp | 2 +- dbms/src/Storages/StorageCatBoostPool.cpp | 5 +- dbms/src/Storages/StorageDistributed.cpp | 9 +-- dbms/src/Storages/StorageMergeTree.cpp | 4 +- dbms/src/Storages/VirtualColumnUtils.cpp | 2 +- .../transformQueryForExternalDatabase.cpp | 2 +- 77 files changed, 135 insertions(+), 347 deletions(-) diff --git a/dbms/src/Analyzers/AnalyzeColumns.cpp b/dbms/src/Analyzers/AnalyzeColumns.cpp index 1e0883f2d3a..1a8b137a573 100644 --- a/dbms/src/Analyzers/AnalyzeColumns.cpp +++ b/dbms/src/Analyzers/AnalyzeColumns.cpp @@ -135,7 +135,7 @@ ASTPtr createASTIdentifierForColumnInTable(const String & column, const CollectT { ASTPtr database_name_identifier_node; if (!table.database_name.empty()) - database_name_identifier_node = std::make_shared(StringRange(), table.database_name, ASTIdentifier::Column); + database_name_identifier_node = std::make_shared(table.database_name, ASTIdentifier::Column); ASTPtr table_name_identifier_node; String table_name_or_alias; @@ -146,9 +146,9 @@ ASTPtr createASTIdentifierForColumnInTable(const String & column, const CollectT table_name_or_alias = table.alias; if (!table_name_or_alias.empty()) - table_name_identifier_node = std::make_shared(StringRange(), table_name_or_alias, ASTIdentifier::Column); + table_name_identifier_node = std::make_shared(table_name_or_alias, ASTIdentifier::Column); - ASTPtr column_identifier_node = std::make_shared(StringRange(), column, ASTIdentifier::Column); + ASTPtr column_identifier_node = std::make_shared(column, ASTIdentifier::Column); String compound_name; if (database_name_identifier_node) @@ -157,8 +157,7 @@ ASTPtr createASTIdentifierForColumnInTable(const String & column, const CollectT compound_name += table_name_or_alias + "."; compound_name += column; - auto elem = std::make_shared( - StringRange(), compound_name, ASTIdentifier::Column); + auto elem = std::make_shared(compound_name, ASTIdentifier::Column); if (database_name_identifier_node) elem->children.emplace_back(std::move(database_name_identifier_node)); diff --git a/dbms/src/Core/iostream_debug_helpers.cpp b/dbms/src/Core/iostream_debug_helpers.cpp index 57a3d215b69..a4b0cba85b8 100644 --- a/dbms/src/Core/iostream_debug_helpers.cpp +++ b/dbms/src/Core/iostream_debug_helpers.cpp @@ -123,9 +123,7 @@ std::ostream & operator<<(std::ostream & stream, const SubqueryForSet & what) std::ostream & operator<<(std::ostream & stream, const IAST & what) { - stream << "IAST(" - << "query_string = " << what.query_string - <<"){"; + stream << "IAST{"; what.dumpTree(stream); stream << "}"; return stream; diff --git a/dbms/src/Interpreters/Aggregator.cpp b/dbms/src/Interpreters/Aggregator.cpp index ecd19370ef9..eebc95cada9 100644 --- a/dbms/src/Interpreters/Aggregator.cpp +++ b/dbms/src/Interpreters/Aggregator.cpp @@ -112,7 +112,7 @@ Block Aggregator::getHeader(bool final) const else type = std::make_shared(params.aggregates[i].function, argument_types, params.aggregates[i].parameters); - res.insert({ type->createColumn(), type, params.aggregates[i].column_name }); + res.insert({ type, params.aggregates[i].column_name }); } } else if (params.intermediate_header) diff --git a/dbms/src/Interpreters/ExpressionAnalyzer.cpp b/dbms/src/Interpreters/ExpressionAnalyzer.cpp index b7f67e8566c..a1cf16a1a27 100644 --- a/dbms/src/Interpreters/ExpressionAnalyzer.cpp +++ b/dbms/src/Interpreters/ExpressionAnalyzer.cpp @@ -359,7 +359,7 @@ void ExpressionAnalyzer::translateQualifiedNamesImpl(ASTPtr & ast, const String || (!alias.empty() && ident->name == alias)))) { /// Replace to plain asterisk. - ast = std::make_shared(ast->range); + ast = std::make_shared(); } } else @@ -688,8 +688,7 @@ static std::shared_ptr interpretSubquery( /// manually substitute column names in place of asterisk for (const auto & column : columns) - select_expression_list->children.emplace_back(std::make_shared( - StringRange{}, column.name)); + select_expression_list->children.emplace_back(std::make_shared(column.name)); select_query->replaceDatabaseAndTable(database_table.first, database_table.second); } @@ -808,7 +807,7 @@ void ExpressionAnalyzer::addExternalStorage(ASTPtr & subquery_or_table_name_or_t * instead of doing a subquery, you just need to read it. */ - auto database_and_table_name = std::make_shared(StringRange(), external_table_name, ASTIdentifier::Table); + auto database_and_table_name = std::make_shared(external_table_name, ASTIdentifier::Table); if (auto ast_table_expr = typeid_cast(subquery_or_table_name_or_table_expression.get())) { @@ -1032,7 +1031,7 @@ void ExpressionAnalyzer::normalizeTreeImpl( { ASTs all_columns; for (const auto & column_name_type : columns) - all_columns.emplace_back(std::make_shared(asterisk->range, column_name_type.name)); + all_columns.emplace_back(std::make_shared(column_name_type.name)); asts.erase(asts.begin() + i); asts.insert(asts.begin() + i, all_columns.begin(), all_columns.end()); @@ -1147,17 +1146,17 @@ void ExpressionAnalyzer::executeScalarSubqueries() static ASTPtr addTypeConversion(std::unique_ptr && ast, const String & type_name) { - auto func = std::make_shared(ast->range); + auto func = std::make_shared(); ASTPtr res = func; func->alias = ast->alias; func->prefer_alias_to_column_name = ast->prefer_alias_to_column_name; ast->alias.clear(); func->name = "CAST"; - auto exp_list = std::make_shared(ast->range); + auto exp_list = std::make_shared(); func->arguments = exp_list; func->children.push_back(func->arguments); exp_list->children.emplace_back(ast.release()); - exp_list->children.emplace_back(std::make_shared(StringRange(), type_name)); + exp_list->children.emplace_back(std::make_shared(type_name)); return res; } @@ -1200,7 +1199,7 @@ void ExpressionAnalyzer::executeScalarSubqueriesImpl(ASTPtr & ast) if (!block) { /// Interpret subquery with empty result as Null literal - auto ast_new = std::make_unique(ast->range, Null()); + auto ast_new = std::make_unique(Null()); ast_new->setAlias(ast->tryGetAlias()); ast = std::move(ast_new); return; @@ -1220,18 +1219,18 @@ void ExpressionAnalyzer::executeScalarSubqueriesImpl(ASTPtr & ast) size_t columns = block.columns(); if (columns == 1) { - auto lit = std::make_unique(ast->range, (*block.safeGetByPosition(0).column)[0]); + auto lit = std::make_unique((*block.safeGetByPosition(0).column)[0]); lit->alias = subquery->alias; lit->prefer_alias_to_column_name = subquery->prefer_alias_to_column_name; ast = addTypeConversion(std::move(lit), block.safeGetByPosition(0).type->getName()); } else { - auto tuple = std::make_shared(ast->range); + auto tuple = std::make_shared(); tuple->alias = subquery->alias; ast = tuple; tuple->name = "tuple"; - auto exp_list = std::make_shared(ast->range); + auto exp_list = std::make_shared(); tuple->arguments = exp_list; tuple->children.push_back(tuple->arguments); @@ -1239,7 +1238,7 @@ void ExpressionAnalyzer::executeScalarSubqueriesImpl(ASTPtr & ast) for (size_t i = 0; i < columns; ++i) { exp_list->children[i] = addTypeConversion( - std::make_unique(ast->range, (*block.safeGetByPosition(i).column)[0]), + std::make_unique((*block.safeGetByPosition(i).column)[0]), block.safeGetByPosition(i).type->getName()); } } @@ -1375,7 +1374,7 @@ void ExpressionAnalyzer::optimizeGroupBy() } select_query->group_expression_list = std::make_shared(); - select_query->group_expression_list->children.emplace_back(std::make_shared(StringRange(), UInt64(unused_column))); + select_query->group_expression_list->children.emplace_back(std::make_shared(UInt64(unused_column))); } } diff --git a/dbms/src/Interpreters/InJoinSubqueriesPreprocessor.cpp b/dbms/src/Interpreters/InJoinSubqueriesPreprocessor.cpp index 363db236759..cc89def49ee 100644 --- a/dbms/src/Interpreters/InJoinSubqueriesPreprocessor.cpp +++ b/dbms/src/Interpreters/InJoinSubqueriesPreprocessor.cpp @@ -102,20 +102,18 @@ StoragePtr tryGetTable(const ASTPtr & database_and_table, const Context & contex void replaceDatabaseAndTable(ASTPtr & database_and_table, const String & database_name, const String & table_name) { - ASTPtr table = std::make_shared(StringRange(), table_name, ASTIdentifier::Table); + ASTPtr table = std::make_shared(table_name, ASTIdentifier::Table); if (!database_name.empty()) { - ASTPtr database = std::make_shared(StringRange(), database_name, ASTIdentifier::Database); + ASTPtr database = std::make_shared(database_name, ASTIdentifier::Database); - database_and_table = std::make_shared( - StringRange(), database_name + "." + table_name, ASTIdentifier::Table); + database_and_table = std::make_shared(database_name + "." + table_name, ASTIdentifier::Table); database_and_table->children = {database, table}; } else { - database_and_table = std::make_shared( - StringRange(), table_name, ASTIdentifier::Table); + database_and_table = std::make_shared(table_name, ASTIdentifier::Table); } } diff --git a/dbms/src/Interpreters/InterpreterAlterQuery.cpp b/dbms/src/Interpreters/InterpreterAlterQuery.cpp index 76fef51f98f..f990fd8570f 100644 --- a/dbms/src/Interpreters/InterpreterAlterQuery.cpp +++ b/dbms/src/Interpreters/InterpreterAlterQuery.cpp @@ -106,9 +106,7 @@ void InterpreterAlterQuery::parseAlter( command.column_name = ast_col_decl.name; if (ast_col_decl.type) { - StringRange type_range = ast_col_decl.type->range; - String type_string(type_range.first, type_range.second - type_range.first); - command.data_type = data_type_factory.get(type_string); + command.data_type = data_type_factory.get(ast_col_decl.type); } if (ast_col_decl.default_expression) { @@ -154,9 +152,7 @@ void InterpreterAlterQuery::parseAlter( command.column_name = ast_col_decl.name; if (ast_col_decl.type) { - StringRange type_range = ast_col_decl.type->range; - String type_string(type_range.first, type_range.second - type_range.first); - command.data_type = data_type_factory.get(type_string); + command.data_type = data_type_factory.get(ast_col_decl.type); } if (ast_col_decl.default_expression) diff --git a/dbms/src/Interpreters/InterpreterCreateQuery.cpp b/dbms/src/Interpreters/InterpreterCreateQuery.cpp index 17262f3cc56..0444b26671b 100644 --- a/dbms/src/Interpreters/InterpreterCreateQuery.cpp +++ b/dbms/src/Interpreters/InterpreterCreateQuery.cpp @@ -199,8 +199,8 @@ static ColumnsAndDefaults parseColumns(const ASTExpressionList & column_list_ast const auto data_type_ptr = columns.back().type.get(); default_expr_list->children.emplace_back(setAlias( - makeASTFunction("CAST", std::make_shared(StringRange(), tmp_column_name), - std::make_shared(StringRange(), Field(data_type_ptr->getName()))), final_column_name)); + makeASTFunction("CAST", std::make_shared(tmp_column_name), + std::make_shared(Field(data_type_ptr->getName()))), final_column_name)); default_expr_list->children.emplace_back(setAlias(col_decl.default_expression->clone(), tmp_column_name)); } else @@ -233,7 +233,7 @@ static ColumnsAndDefaults parseColumns(const ASTExpressionList & column_list_ast if (!explicit_type->equals(*deduced_type)) { col_decl_ptr->default_expression = makeASTFunction("CAST", col_decl_ptr->default_expression, - std::make_shared(StringRange(), explicit_type->getName())); + std::make_shared(explicit_type->getName())); col_decl_ptr->children.clear(); col_decl_ptr->children.push_back(col_decl_ptr->type); @@ -293,7 +293,7 @@ ASTPtr InterpreterCreateQuery::formatColumns(const NamesAndTypesList & columns) ParserIdentifierWithOptionalParameters storage_p; column_declaration->type = parseQuery(storage_p, pos, end, "data type"); - column_declaration->type->query_string = type_name; + column_declaration->type->owned_string = type_name; columns_list->children.emplace_back(column_declaration); } @@ -321,7 +321,7 @@ ASTPtr InterpreterCreateQuery::formatColumns( ParserIdentifierWithOptionalParameters storage_p; column_declaration->type = parseQuery(storage_p, pos, end, "data type"); - column_declaration->type->query_string = type_name; + column_declaration->type->owned_string = type_name; const auto it = column_defaults.find(column.name); if (it != std::end(column_defaults)) diff --git a/dbms/src/Interpreters/InterpreterSelectQuery.cpp b/dbms/src/Interpreters/InterpreterSelectQuery.cpp index 3002b73297a..56996c1eb5e 100644 --- a/dbms/src/Interpreters/InterpreterSelectQuery.cpp +++ b/dbms/src/Interpreters/InterpreterSelectQuery.cpp @@ -696,7 +696,7 @@ QueryProcessingStage::Enum InterpreterSelectQuery::executeFetchColumns(Pipeline if (default_it != std::end(storage->column_defaults) && default_it->second.type == ColumnDefaultType::Alias) required_columns_expr_list->children.emplace_back(setAlias(default_it->second.expression->clone(), column)); else - required_columns_expr_list->children.emplace_back(std::make_shared(StringRange(), column)); + required_columns_expr_list->children.emplace_back(std::make_shared(column)); } alias_actions = ExpressionAnalyzer{required_columns_expr_list, context, storage, source_header.getNamesAndTypesList()}.getActions(true); diff --git a/dbms/src/Interpreters/evaluateConstantExpression.cpp b/dbms/src/Interpreters/evaluateConstantExpression.cpp index 964aae94619..497df93f9bc 100644 --- a/dbms/src/Interpreters/evaluateConstantExpression.cpp +++ b/dbms/src/Interpreters/evaluateConstantExpression.cpp @@ -55,15 +55,14 @@ ASTPtr evaluateConstantExpressionAsLiteral(const ASTPtr & node, const Context & if (typeid_cast(node.get())) return node; - return std::make_shared(node->range, - evaluateConstantExpression(node, context).first); + return std::make_shared(evaluateConstantExpression(node, context).first); } ASTPtr evaluateConstantExpressionOrIdentifierAsLiteral(const ASTPtr & node, const Context & context) { if (auto id = typeid_cast(node.get())) - return std::make_shared(node->range, Field(id->name)); + return std::make_shared(Field(id->name)); return evaluateConstantExpressionAsLiteral(node, context); } diff --git a/dbms/src/Parsers/ASTAlterQuery.cpp b/dbms/src/Parsers/ASTAlterQuery.cpp index d9ed5d83fc2..6b439e83dda 100644 --- a/dbms/src/Parsers/ASTAlterQuery.cpp +++ b/dbms/src/Parsers/ASTAlterQuery.cpp @@ -33,10 +33,6 @@ void ASTAlterQuery::addParameters(const Parameters & params) children.push_back(params.primary_key); } -ASTAlterQuery::ASTAlterQuery(StringRange range_) : ASTQueryWithOutput(range_) -{ -} - /** Get the text that identifies this element. */ String ASTAlterQuery::getID() const { diff --git a/dbms/src/Parsers/ASTAlterQuery.h b/dbms/src/Parsers/ASTAlterQuery.h index 5b5e543d64d..dc1c4dde849 100644 --- a/dbms/src/Parsers/ASTAlterQuery.h +++ b/dbms/src/Parsers/ASTAlterQuery.h @@ -87,8 +87,6 @@ public: void addParameters(const Parameters & params); - explicit ASTAlterQuery(StringRange range_ = StringRange()); - /** Get the text that identifies this element. */ String getID() const override; diff --git a/dbms/src/Parsers/ASTAsterisk.h b/dbms/src/Parsers/ASTAsterisk.h index a52885f63cf..3861c992c75 100644 --- a/dbms/src/Parsers/ASTAsterisk.h +++ b/dbms/src/Parsers/ASTAsterisk.h @@ -9,8 +9,6 @@ namespace DB class ASTAsterisk : public IAST { public: - ASTAsterisk() = default; - ASTAsterisk(StringRange range_) : IAST(range_) {} String getID() const override { return "Asterisk"; } ASTPtr clone() const override { return std::make_shared(*this); } String getColumnName() const override { return "*"; } diff --git a/dbms/src/Parsers/ASTCheckQuery.h b/dbms/src/Parsers/ASTCheckQuery.h index 01e9c34b616..74f6249a732 100644 --- a/dbms/src/Parsers/ASTCheckQuery.h +++ b/dbms/src/Parsers/ASTCheckQuery.h @@ -7,8 +7,6 @@ namespace DB struct ASTCheckQuery : public ASTQueryWithOutput { - ASTCheckQuery(StringRange range_ = StringRange()) : ASTQueryWithOutput(range_) {}; - /** Get the text that identifies this element. */ String getID() const override { return ("CheckQuery_" + database + "_" + table); }; diff --git a/dbms/src/Parsers/ASTColumnDeclaration.h b/dbms/src/Parsers/ASTColumnDeclaration.h index 0cf49be00ec..57a1f7695d7 100644 --- a/dbms/src/Parsers/ASTColumnDeclaration.h +++ b/dbms/src/Parsers/ASTColumnDeclaration.h @@ -16,9 +16,6 @@ public: String default_specifier; ASTPtr default_expression; - ASTColumnDeclaration() = default; - ASTColumnDeclaration(const StringRange range) : IAST{range} {} - String getID() const override { return "ColumnDeclaration_" + name; } ASTPtr clone() const override diff --git a/dbms/src/Parsers/ASTCreateQuery.h b/dbms/src/Parsers/ASTCreateQuery.h index 5f1c8c66891..e1180de4af0 100644 --- a/dbms/src/Parsers/ASTCreateQuery.h +++ b/dbms/src/Parsers/ASTCreateQuery.h @@ -20,8 +20,6 @@ public: IAST * sample_by = nullptr; ASTSetQuery * settings = nullptr; - ASTStorage() = default; - ASTStorage(StringRange range_) : IAST(range_) {} String getID() const override { return "Storage definition"; } ASTPtr clone() const override @@ -95,9 +93,6 @@ public: String as_table; ASTSelectQuery * select = nullptr; - ASTCreateQuery() = default; - ASTCreateQuery(const StringRange range_) : ASTQueryWithOutput(range_) {} - /** Get the text that identifies this element. */ String getID() const override { return (attach ? "AttachQuery_" : "CreateQuery_") + database + "_" + table; }; diff --git a/dbms/src/Parsers/ASTDropQuery.h b/dbms/src/Parsers/ASTDropQuery.h index 3735a58ab66..41e9b255bf3 100644 --- a/dbms/src/Parsers/ASTDropQuery.h +++ b/dbms/src/Parsers/ASTDropQuery.h @@ -19,9 +19,6 @@ public: String database; String table; - ASTDropQuery() = default; - explicit ASTDropQuery(const StringRange range_) : ASTQueryWithOutput(range_) {} - /** Get the text that identifies this element. */ String getID() const override { return (detach ? "DetachQuery_" : "DropQuery_") + database + "_" + table; }; diff --git a/dbms/src/Parsers/ASTEnumElement.h b/dbms/src/Parsers/ASTEnumElement.h index 1898c5d9172..10b4e1e7482 100644 --- a/dbms/src/Parsers/ASTEnumElement.h +++ b/dbms/src/Parsers/ASTEnumElement.h @@ -14,14 +14,14 @@ public: String name; Field value; - ASTEnumElement(const StringRange range, const String & name, const Field & value) - : IAST{range}, name{name}, value {value} {} + ASTEnumElement(const String & name, const Field & value) + : name{name}, value {value} {} String getID() const override { return "EnumElement"; } ASTPtr clone() const override { - return std::make_shared(StringRange(), name, value); + return std::make_shared(name, value); } protected: diff --git a/dbms/src/Parsers/ASTExpressionList.h b/dbms/src/Parsers/ASTExpressionList.h index 4d49df84ad6..cfe9cb3b714 100644 --- a/dbms/src/Parsers/ASTExpressionList.h +++ b/dbms/src/Parsers/ASTExpressionList.h @@ -11,9 +11,6 @@ namespace DB class ASTExpressionList : public IAST { public: - ASTExpressionList() = default; - ASTExpressionList(const StringRange range_) : IAST(range_) {} - String getID() const override { return "ExpressionList"; } ASTPtr clone() const override; diff --git a/dbms/src/Parsers/ASTFunction.h b/dbms/src/Parsers/ASTFunction.h index 462dc439329..9e78de369a1 100644 --- a/dbms/src/Parsers/ASTFunction.h +++ b/dbms/src/Parsers/ASTFunction.h @@ -18,9 +18,6 @@ public: ASTPtr parameters; public: - ASTFunction() = default; - ASTFunction(const StringRange range_) : ASTWithAlias(range_) {} - /** Get text identifying the AST node. */ String getID() const override; @@ -36,7 +33,6 @@ template ASTPtr makeASTFunction(const String & name, Args &&... args) { const auto function = std::make_shared(); - ASTPtr result{function}; function->name = name; function->arguments = std::make_shared(); @@ -44,24 +40,7 @@ ASTPtr makeASTFunction(const String & name, Args &&... args) function->arguments->children = { std::forward(args)... }; - return result; -} - - -template -ASTPtr makeASTFunction(const String & name, const StringRange & function_range, - const StringRange & arguments_range, Args &&... args) -{ - const auto function = std::make_shared(function_range); - ASTPtr result{function}; - - function->name = name; - function->arguments = std::make_shared(arguments_range); - function->children.push_back(function->arguments); - - function->arguments->children = { std::forward(args)... }; - - return result; + return function; } } diff --git a/dbms/src/Parsers/ASTIdentifier.h b/dbms/src/Parsers/ASTIdentifier.h index 1c424f8e50e..017e33af500 100644 --- a/dbms/src/Parsers/ASTIdentifier.h +++ b/dbms/src/Parsers/ASTIdentifier.h @@ -25,9 +25,8 @@ public: /// what this identifier identifies Kind kind; - ASTIdentifier() = default; - ASTIdentifier(const StringRange range_, const String & name_, const Kind kind_ = Column) - : ASTWithAlias(range_), name(name_), kind(kind_) {} + ASTIdentifier(const String & name_, const Kind kind_ = Column) + : name(name_), kind(kind_) {} /** Get the text that identifies this element. */ String getID() const override { return "Identifier_" + name; } diff --git a/dbms/src/Parsers/ASTInsertQuery.h b/dbms/src/Parsers/ASTInsertQuery.h index bbd730ae50c..12e3de2ef42 100644 --- a/dbms/src/Parsers/ASTInsertQuery.h +++ b/dbms/src/Parsers/ASTInsertQuery.h @@ -26,9 +26,6 @@ public: const char * data = nullptr; const char * end = nullptr; - ASTInsertQuery() = default; - explicit ASTInsertQuery(const StringRange range_) : IAST(range_) {} - /** Get the text that identifies this element. */ String getID() const override { return "InsertQuery_" + database + "_" + table; }; diff --git a/dbms/src/Parsers/ASTKillQueryQuery.h b/dbms/src/Parsers/ASTKillQueryQuery.h index e28c97e4baf..23ef73fec3d 100644 --- a/dbms/src/Parsers/ASTKillQueryQuery.h +++ b/dbms/src/Parsers/ASTKillQueryQuery.h @@ -11,10 +11,6 @@ public: bool sync = false; // SYNC or ASYNC mode bool test = false; // does it TEST mode? (doesn't cancel queries just checks and shows them) - ASTKillQueryQuery() = default; - - ASTKillQueryQuery(const StringRange range_) : ASTQueryWithOutput(range_) {} - ASTPtr clone() const override { return std::make_shared(*this); } String getID() const override; diff --git a/dbms/src/Parsers/ASTLiteral.h b/dbms/src/Parsers/ASTLiteral.h index e31ae7f49da..36707a7e950 100644 --- a/dbms/src/Parsers/ASTLiteral.h +++ b/dbms/src/Parsers/ASTLiteral.h @@ -15,8 +15,7 @@ class ASTLiteral : public ASTWithAlias public: Field value; - ASTLiteral() = default; - ASTLiteral(const StringRange range_, const Field & value_) : ASTWithAlias(range_), value(value_) {} + ASTLiteral(const Field & value_) : value(value_) {} /** Get the text that identifies this element. */ String getID() const override { return "Literal_" + applyVisitor(FieldVisitorDump(), value); } diff --git a/dbms/src/Parsers/ASTNameTypePair.h b/dbms/src/Parsers/ASTNameTypePair.h index ae0574f1dac..9dad01df2f5 100644 --- a/dbms/src/Parsers/ASTNameTypePair.h +++ b/dbms/src/Parsers/ASTNameTypePair.h @@ -16,9 +16,6 @@ public: /// type ASTPtr type; - ASTNameTypePair() = default; - ASTNameTypePair(const StringRange range_) : IAST(range_) {} - /** Get the text that identifies this element. */ String getID() const override { return "NameTypePair_" + name; } diff --git a/dbms/src/Parsers/ASTOptimizeQuery.h b/dbms/src/Parsers/ASTOptimizeQuery.h index 3caae258b41..1a4bd260ed3 100644 --- a/dbms/src/Parsers/ASTOptimizeQuery.h +++ b/dbms/src/Parsers/ASTOptimizeQuery.h @@ -22,9 +22,6 @@ public: /// Do deduplicate (default: false) bool deduplicate; - ASTOptimizeQuery() = default; - ASTOptimizeQuery(const StringRange range_) : IAST(range_) {} - /** Get the text that identifies this element. */ String getID() const override { return "OptimizeQuery_" + database + "_" + table + (final ? "_final" : "") + (deduplicate ? "_deduplicate" : ""); }; diff --git a/dbms/src/Parsers/ASTOrderByElement.h b/dbms/src/Parsers/ASTOrderByElement.h index bd3d2c5eb06..19d0d723a7c 100644 --- a/dbms/src/Parsers/ASTOrderByElement.h +++ b/dbms/src/Parsers/ASTOrderByElement.h @@ -19,11 +19,12 @@ public: /** Collation for locale-specific string comparison. If empty, then sorting done by bytes. */ ASTPtr collation; - ASTOrderByElement() = default; - ASTOrderByElement(const StringRange range_, - const int direction_, const int nulls_direction_, const bool nulls_direction_was_explicitly_specified_, + ASTOrderByElement( + const int direction_, + const int nulls_direction_, + const bool nulls_direction_was_explicitly_specified_, ASTPtr & collation_) - : IAST(range_), + : direction(direction_), nulls_direction(nulls_direction_), nulls_direction_was_explicitly_specified(nulls_direction_was_explicitly_specified_), collation(collation_) {} diff --git a/dbms/src/Parsers/ASTPartition.h b/dbms/src/Parsers/ASTPartition.h index 9f78d56fca1..b1ed866284a 100644 --- a/dbms/src/Parsers/ASTPartition.h +++ b/dbms/src/Parsers/ASTPartition.h @@ -17,8 +17,6 @@ public: String id; - ASTPartition() = default; - ASTPartition(StringRange range_) : IAST(range_) {} String getID() const override; ASTPtr clone() const override; diff --git a/dbms/src/Parsers/ASTQualifiedAsterisk.h b/dbms/src/Parsers/ASTQualifiedAsterisk.h index 52d9e8b39c6..5baf24686fc 100644 --- a/dbms/src/Parsers/ASTQualifiedAsterisk.h +++ b/dbms/src/Parsers/ASTQualifiedAsterisk.h @@ -12,8 +12,6 @@ namespace DB class ASTQualifiedAsterisk : public IAST { public: - ASTQualifiedAsterisk() = default; - ASTQualifiedAsterisk(StringRange range_) : IAST(range_) {} String getID() const override { return "QualifiedAsterisk"; } ASTPtr clone() const override { return std::make_shared(*this); } String getColumnName() const override; diff --git a/dbms/src/Parsers/ASTQueryWithOutput.h b/dbms/src/Parsers/ASTQueryWithOutput.h index 40ac02380e5..eea314ecbdf 100644 --- a/dbms/src/Parsers/ASTQueryWithOutput.h +++ b/dbms/src/Parsers/ASTQueryWithOutput.h @@ -14,9 +14,6 @@ public: ASTPtr out_file; ASTPtr format; - ASTQueryWithOutput() = default; - explicit ASTQueryWithOutput(const StringRange range_) : IAST(range_) {} - void formatImpl(const FormatSettings & s, FormatState & state, FormatStateStacked frame) const final; /// Remove 'FORMAT and INTO OUTFILE ' if exists @@ -31,17 +28,15 @@ protected: }; -template +template class ASTQueryWithOutputImpl : public ASTQueryWithOutput { public: - explicit ASTQueryWithOutputImpl() = default; - explicit ASTQueryWithOutputImpl(StringRange range_) : ASTQueryWithOutput(range_) {} - String getID() const override { return AstIDAndQueryNames::ID; }; + String getID() const override { return ASTIDAndQueryNames::ID; }; ASTPtr clone() const override { - auto res = std::make_shared>(*this); + auto res = std::make_shared>(*this); res->children.clear(); cloneOutputOptions(*res); return res; @@ -51,7 +46,7 @@ protected: void formatQueryImpl(const FormatSettings & settings, FormatState &, FormatStateStacked) const override { settings.ostr << (settings.hilite ? hilite_keyword : "") - << AstIDAndQueryNames::Query << (settings.hilite ? hilite_none : ""); + << ASTIDAndQueryNames::Query << (settings.hilite ? hilite_none : ""); } }; diff --git a/dbms/src/Parsers/ASTQueryWithTableAndOutput.h b/dbms/src/Parsers/ASTQueryWithTableAndOutput.h index abcb7fa26e5..952ea23fd61 100644 --- a/dbms/src/Parsers/ASTQueryWithTableAndOutput.h +++ b/dbms/src/Parsers/ASTQueryWithTableAndOutput.h @@ -16,9 +16,6 @@ public: String database; String table; - ASTQueryWithTableAndOutput() = default; - explicit ASTQueryWithTableAndOutput(const StringRange range_) : ASTQueryWithOutput(range_) {} - protected: void formatHelper(const FormatSettings & settings, const char * name) const { @@ -32,10 +29,6 @@ template class ASTQueryWithTableAndOutputImpl : public ASTQueryWithTableAndOutput { public: - ASTQueryWithTableAndOutputImpl() = default; - - explicit ASTQueryWithTableAndOutputImpl(const StringRange range_) : ASTQueryWithTableAndOutput(range_) {} - String getID() const override { return AstIDAndQueryNames::ID + ("_" + database) + "_" + table; }; ASTPtr clone() const override diff --git a/dbms/src/Parsers/ASTRenameQuery.h b/dbms/src/Parsers/ASTRenameQuery.h index 1a2eda8b029..3da772a5552 100644 --- a/dbms/src/Parsers/ASTRenameQuery.h +++ b/dbms/src/Parsers/ASTRenameQuery.h @@ -28,9 +28,6 @@ public: using Elements = std::vector; Elements elements; - ASTRenameQuery() = default; - explicit ASTRenameQuery(const StringRange range_) : ASTQueryWithOutput(range_) {} - /** Get the text that identifies this element. */ String getID() const override { return "Rename"; }; diff --git a/dbms/src/Parsers/ASTSampleRatio.h b/dbms/src/Parsers/ASTSampleRatio.h index 84915cab6cb..ca91d0b6cbb 100644 --- a/dbms/src/Parsers/ASTSampleRatio.h +++ b/dbms/src/Parsers/ASTSampleRatio.h @@ -26,9 +26,7 @@ public: Rational ratio; - ASTSampleRatio() = default; - ASTSampleRatio(const StringRange range_) : IAST(range_) {} - ASTSampleRatio(const StringRange range_, Rational & ratio_) : IAST(range_), ratio(ratio_) {} + ASTSampleRatio(Rational & ratio_) : ratio(ratio_) {} String getID() const override { return "SampleRatio_" + toString(ratio); } diff --git a/dbms/src/Parsers/ASTSelectQuery.cpp b/dbms/src/Parsers/ASTSelectQuery.cpp index aec8d6345d9..5c13e730b66 100644 --- a/dbms/src/Parsers/ASTSelectQuery.cpp +++ b/dbms/src/Parsers/ASTSelectQuery.cpp @@ -21,10 +21,6 @@ namespace ErrorCodes } -ASTSelectQuery::ASTSelectQuery(const StringRange range_) : ASTQueryWithOutput(range_) -{ -} - bool ASTSelectQuery::hasArrayJoin(const ASTPtr & ast) { if (const ASTFunction * function = typeid_cast(&*ast)) @@ -127,7 +123,7 @@ void ASTSelectQuery::rewriteSelectExpressionList(const Names & required_column_n if (!other_required_columns_in_select.count(name) && !columns_with_array_join.count(name)) { if (asterisk.first) - new_children.push_back({ std::make_shared(asterisk.first->range, name), asterisk.second }); + new_children.push_back({ std::make_shared(name), asterisk.second }); else throw Exception("SELECT query doesn't have required column: " + backQuoteIfNeed(name), ErrorCodes::THERE_IS_NO_COLUMN); } @@ -530,11 +526,11 @@ void ASTSelectQuery::setDatabaseIfNeeded(const String & database_name) if (table_expression->database_and_table_name->children.empty()) { - ASTPtr database = std::make_shared(StringRange(), database_name, ASTIdentifier::Database); + ASTPtr database = std::make_shared(database_name, ASTIdentifier::Database); ASTPtr table = table_expression->database_and_table_name; const String & old_name = static_cast(*table_expression->database_and_table_name).name; - table_expression->database_and_table_name = std::make_shared(StringRange(), database_name + "." + old_name, ASTIdentifier::Table); + table_expression->database_and_table_name = std::make_shared(database_name + "." + old_name, ASTIdentifier::Table); table_expression->database_and_table_name->children = {database, table}; } else if (table_expression->database_and_table_name->children.size() != 2) @@ -561,20 +557,18 @@ void ASTSelectQuery::replaceDatabaseAndTable(const String & database_name, const table_expression = table_expr.get(); } - ASTPtr table = std::make_shared(StringRange(), table_name, ASTIdentifier::Table); + ASTPtr table = std::make_shared(table_name, ASTIdentifier::Table); if (!database_name.empty()) { - ASTPtr database = std::make_shared(StringRange(), database_name, ASTIdentifier::Database); + ASTPtr database = std::make_shared(database_name, ASTIdentifier::Database); - table_expression->database_and_table_name = std::make_shared( - StringRange(), database_name + "." + table_name, ASTIdentifier::Table); + table_expression->database_and_table_name = std::make_shared(database_name + "." + table_name, ASTIdentifier::Table); table_expression->database_and_table_name->children = {database, table}; } else { - table_expression->database_and_table_name = std::make_shared( - StringRange(), table_name, ASTIdentifier::Table); + table_expression->database_and_table_name = std::make_shared(table_name, ASTIdentifier::Table); } } diff --git a/dbms/src/Parsers/ASTSelectQuery.h b/dbms/src/Parsers/ASTSelectQuery.h index 5f4898d33d9..a524a79bd79 100644 --- a/dbms/src/Parsers/ASTSelectQuery.h +++ b/dbms/src/Parsers/ASTSelectQuery.h @@ -16,9 +16,6 @@ struct ASTTablesInSelectQueryElement; class ASTSelectQuery : public ASTQueryWithOutput { public: - ASTSelectQuery() = default; - ASTSelectQuery(const StringRange range_); - /** Get the text that identifies this element. */ String getID() const override { return "SelectQuery"; }; diff --git a/dbms/src/Parsers/ASTSetQuery.h b/dbms/src/Parsers/ASTSetQuery.h index 08b617db646..3a41ed0d80c 100644 --- a/dbms/src/Parsers/ASTSetQuery.h +++ b/dbms/src/Parsers/ASTSetQuery.h @@ -25,9 +25,6 @@ public: using Changes = std::vector; Changes changes; - ASTSetQuery() = default; - explicit ASTSetQuery(const StringRange range_) : IAST(range_) {} - /** Get the text that identifies this element. */ String getID() const override { return "Set"; }; diff --git a/dbms/src/Parsers/ASTShowTablesQuery.h b/dbms/src/Parsers/ASTShowTablesQuery.h index 176f9d69697..09ee0475847 100644 --- a/dbms/src/Parsers/ASTShowTablesQuery.h +++ b/dbms/src/Parsers/ASTShowTablesQuery.h @@ -20,9 +20,6 @@ public: String like; bool not_like{false}; - ASTShowTablesQuery() = default; - ASTShowTablesQuery(const StringRange range_) : ASTQueryWithOutput(range_) {} - /** Get the text that identifies this element. */ String getID() const override { return "ShowTables"; }; diff --git a/dbms/src/Parsers/ASTSubquery.h b/dbms/src/Parsers/ASTSubquery.h index 2ec2b4469fa..1b9ba97ac88 100644 --- a/dbms/src/Parsers/ASTSubquery.h +++ b/dbms/src/Parsers/ASTSubquery.h @@ -12,9 +12,6 @@ namespace DB class ASTSubquery : public ASTWithAlias { public: - ASTSubquery() = default; - ASTSubquery(const StringRange range_) : ASTWithAlias(range_) {} - /** Get the text that identifies this element. */ String getID() const override { return "Subquery"; } @@ -44,6 +41,7 @@ protected: children[0]->formatImpl(settings, state, frame_nested); settings.ostr << nl_or_nothing << indent_str << ")"; } + String getColumnNameImpl() const override; }; diff --git a/dbms/src/Parsers/ASTSystemQuery.h b/dbms/src/Parsers/ASTSystemQuery.h index 8f9a4bf2208..1821b73bc12 100644 --- a/dbms/src/Parsers/ASTSystemQuery.h +++ b/dbms/src/Parsers/ASTSystemQuery.h @@ -39,9 +39,6 @@ public: //String target_replica_database; //String target_replica_table; - ASTSystemQuery() = default; - explicit ASTSystemQuery(const StringRange range) : IAST(range) {} - String getID() const override { return "SYSTEM query"; }; ASTPtr clone() const override { return std::make_shared(*this); } diff --git a/dbms/src/Parsers/ASTUseQuery.h b/dbms/src/Parsers/ASTUseQuery.h index dd23b24f41a..71108b200d1 100644 --- a/dbms/src/Parsers/ASTUseQuery.h +++ b/dbms/src/Parsers/ASTUseQuery.h @@ -14,9 +14,6 @@ class ASTUseQuery : public IAST public: String database; - ASTUseQuery() = default; - ASTUseQuery(const StringRange range_) : IAST(range_) {} - /** Get the text that identifies this element. */ String getID() const override { return "UseQuery_" + database; }; diff --git a/dbms/src/Parsers/ExpressionElementParsers.cpp b/dbms/src/Parsers/ExpressionElementParsers.cpp index 5e26f42593b..9463b737d82 100644 --- a/dbms/src/Parsers/ExpressionElementParsers.cpp +++ b/dbms/src/Parsers/ExpressionElementParsers.cpp @@ -36,7 +36,6 @@ namespace ErrorCodes bool ParserArray::parseImpl(Pos & pos, ASTPtr & node, Expected & expected) { - Pos begin = pos; ASTPtr contents_node; ParserExpressionList contents(false); @@ -51,7 +50,7 @@ bool ParserArray::parseImpl(Pos & pos, ASTPtr & node, Expected & expected) return false; ++pos; - auto function_node = std::make_shared(StringRange(begin, pos)); + auto function_node = std::make_shared(); function_node->name = "array"; function_node->arguments = contents_node; function_node->children.push_back(contents_node); @@ -63,7 +62,6 @@ bool ParserArray::parseImpl(Pos & pos, ASTPtr & node, Expected & expected) bool ParserParenthesisExpression::parseImpl(Pos & pos, ASTPtr & node, Expected & expected) { - Pos begin = pos; ASTPtr contents_node; ParserExpressionList contents(false); @@ -93,7 +91,7 @@ bool ParserParenthesisExpression::parseImpl(Pos & pos, ASTPtr & node, Expected & } else { - auto function_node = std::make_shared(StringRange(begin, pos)); + auto function_node = std::make_shared(); function_node->name = "tuple"; function_node->arguments = contents_node; function_node->children.push_back(contents_node); @@ -106,7 +104,6 @@ bool ParserParenthesisExpression::parseImpl(Pos & pos, ASTPtr & node, Expected & bool ParserSubquery::parseImpl(Pos & pos, ASTPtr & node, Expected & expected) { - Pos begin = pos; ASTPtr select_node; ParserSelectQuery select; @@ -121,7 +118,7 @@ bool ParserSubquery::parseImpl(Pos & pos, ASTPtr & node, Expected & expected) return false; ++pos; - node = std::make_shared(StringRange(begin, pos)); + node = std::make_shared(); typeid_cast(*node).children.push_back(select_node); return true; } @@ -129,8 +126,6 @@ bool ParserSubquery::parseImpl(Pos & pos, ASTPtr & node, Expected & expected) bool ParserIdentifier::parseImpl(Pos & pos, ASTPtr & node, Expected &) { - Pos begin = pos; - /// Identifier in backquotes or in double quotes if (pos->type == TokenType::QuotedIdentifier) { @@ -145,14 +140,14 @@ bool ParserIdentifier::parseImpl(Pos & pos, ASTPtr & node, Expected &) if (s.empty()) /// Identifiers "empty string" are not allowed. return false; + node = std::make_shared(s); ++pos; - node = std::make_shared(StringRange(begin), s); return true; } else if (pos->type == TokenType::BareWord) { + node = std::make_shared(String(pos->begin, pos->end)); ++pos; - node = std::make_shared(StringRange(begin), String(begin->begin, begin->end)); return true; } @@ -162,8 +157,6 @@ bool ParserIdentifier::parseImpl(Pos & pos, ASTPtr & node, Expected &) bool ParserCompoundIdentifier::parseImpl(Pos & pos, ASTPtr & node, Expected & expected) { - Pos begin = pos; - ASTPtr id_list; if (!ParserList(std::make_unique(), std::make_unique(TokenType::Dot), false) .parse(pos, id_list, expected)) @@ -178,7 +171,7 @@ bool ParserCompoundIdentifier::parseImpl(Pos & pos, ASTPtr & node, Expected & ex name += static_cast(*child.get()).name; } - node = std::make_shared(StringRange(begin, pos), name); + node = std::make_shared(name); /// In `children`, remember the identifiers-components, if there are more than one. if (list.children.size() > 1) @@ -190,8 +183,6 @@ bool ParserCompoundIdentifier::parseImpl(Pos & pos, ASTPtr & node, Expected & ex bool ParserFunction::parseImpl(Pos & pos, ASTPtr & node, Expected & expected) { - Pos begin = pos; - ParserIdentifier id_parser; ParserKeyword distinct("DISTINCT"); ParserExpressionList contents(false); @@ -267,7 +258,7 @@ bool ParserFunction::parseImpl(Pos & pos, ASTPtr & node, Expected & expected) ++pos; } - auto function_node = std::make_shared(StringRange(begin, pos)); + auto function_node = std::make_shared(); function_node->name = typeid_cast(*identifier).name; /// func(DISTINCT ...) is equivalent to funcDistinct(...) @@ -335,10 +326,10 @@ bool ParserCastExpression::parseImpl(Pos & pos, ASTPtr & node, Expected & expect return false; } - expr_list_args = std::make_shared(StringRange{contents_begin, pos}); + expr_list_args = std::make_shared(); first_argument->setAlias({}); expr_list_args->children.push_back(first_argument); - expr_list_args->children.emplace_back(std::make_shared(StringRange(), type)); + expr_list_args->children.emplace_back(std::make_shared(type)); } else { @@ -363,7 +354,7 @@ bool ParserCastExpression::parseImpl(Pos & pos, ASTPtr & node, Expected & expect return false; } - expr_list_args = std::make_shared(StringRange{contents_begin, pos}); + expr_list_args = std::make_shared(); expr_list_args->children.push_back(first_argument); expr_list_args->children.push_back(type_as_literal); } @@ -372,7 +363,7 @@ bool ParserCastExpression::parseImpl(Pos & pos, ASTPtr & node, Expected & expect return false; ++pos; - const auto function_node = std::make_shared(StringRange(begin, pos)); + const auto function_node = std::make_shared(); ASTPtr node_holder{function_node}; function_node->name = name; @@ -386,11 +377,10 @@ bool ParserCastExpression::parseImpl(Pos & pos, ASTPtr & node, Expected & expect bool ParserNull::parseImpl(Pos & pos, ASTPtr & node, Expected & expected) { - Pos begin = pos; ParserKeyword nested_parser("NULL"); if (nested_parser.parse(pos, node, expected)) { - node = std::make_shared(StringRange(StringRange(begin, pos)), Null()); + node = std::make_shared(Null()); return true; } else @@ -412,7 +402,6 @@ bool ParserNumber::parseImpl(Pos & pos, ASTPtr & node, Expected & expected) Field res; - Pos begin = pos; if (!pos.isValid()) return false; @@ -464,7 +453,7 @@ bool ParserNumber::parseImpl(Pos & pos, ASTPtr & node, Expected & expected) } ++pos; - node = std::make_shared(StringRange(begin, pos), res); + node = std::make_shared(res); return true; } @@ -473,7 +462,6 @@ bool ParserUnsignedInteger::parseImpl(Pos & pos, ASTPtr & node, Expected & expec { Field res; - Pos begin = pos; if (!pos.isValid()) return false; @@ -487,7 +475,7 @@ bool ParserUnsignedInteger::parseImpl(Pos & pos, ASTPtr & node, Expected & expec res = x; ++pos; - node = std::make_shared(StringRange(begin, pos), res); + node = std::make_shared(res); return true; } @@ -497,8 +485,6 @@ bool ParserStringLiteral::parseImpl(Pos & pos, ASTPtr & node, Expected & expecte if (pos->type != TokenType::StringLiteral) return false; - Pos begin = pos; - String s; ReadBufferFromMemory in(pos->begin, pos->size()); @@ -519,7 +505,7 @@ bool ParserStringLiteral::parseImpl(Pos & pos, ASTPtr & node, Expected & expecte } ++pos; - node = std::make_shared(StringRange(begin, pos), s); + node = std::make_shared(s); return true; } @@ -529,7 +515,6 @@ bool ParserArrayOfLiterals::parseImpl(Pos & pos, ASTPtr & node, Expected & expec if (pos->type != TokenType::OpeningSquareBracket) return false; - Pos begin = pos; Array arr; ParserLiteral literal_p; @@ -543,7 +528,7 @@ bool ParserArrayOfLiterals::parseImpl(Pos & pos, ASTPtr & node, Expected & expec if (pos->type == TokenType::ClosingSquareBracket) { ++pos; - node = std::make_shared(StringRange(begin, pos), arr); + node = std::make_shared(arr); return true; } else if (pos->type == TokenType::Comma) @@ -655,11 +640,10 @@ template class ParserAliasImpl; bool ParserAsterisk::parseImpl(Pos & pos, ASTPtr & node, Expected &) { - Pos begin = pos; if (pos->type == TokenType::Asterisk) { ++pos; - node = std::make_shared(StringRange(begin, pos)); + node = std::make_shared(); return true; } return false; @@ -668,8 +652,6 @@ bool ParserAsterisk::parseImpl(Pos & pos, ASTPtr & node, Expected &) bool ParserQualifiedAsterisk::parseImpl(Pos & pos, ASTPtr & node, Expected & expected) { - Pos begin = pos; - if (!ParserCompoundIdentifier().parse(pos, node, expected)) return false; @@ -681,7 +663,7 @@ bool ParserQualifiedAsterisk::parseImpl(Pos & pos, ASTPtr & node, Expected & exp return false; ++pos; - auto res = std::make_shared(StringRange(begin, pos)); + auto res = std::make_shared(); res->children.push_back(node); node = std::move(res); return true; @@ -788,8 +770,6 @@ template class ParserWithOptionalAliasImpl; bool ParserOrderByElement::parseImpl(Pos & pos, ASTPtr & node, Expected & expected) { - Pos begin = pos; - ParserExpressionWithOptionalAlias elem_p(false); ParserKeyword ascending("ASCENDING"); ParserKeyword descending("DESCENDING"); @@ -834,7 +814,7 @@ bool ParserOrderByElement::parseImpl(Pos & pos, ASTPtr & node, Expected & expect return false; } - node = std::make_shared(StringRange(begin, pos), direction, nulls_direction, nulls_direction_was_explicitly_specified, locale_node); + node = std::make_shared(direction, nulls_direction, nulls_direction_was_explicitly_specified, locale_node); node->children.push_back(expr_elem); if (locale_node) node->children.push_back(locale_node); diff --git a/dbms/src/Parsers/ExpressionListParsers.cpp b/dbms/src/Parsers/ExpressionListParsers.cpp index 50f5ce81e51..5ac3d9f046d 100644 --- a/dbms/src/Parsers/ExpressionListParsers.cpp +++ b/dbms/src/Parsers/ExpressionListParsers.cpp @@ -206,7 +206,6 @@ bool ParserLeftAssociativeBinaryOperatorList::parseImpl(Pos & pos, ASTPtr & node bool ParserVariableArityOperatorList::parseImpl(Pos & pos, ASTPtr & node, Expected & expected) { - Pos begin = pos; ASTPtr arguments; if (!elem_parser->parse(pos, node, expected)) @@ -230,9 +229,6 @@ bool ParserVariableArityOperatorList::parseImpl(Pos & pos, ASTPtr & node, Expect arguments->children.push_back(elem); } - if (arguments) - arguments->range = node->range = StringRange(begin, pos); - return true; } @@ -575,8 +571,6 @@ bool ParserNullityChecking::parseImpl(Pos & pos, ASTPtr & node, Expected & expec if (!ParserComparisonExpression{}.parse(pos, node_comp, expected)) return false; - Pos begin = pos; - ParserKeyword s_is{"IS"}; ParserKeyword s_not{"NOT"}; ParserKeyword s_null{"NULL"}; @@ -593,7 +587,7 @@ bool ParserNullityChecking::parseImpl(Pos & pos, ASTPtr & node, Expected & expec auto args = std::make_shared(); args->children.push_back(node_comp); - auto function = std::make_shared(StringRange{begin, pos}); + auto function = std::make_shared(); function->name = is_not ? "isNotNull" : "isNull"; function->arguments = args; function->children.push_back(function->arguments); diff --git a/dbms/src/Parsers/IAST.h b/dbms/src/Parsers/IAST.h index 56971824548..9c4f33ebf49 100644 --- a/dbms/src/Parsers/IAST.h +++ b/dbms/src/Parsers/IAST.h @@ -40,13 +40,9 @@ public: ASTs children; StringRange range; - /** A string with a full query. - * This pointer does not allow it to be deleted while the range refers to it. - */ - StringPtr query_string; + /// This pointer does not allow it to be deleted while the range refers to it. + StringPtr owned_string; - IAST() = default; - IAST(const StringRange range_) : range(range_) {} virtual ~IAST() = default; /** Get the canonical name of the column if the element is a column */ diff --git a/dbms/src/Parsers/IParserBase.cpp b/dbms/src/Parsers/IParserBase.cpp index b7e44ace03d..c1a17805068 100644 --- a/dbms/src/Parsers/IParserBase.cpp +++ b/dbms/src/Parsers/IParserBase.cpp @@ -17,13 +17,13 @@ bool IParserBase::parse(Pos & pos, ASTPtr & node, Expected & expected) bool res = parseImpl(pos, node, expected); - /// TODO expected - if (!res) { node = nullptr; pos = begin; } + else + node->range = StringRange(begin, pos); return res; } diff --git a/dbms/src/Parsers/ParserAlterQuery.cpp b/dbms/src/Parsers/ParserAlterQuery.cpp index 2667c2bf247..dbd1805e7b1 100644 --- a/dbms/src/Parsers/ParserAlterQuery.cpp +++ b/dbms/src/Parsers/ParserAlterQuery.cpp @@ -12,8 +12,6 @@ namespace DB bool ParserAlterQuery::parseImpl(Pos & pos, ASTPtr & node, Expected & expected) { - Pos begin = pos; - ParserKeyword s_alter_table("ALTER TABLE"); ParserKeyword s_add_column("ADD COLUMN"); ParserKeyword s_drop_column("DROP COLUMN"); @@ -218,7 +216,6 @@ bool ParserAlterQuery::parseImpl(Pos & pos, ASTPtr & node, Expected & expected) } while (!parsing_finished); - query->range = StringRange(begin, pos); query->cluster = cluster_str; node = query; diff --git a/dbms/src/Parsers/ParserCase.cpp b/dbms/src/Parsers/ParserCase.cpp index 368ccc657ca..e932dfdb04f 100644 --- a/dbms/src/Parsers/ParserCase.cpp +++ b/dbms/src/Parsers/ParserCase.cpp @@ -10,8 +10,6 @@ namespace DB bool ParserCase::parseImpl(Pos & pos, ASTPtr & node, Expected & expected) { - Pos begin = pos; - ParserKeyword s_case{"CASE"}; ParserKeyword s_when{"WHEN"}; ParserKeyword s_then{"THEN"}; @@ -22,7 +20,6 @@ bool ParserCase::parseImpl(Pos & pos, ASTPtr & node, Expected & expected) if (!s_case.parse(pos, node, expected)) { /// Parse as a simple ASTFunction. - pos = begin; return ParserFunction{}.parse(pos, node, expected); } @@ -80,10 +77,10 @@ bool ParserCase::parseImpl(Pos & pos, ASTPtr & node, Expected & expected) if (!parse_branches()) return false; - auto function_args = std::make_shared(StringRange{begin, pos}); + auto function_args = std::make_shared(); function_args->children = std::move(args); - auto function = std::make_shared(StringRange{begin, pos}); + auto function = std::make_shared(); function->name = "caseWithExpression"; function->arguments = function_args; function->children.push_back(function->arguments); @@ -95,10 +92,10 @@ bool ParserCase::parseImpl(Pos & pos, ASTPtr & node, Expected & expected) if (!parse_branches()) return false; - auto function_args = std::make_shared(StringRange{begin, pos}); + auto function_args = std::make_shared(); function_args->children = std::move(args); - auto function = std::make_shared(StringRange{begin, pos}); + auto function = std::make_shared(); function->name = "multiIf"; function->arguments = function_args; function->children.push_back(function->arguments); diff --git a/dbms/src/Parsers/ParserCheckQuery.cpp b/dbms/src/Parsers/ParserCheckQuery.cpp index b4e243b240b..d9fd46694d6 100644 --- a/dbms/src/Parsers/ParserCheckQuery.cpp +++ b/dbms/src/Parsers/ParserCheckQuery.cpp @@ -12,8 +12,6 @@ namespace DB bool ParserCheckQuery::parseImpl(Pos & pos, ASTPtr & node, Expected & expected) { - Pos begin = pos; - ParserKeyword s_check_table("CHECK TABLE"); ParserToken s_dot(TokenType::Dot); @@ -32,7 +30,7 @@ bool ParserCheckQuery::parseImpl(Pos & pos, ASTPtr & node, Expected & expected) if (!table_parser.parse(pos, table, expected)) return false; - auto query = std::make_shared(StringRange(begin, pos)); + auto query = std::make_shared(); query->database = typeid_cast(*database).name; query->table = typeid_cast(*table).name; node = query; @@ -40,7 +38,7 @@ bool ParserCheckQuery::parseImpl(Pos & pos, ASTPtr & node, Expected & expected) else { table = database; - auto query = std::make_shared(StringRange(begin, pos)); + auto query = std::make_shared(); query->table = typeid_cast(*table).name; node = query; } diff --git a/dbms/src/Parsers/ParserCreateQuery.cpp b/dbms/src/Parsers/ParserCreateQuery.cpp index 6f3d3a4db7c..24c111afc3d 100644 --- a/dbms/src/Parsers/ParserCreateQuery.cpp +++ b/dbms/src/Parsers/ParserCreateQuery.cpp @@ -21,8 +21,6 @@ bool ParserNestedTable::parseImpl(Pos & pos, ASTPtr & node, Expected & expected) ASTPtr name; ASTPtr columns; - Pos begin = pos; - /// For now `name == 'Nested'`, probably alternative nested data structures will appear if (!name_p.parse(pos, name, expected)) return false; @@ -36,7 +34,7 @@ bool ParserNestedTable::parseImpl(Pos & pos, ASTPtr & node, Expected & expected) if (!close.ignore(pos)) return false; - auto func = std::make_shared(StringRange(begin, pos)); + auto func = std::make_shared(); func->name = typeid_cast(*name).name; func->arguments = columns; func->children.push_back(columns); @@ -65,15 +63,13 @@ bool ParserIdentifierWithOptionalParameters::parseImpl(Pos & pos, ASTPtr & node, ParserIdentifier non_parametric; ParserIdentifierWithParameters parametric; - Pos begin = pos; - if (parametric.parse(pos, node, expected)) return true; ASTPtr ident; if (non_parametric.parse(pos, ident, expected)) { - auto func = std::make_shared(StringRange(begin)); + auto func = std::make_shared(); func->name = typeid_cast(*ident).name; node = func; return true; @@ -87,7 +83,7 @@ bool ParserTypeInCastExpression::parseImpl(Pos & pos, ASTPtr & node, Expected & if (ParserIdentifierWithOptionalParameters::parseImpl(pos, node, expected)) { const auto & id_with_params = typeid_cast(*node); - node = std::make_shared(id_with_params.range, String{ id_with_params.range.first, id_with_params.range.second }); + node = std::make_shared(String{ id_with_params.range.first, id_with_params.range.second }); return true; } @@ -120,8 +116,6 @@ bool ParserStorage::parseImpl(Pos & pos, ASTPtr & node, Expected & expected) ParserExpression expression_p; ParserSetQuery settings_p(/* parse_only_internals_ = */ true); - Pos begin = pos; - ASTPtr engine; ASTPtr partition_by; ASTPtr order_by; @@ -171,7 +165,7 @@ bool ParserStorage::parseImpl(Pos & pos, ASTPtr & node, Expected & expected) break; } - auto storage = std::make_shared(StringRange(begin, pos)); + auto storage = std::make_shared(); storage->set(storage->engine, engine); storage->set(storage->partition_by, partition_by); storage->set(storage->order_by, order_by); @@ -185,8 +179,6 @@ bool ParserStorage::parseImpl(Pos & pos, ASTPtr & node, Expected & expected) bool ParserCreateQuery::parseImpl(Pos & pos, ASTPtr & node, Expected & expected) { - Pos begin = pos; - ParserKeyword s_create("CREATE"); ParserKeyword s_temporary("TEMPORARY"); ParserKeyword s_attach("ATTACH"); @@ -259,7 +251,7 @@ bool ParserCreateQuery::parseImpl(Pos & pos, ASTPtr & node, Expected & expected) // Shortcut for ATTACH a previously detached table if (attach && (!pos.isValid() || pos.get().type == TokenType::Semicolon)) { - auto query = std::make_shared(StringRange(begin, pos)); + auto query = std::make_shared(); node = query; query->attach = attach; @@ -403,7 +395,7 @@ bool ParserCreateQuery::parseImpl(Pos & pos, ASTPtr & node, Expected & expected) return false; } - auto query = std::make_shared(StringRange(begin, pos)); + auto query = std::make_shared(); node = query; query->attach = attach; diff --git a/dbms/src/Parsers/ParserCreateQuery.h b/dbms/src/Parsers/ParserCreateQuery.h index 4e5261ff8b6..4225fa9b8ca 100644 --- a/dbms/src/Parsers/ParserCreateQuery.h +++ b/dbms/src/Parsers/ParserCreateQuery.h @@ -75,13 +75,11 @@ bool IParserNameTypePair::parseImpl(Pos & pos, ASTPtr & node, Expect NameParser name_parser; ParserIdentifierWithOptionalParameters type_parser; - Pos begin = pos; - ASTPtr name, type; if (name_parser.parse(pos, name, expected) && type_parser.parse(pos, type, expected)) { - auto name_type_pair = std::make_shared(StringRange(begin, pos)); + auto name_type_pair = std::make_shared(); name_type_pair->name = typeid_cast(*name).name; name_type_pair->type = type; name_type_pair->children.push_back(type); @@ -122,8 +120,6 @@ bool IParserColumnDeclaration::parseImpl(Pos & pos, ASTPtr & node, E ParserKeyword s_alias{"ALIAS"}; ParserTernaryOperatorExpression expr_parser; - const auto begin = pos; - /// mandatory column name ASTPtr name; if (!name_parser.parse(pos, name, expected)) @@ -160,7 +156,7 @@ bool IParserColumnDeclaration::parseImpl(Pos & pos, ASTPtr & node, E else if (!type) return false; /// reject sole column name without type - const auto column_declaration = std::make_shared(StringRange{begin, pos}); + const auto column_declaration = std::make_shared(); node = column_declaration; column_declaration->name = typeid_cast(*name).name; if (type) diff --git a/dbms/src/Parsers/ParserDescribeTableQuery.cpp b/dbms/src/Parsers/ParserDescribeTableQuery.cpp index 1341f105c89..ebfc3baa33f 100644 --- a/dbms/src/Parsers/ParserDescribeTableQuery.cpp +++ b/dbms/src/Parsers/ParserDescribeTableQuery.cpp @@ -14,8 +14,6 @@ namespace DB bool ParserDescribeTableQuery::parseImpl(Pos & pos, ASTPtr & node, Expected & expected) { - Pos begin = pos; - ParserKeyword s_describe("DESCRIBE"); ParserKeyword s_desc("DESC"); ParserKeyword s_table("TABLE"); @@ -36,7 +34,6 @@ bool ParserDescribeTableQuery::parseImpl(Pos & pos, ASTPtr & node, Expected & ex if (!ParserTableExpression().parse(pos, table_expression, expected)) return false; - query->range = StringRange(begin, pos); query->table_expression = table_expression; node = query; diff --git a/dbms/src/Parsers/ParserDropQuery.cpp b/dbms/src/Parsers/ParserDropQuery.cpp index 0475711a225..fe4249db019 100644 --- a/dbms/src/Parsers/ParserDropQuery.cpp +++ b/dbms/src/Parsers/ParserDropQuery.cpp @@ -13,8 +13,6 @@ namespace DB bool ParserDropQuery::parseImpl(Pos & pos, ASTPtr & node, Expected & expected) { - Pos begin = pos; - ParserKeyword s_drop("DROP"); ParserKeyword s_detach("DETACH"); ParserKeyword s_temporary("TEMPORARY"); @@ -81,7 +79,7 @@ bool ParserDropQuery::parseImpl(Pos & pos, ASTPtr & node, Expected & expected) } } - auto query = std::make_shared(StringRange(begin, pos)); + auto query = std::make_shared(); node = query; query->detach = detach; diff --git a/dbms/src/Parsers/ParserInsertQuery.cpp b/dbms/src/Parsers/ParserInsertQuery.cpp index 2fe8ca46f68..ef1aeb6620e 100644 --- a/dbms/src/Parsers/ParserInsertQuery.cpp +++ b/dbms/src/Parsers/ParserInsertQuery.cpp @@ -24,8 +24,6 @@ namespace ErrorCodes bool ParserInsertQuery::parseImpl(Pos & pos, ASTPtr & node, Expected & expected) { - Pos begin = pos; - ParserKeyword s_insert_into("INSERT INTO"); ParserKeyword s_table("TABLE"); ParserKeyword s_function("FUNCTION"); @@ -130,7 +128,7 @@ bool ParserInsertQuery::parseImpl(Pos & pos, ASTPtr & node, Expected & expected) return false; } - auto query = std::make_shared(StringRange(begin, pos)); + auto query = std::make_shared(); node = query; if (table_function) diff --git a/dbms/src/Parsers/ParserKillQueryQuery.cpp b/dbms/src/Parsers/ParserKillQueryQuery.cpp index bbc4eb22ead..8179a4897fc 100644 --- a/dbms/src/Parsers/ParserKillQueryQuery.cpp +++ b/dbms/src/Parsers/ParserKillQueryQuery.cpp @@ -11,7 +11,6 @@ namespace DB bool ParserKillQueryQuery::parseImpl(Pos & pos, ASTPtr & node, Expected & expected) { - Pos begin = pos; auto query = std::make_shared(); if (!ParserKeyword{"KILL QUERY"}.ignore(pos, expected)) @@ -31,8 +30,6 @@ bool ParserKillQueryQuery::parseImpl(Pos & pos, ASTPtr & node, Expected & expect else if (ParserKeyword{"TEST"}.ignore(pos)) query->test = true; - query->range = StringRange(begin, pos); - node = std::move(query); return true; diff --git a/dbms/src/Parsers/ParserOptimizeQuery.cpp b/dbms/src/Parsers/ParserOptimizeQuery.cpp index 90e9146210a..c01a1a7b5df 100644 --- a/dbms/src/Parsers/ParserOptimizeQuery.cpp +++ b/dbms/src/Parsers/ParserOptimizeQuery.cpp @@ -15,8 +15,6 @@ namespace DB bool ParserOptimizeQuery::parseImpl(Pos & pos, ASTPtr & node, Expected & expected) { - Pos begin = pos; - ParserKeyword s_optimize_table("OPTIMIZE TABLE"); ParserKeyword s_partition("PARTITION"); ParserKeyword s_final("FINAL"); @@ -56,7 +54,7 @@ bool ParserOptimizeQuery::parseImpl(Pos & pos, ASTPtr & node, Expected & expecte if (s_deduplicate.ignore(pos, expected)) deduplicate = true; - auto query = std::make_shared(StringRange(begin, pos)); + auto query = std::make_shared(); node = query; if (database) diff --git a/dbms/src/Parsers/ParserPartition.cpp b/dbms/src/Parsers/ParserPartition.cpp index 9ecd03d9cd8..1daf4dead18 100644 --- a/dbms/src/Parsers/ParserPartition.cpp +++ b/dbms/src/Parsers/ParserPartition.cpp @@ -73,7 +73,6 @@ bool ParserPartition::parseImpl(Pos & pos, ASTPtr & node, Expected & expected) partition->fields_count = fields_count; } - partition->range = StringRange(begin, pos); node = partition; return true; } diff --git a/dbms/src/Parsers/ParserRenameQuery.cpp b/dbms/src/Parsers/ParserRenameQuery.cpp index 219311b63d1..6eb8d768df9 100644 --- a/dbms/src/Parsers/ParserRenameQuery.cpp +++ b/dbms/src/Parsers/ParserRenameQuery.cpp @@ -40,8 +40,6 @@ static bool parseDatabaseAndTable( bool ParserRenameQuery::parseImpl(Pos & pos, ASTPtr & node, Expected & expected) { - Pos begin = pos; - ParserKeyword s_rename_table("RENAME TABLE"); ParserKeyword s_to("TO"); ParserToken s_comma(TokenType::Comma); @@ -71,7 +69,7 @@ bool ParserRenameQuery::parseImpl(Pos & pos, ASTPtr & node, Expected & expected) return false; } - auto query = std::make_shared(StringRange(begin, pos)); + auto query = std::make_shared(); query->cluster = cluster_str; node = query; diff --git a/dbms/src/Parsers/ParserSampleRatio.cpp b/dbms/src/Parsers/ParserSampleRatio.cpp index 85cba60a370..3091ed91570 100644 --- a/dbms/src/Parsers/ParserSampleRatio.cpp +++ b/dbms/src/Parsers/ParserSampleRatio.cpp @@ -83,8 +83,6 @@ static bool parseDecimal(const char * pos, const char * end, ASTSampleRatio::Rat */ bool ParserSampleRatio::parseImpl(Pos & pos, ASTPtr & node, Expected &) { - auto begin = pos; - ASTSampleRatio::Rational numerator; ASTSampleRatio::Rational denominator; ASTSampleRatio::Rational res; @@ -111,7 +109,7 @@ bool ParserSampleRatio::parseImpl(Pos & pos, ASTPtr & node, Expected &) res = numerator; } - node = std::make_shared(StringRange(begin, pos), res); + node = std::make_shared(res); return true; } diff --git a/dbms/src/Parsers/ParserSelectQuery.cpp b/dbms/src/Parsers/ParserSelectQuery.cpp index 99240a31f76..c8c2aec1d50 100644 --- a/dbms/src/Parsers/ParserSelectQuery.cpp +++ b/dbms/src/Parsers/ParserSelectQuery.cpp @@ -22,8 +22,6 @@ namespace ErrorCodes bool ParserSelectQuery::parseImpl(Pos & pos, ASTPtr & node, Expected & expected) { - Pos begin = pos; - auto select_query = std::make_shared(); node = select_query; @@ -183,8 +181,6 @@ bool ParserSelectQuery::parseImpl(Pos & pos, ASTPtr & node, Expected & expected) next_select_query->prev_union_all = node.get(); } - select_query->range = StringRange(begin, pos); - if (select_query->with_expression_list) select_query->children.push_back(select_query->with_expression_list); select_query->children.push_back(select_query->select_expression_list); diff --git a/dbms/src/Parsers/ParserSetQuery.cpp b/dbms/src/Parsers/ParserSetQuery.cpp index 109c4e5acc1..11f125bb955 100644 --- a/dbms/src/Parsers/ParserSetQuery.cpp +++ b/dbms/src/Parsers/ParserSetQuery.cpp @@ -40,8 +40,6 @@ static bool parseNameValuePair(ASTSetQuery::Change & change, IParser::Pos & pos, bool ParserSetQuery::parseImpl(Pos & pos, ASTPtr & node, Expected & expected) { - Pos begin = pos; - ParserToken s_comma(TokenType::Comma); if (!parse_only_internals) @@ -65,7 +63,7 @@ bool ParserSetQuery::parseImpl(Pos & pos, ASTPtr & node, Expected & expected) return false; } - auto query = std::make_shared(StringRange(begin, pos)); + auto query = std::make_shared(); node = query; query->is_standalone = !parse_only_internals; diff --git a/dbms/src/Parsers/ParserShowProcesslistQuery.h b/dbms/src/Parsers/ParserShowProcesslistQuery.h index 5958259fb76..b7a661516b0 100644 --- a/dbms/src/Parsers/ParserShowProcesslistQuery.h +++ b/dbms/src/Parsers/ParserShowProcesslistQuery.h @@ -19,14 +19,11 @@ protected: bool parseImpl(Pos & pos, ASTPtr & node, Expected & expected) { - Pos begin = pos; - auto query = std::make_shared(); if (!ParserKeyword("SHOW PROCESSLIST").ignore(pos, expected)) return false; - query->range = StringRange(begin, pos); node = query; return true; diff --git a/dbms/src/Parsers/ParserShowTablesQuery.cpp b/dbms/src/Parsers/ParserShowTablesQuery.cpp index 5399eeef50c..e4d6b5288d2 100644 --- a/dbms/src/Parsers/ParserShowTablesQuery.cpp +++ b/dbms/src/Parsers/ParserShowTablesQuery.cpp @@ -15,8 +15,6 @@ namespace DB bool ParserShowTablesQuery::parseImpl(Pos & pos, ASTPtr & node, Expected & expected) { - Pos begin = pos; - ParserKeyword s_show("SHOW"); ParserKeyword s_temporary("TEMPORARY"); ParserKeyword s_tables("TABLES"); @@ -67,8 +65,6 @@ bool ParserShowTablesQuery::parseImpl(Pos & pos, ASTPtr & node, Expected & expec return false; } - query->range = StringRange(begin, pos); - if (database) query->from = typeid_cast(*database).name; if (like) diff --git a/dbms/src/Parsers/ParserSystemQuery.cpp b/dbms/src/Parsers/ParserSystemQuery.cpp index 2ef71b9dcb3..b430e9e7fc7 100644 --- a/dbms/src/Parsers/ParserSystemQuery.cpp +++ b/dbms/src/Parsers/ParserSystemQuery.cpp @@ -18,8 +18,6 @@ namespace DB bool ParserSystemQuery::parseImpl(IParser::Pos & pos, ASTPtr & node, Expected & expected) { - auto begin = pos; - if (!ParserKeyword{"SYSTEM"}.ignore(pos)) return false; @@ -51,7 +49,6 @@ bool ParserSystemQuery::parseImpl(IParser::Pos & pos, ASTPtr & node, Expected & throw Exception("SYNC REPLICA is not supported yet", ErrorCodes::NOT_IMPLEMENTED); } - res->range = {begin, pos}; node = std::move(res); return true; } diff --git a/dbms/src/Parsers/ParserTablePropertiesQuery.cpp b/dbms/src/Parsers/ParserTablePropertiesQuery.cpp index 8ed7046b2b2..4c9383d460a 100644 --- a/dbms/src/Parsers/ParserTablePropertiesQuery.cpp +++ b/dbms/src/Parsers/ParserTablePropertiesQuery.cpp @@ -13,8 +13,6 @@ namespace DB bool ParserTablePropertiesQuery::parseImpl(Pos & pos, ASTPtr & node, Expected & expected) { - Pos begin = pos; - ParserKeyword s_exists("EXISTS"); ParserKeyword s_describe("DESCRIBE"); ParserKeyword s_desc("DESC"); @@ -56,8 +54,6 @@ bool ParserTablePropertiesQuery::parseImpl(Pos & pos, ASTPtr & node, Expected & return false; } - query->range = StringRange(begin, pos); - if (database) query->database = typeid_cast(*database).name; if (table) diff --git a/dbms/src/Parsers/ParserUseQuery.cpp b/dbms/src/Parsers/ParserUseQuery.cpp index 25d41dae213..9e521a0d746 100644 --- a/dbms/src/Parsers/ParserUseQuery.cpp +++ b/dbms/src/Parsers/ParserUseQuery.cpp @@ -9,10 +9,9 @@ namespace DB { + bool ParserUseQuery::parseImpl(Pos & pos, ASTPtr & node, Expected & expected) { - Pos begin = pos; - ParserKeyword s_use("USE"); ParserIdentifier name_p; @@ -24,10 +23,11 @@ bool ParserUseQuery::parseImpl(Pos & pos, ASTPtr & node, Expected & expected) if (!name_p.parse(pos, database, expected)) return false; - auto query = std::make_shared(StringRange(begin, pos)); + auto query = std::make_shared(); query->database = typeid_cast(*database).name; node = query; return true; } + } diff --git a/dbms/src/Parsers/StringRange.h b/dbms/src/Parsers/StringRange.h index 0c901bf5309..b919a899293 100644 --- a/dbms/src/Parsers/StringRange.h +++ b/dbms/src/Parsers/StringRange.h @@ -11,8 +11,8 @@ namespace DB struct StringRange { - const char * first; - const char * second; + const char * first = nullptr; + const char * second = nullptr; StringRange() {} StringRange(const char * begin, const char * end) : first(begin), second(end) {} @@ -41,7 +41,7 @@ using StringPtr = std::shared_ptr; inline String toString(const StringRange & range) { - return String(range.first, range.second); + return range.first ? String(range.first, range.second) : String(); } } diff --git a/dbms/src/Parsers/TablePropertiesQueriesASTs.h b/dbms/src/Parsers/TablePropertiesQueriesASTs.h index 667ef00399b..312b112f494 100644 --- a/dbms/src/Parsers/TablePropertiesQueriesASTs.h +++ b/dbms/src/Parsers/TablePropertiesQueriesASTs.h @@ -32,8 +32,6 @@ class ASTDescribeQuery : public ASTQueryWithOutput public: ASTPtr table_expression; - ASTDescribeQuery() = default; - explicit ASTDescribeQuery(StringRange range_) : ASTQueryWithOutput(range_) {} String getID() const override { return "DescribeQuery"; }; ASTPtr clone() const override diff --git a/dbms/src/Parsers/parseIdentifierOrStringLiteral.cpp b/dbms/src/Parsers/parseIdentifierOrStringLiteral.cpp index 81281bbc0d6..eaff2e85a9a 100644 --- a/dbms/src/Parsers/parseIdentifierOrStringLiteral.cpp +++ b/dbms/src/Parsers/parseIdentifierOrStringLiteral.cpp @@ -10,12 +10,10 @@ namespace DB bool parseIdentifierOrStringLiteral(IParser::Pos & pos, Expected & expected, String & result) { - IParser::Pos begin = pos; ASTPtr res; if (!ParserIdentifier().parse(pos, res, expected)) { - pos = begin; if (!ParserStringLiteral().parse(pos, res, expected)) return false; @@ -27,4 +25,4 @@ bool parseIdentifierOrStringLiteral(IParser::Pos & pos, Expected & expected, Str return true; } -} \ No newline at end of file +} diff --git a/dbms/src/Parsers/queryToString.cpp b/dbms/src/Parsers/queryToString.cpp index 35e2edd61d6..d214468c2a9 100644 --- a/dbms/src/Parsers/queryToString.cpp +++ b/dbms/src/Parsers/queryToString.cpp @@ -13,7 +13,6 @@ namespace DB { std::ostringstream out; formatAST(query, out, false, true); - return out.str(); } } diff --git a/dbms/src/Server/ClusterCopier.cpp b/dbms/src/Server/ClusterCopier.cpp index ae1d0643ff1..571b8a58232 100644 --- a/dbms/src/Server/ClusterCopier.cpp +++ b/dbms/src/Server/ClusterCopier.cpp @@ -373,9 +373,9 @@ std::shared_ptr createASTStorageDistributed( const String & cluster_name, const String & database, const String & table, const ASTPtr & sharding_key_ast = nullptr) { auto args = std::make_shared(); - args->children.emplace_back(std::make_shared(StringRange(nullptr, nullptr), cluster_name)); - args->children.emplace_back(std::make_shared(StringRange(nullptr, nullptr), database)); - args->children.emplace_back(std::make_shared(StringRange(nullptr, nullptr), table)); + args->children.emplace_back(std::make_shared(cluster_name)); + args->children.emplace_back(std::make_shared(database)); + args->children.emplace_back(std::make_shared(table)); if (sharding_key_ast) args->children.emplace_back(sharding_key_ast); @@ -487,7 +487,7 @@ static ASTPtr extractPartitionKey(const ASTPtr & storage_ast) return storage.partition_by->clone(); static const char * all = "all"; - return std::make_shared(StringRange(all, all + strlen(all)), Field(all, strlen(all))); + return std::make_shared(Field(all, strlen(all))); } else { diff --git a/dbms/src/Storages/AlterCommands.cpp b/dbms/src/Storages/AlterCommands.cpp index b5a726ecc6e..2ad9ae6e27d 100644 --- a/dbms/src/Storages/AlterCommands.cpp +++ b/dbms/src/Storages/AlterCommands.cpp @@ -245,8 +245,8 @@ void AlterCommands::validate(IStorage * table, const Context & context) const auto column_type_raw_ptr = command.data_type.get(); default_expr_list->children.emplace_back(setAlias( - makeASTFunction("CAST", std::make_shared(StringRange(), tmp_column_name), - std::make_shared(StringRange(), Field(column_type_raw_ptr->getName()))), + makeASTFunction("CAST", std::make_shared(tmp_column_name), + std::make_shared(Field(column_type_raw_ptr->getName()))), final_column_name)); default_expr_list->children.emplace_back(setAlias(command.default_expression->clone(), tmp_column_name)); @@ -299,8 +299,8 @@ void AlterCommands::validate(IStorage * table, const Context & context) const auto & column_type_ptr = column_it->type; default_expr_list->children.emplace_back(setAlias( - makeASTFunction("CAST", std::make_shared(StringRange(), tmp_column_name), - std::make_shared(StringRange(), Field(column_type_ptr->getName()))), + makeASTFunction("CAST", std::make_shared(tmp_column_name), + std::make_shared(Field(column_type_ptr->getName()))), column_name)); default_expr_list->children.emplace_back(setAlias(col_def.second.expression->clone(), tmp_column_name)); @@ -345,7 +345,7 @@ void AlterCommands::validate(IStorage * table, const Context & context) } command_ptr->default_expression = makeASTFunction("CAST", command_ptr->default_expression->clone(), - std::make_shared(StringRange(), Field(explicit_type->getName()))); + std::make_shared(Field(explicit_type->getName()))); } } else diff --git a/dbms/src/Storages/MergeTree/MergeTreeDataSelectExecutor.cpp b/dbms/src/Storages/MergeTree/MergeTreeDataSelectExecutor.cpp index 8c9655fe68a..b6d19da1d89 100644 --- a/dbms/src/Storages/MergeTree/MergeTreeDataSelectExecutor.cpp +++ b/dbms/src/Storages/MergeTree/MergeTreeDataSelectExecutor.cpp @@ -434,7 +434,7 @@ BlockInputStreams MergeTreeDataSelectExecutor::read( ASTPtr args = std::make_shared(); args->children.push_back(data.sampling_expression); - args->children.push_back(std::make_shared(StringRange(), lower)); + args->children.push_back(std::make_shared(lower)); lower_function = std::make_shared(); lower_function->name = "greaterOrEquals"; @@ -451,7 +451,7 @@ BlockInputStreams MergeTreeDataSelectExecutor::read( ASTPtr args = std::make_shared(); args->children.push_back(data.sampling_expression); - args->children.push_back(std::make_shared(StringRange(), upper)); + args->children.push_back(std::make_shared(upper)); upper_function = std::make_shared(); upper_function->name = "less"; @@ -846,8 +846,8 @@ void MergeTreeDataSelectExecutor::createPositiveSignCondition( { auto function = std::make_shared(); auto arguments = std::make_shared(); - auto sign = std::make_shared(); - auto one = std::make_shared(); + auto sign = std::make_shared(data.merging_params.sign_column); + auto one = std::make_shared(Field(static_cast(1))); function->name = "equals"; function->arguments = arguments; @@ -856,11 +856,6 @@ void MergeTreeDataSelectExecutor::createPositiveSignCondition( arguments->children.push_back(sign); arguments->children.push_back(one); - sign->name = data.merging_params.sign_column; - sign->kind = ASTIdentifier::Column; - - one->value = Field(static_cast(1)); - out_expression = ExpressionAnalyzer(function, context, {}, data.getColumnsList()).getActions(false); out_column = function->getColumnName(); } diff --git a/dbms/src/Storages/MergeTree/PKCondition.cpp b/dbms/src/Storages/MergeTree/PKCondition.cpp index 798266e1d15..1d80ea38a87 100644 --- a/dbms/src/Storages/MergeTree/PKCondition.cpp +++ b/dbms/src/Storages/MergeTree/PKCondition.cpp @@ -13,6 +13,7 @@ #include #include #include +#include namespace DB @@ -593,7 +594,7 @@ static void castValueToType(const DataTypePtr & desired_type, Field & src_value, { throw Exception("Primary key expression contains comparison between inconvertible types: " + desired_type->getName() + " and " + src_type->getName() + - " inside " + DB::toString(node->range), + " inside " + queryToString(node), ErrorCodes::BAD_TYPE_OF_FIELD); } } diff --git a/dbms/src/Storages/StorageBuffer.cpp b/dbms/src/Storages/StorageBuffer.cpp index 1b32ba197ff..62ab67df163 100644 --- a/dbms/src/Storages/StorageBuffer.cpp +++ b/dbms/src/Storages/StorageBuffer.cpp @@ -558,7 +558,7 @@ void StorageBuffer::writeBlockToDestination(const Block & block, StoragePtr tabl insert->columns = list_of_columns; list_of_columns->children.reserve(columns_intersection.size()); for (const String & column : columns_intersection) - list_of_columns->children.push_back(std::make_shared(StringRange(), column, ASTIdentifier::Column)); + list_of_columns->children.push_back(std::make_shared(column, ASTIdentifier::Column)); InterpreterInsertQuery interpreter{insert, context, allow_materialized}; diff --git a/dbms/src/Storages/StorageCatBoostPool.cpp b/dbms/src/Storages/StorageCatBoostPool.cpp index 74a40372b79..cbaf523e3bf 100644 --- a/dbms/src/Storages/StorageCatBoostPool.cpp +++ b/dbms/src/Storages/StorageCatBoostPool.cpp @@ -243,13 +243,12 @@ void StorageCatBoostPool::createSampleBlockAndColumns() if (!desc.alias.empty()) { - auto alias = std::make_shared(); - alias->name = desc.column_name; + auto alias = std::make_shared(desc.column_name); column_defaults[desc.alias] = {ColumnDefaultType::Alias, alias}; alias_columns.emplace_back(desc.alias, type); } - sample_block.insert(ColumnWithTypeAndName(type->createColumn(), type, desc.column_name)); + sample_block.insert(ColumnWithTypeAndName(type, desc.column_name)); } columns.insert(columns.end(), num_columns.begin(), num_columns.end()); columns.insert(columns.end(), cat_columns.begin(), cat_columns.end()); diff --git a/dbms/src/Storages/StorageDistributed.cpp b/dbms/src/Storages/StorageDistributed.cpp index b191f598a0e..aad4245d39c 100644 --- a/dbms/src/Storages/StorageDistributed.cpp +++ b/dbms/src/Storages/StorageDistributed.cpp @@ -267,13 +267,10 @@ BlockInputStreams StorageDistributed::describe(const Context & context, const Se std::string name = remote_database + '.' + remote_table; - auto id = std::make_shared(); - id->name = name; + auto id = std::make_shared(name); - auto desc_database = std::make_shared(); - auto desc_table = std::make_shared(); - desc_database->name = remote_database; - desc_table->name = remote_table; + auto desc_database = std::make_shared(remote_database); + auto desc_table = std::make_shared(remote_table); id->children.push_back(desc_database); id->children.push_back(desc_table); diff --git a/dbms/src/Storages/StorageMergeTree.cpp b/dbms/src/Storages/StorageMergeTree.cpp index 29d0ba0ba08..317891065c4 100644 --- a/dbms/src/Storages/StorageMergeTree.cpp +++ b/dbms/src/Storages/StorageMergeTree.cpp @@ -202,9 +202,10 @@ void StorageMergeTree::alter( IDatabase::ASTModifier storage_modifier; if (primary_key_is_modified) + { storage_modifier = [&new_primary_key_ast] (IAST & ast) { - auto tuple = std::make_shared(new_primary_key_ast->range); + auto tuple = std::make_shared(); tuple->name = "tuple"; tuple->arguments = new_primary_key_ast; tuple->children.push_back(tuple->arguments); @@ -214,6 +215,7 @@ void StorageMergeTree::alter( auto & storage_ast = typeid_cast(ast); typeid_cast(*storage_ast.engine->arguments).children.at(1) = tuple; }; + } context.getDatabase(database_name)->alterTable( context, table_name, diff --git a/dbms/src/Storages/VirtualColumnUtils.cpp b/dbms/src/Storages/VirtualColumnUtils.cpp index 70fa6f8712a..e9efe406e45 100644 --- a/dbms/src/Storages/VirtualColumnUtils.cpp +++ b/dbms/src/Storages/VirtualColumnUtils.cpp @@ -81,7 +81,7 @@ void rewriteEntityInAst(ASTPtr ast, const String & column_name, const Field & va } ASTExpressionList & with = typeid_cast(*select.with_expression_list); - auto literal = std::make_shared(StringRange(), value); + auto literal = std::make_shared(value); literal->alias = column_name; literal->prefer_alias_to_column_name = true; with.children.push_back(literal); diff --git a/dbms/src/Storages/transformQueryForExternalDatabase.cpp b/dbms/src/Storages/transformQueryForExternalDatabase.cpp index 538c8ede9a4..bf4fd14b23a 100644 --- a/dbms/src/Storages/transformQueryForExternalDatabase.cpp +++ b/dbms/src/Storages/transformQueryForExternalDatabase.cpp @@ -70,7 +70,7 @@ String transformQueryForExternalDatabase( auto select_expr_list = std::make_shared(); for (const auto & name : used_columns) - select_expr_list->children.push_back(std::make_shared(StringRange(), name)); + select_expr_list->children.push_back(std::make_shared(name)); select->select_expression_list = std::move(select_expr_list); From 89c0dc2eeaf1dd8eef1362104e6e1e50d8038c6c Mon Sep 17 00:00:00 2001 From: Alexey Milovidov Date: Mon, 26 Feb 2018 06:45:46 +0300 Subject: [PATCH 2/4] Fixed build #1947 --- dbms/src/Interpreters/ExpressionAnalyzer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dbms/src/Interpreters/ExpressionAnalyzer.cpp b/dbms/src/Interpreters/ExpressionAnalyzer.cpp index a1cf16a1a27..93352e7b027 100644 --- a/dbms/src/Interpreters/ExpressionAnalyzer.cpp +++ b/dbms/src/Interpreters/ExpressionAnalyzer.cpp @@ -1027,7 +1027,7 @@ void ExpressionAnalyzer::normalizeTreeImpl( ASTs & asts = node->children; for (int i = static_cast(asts.size()) - 1; i >= 0; --i) { - if (ASTAsterisk * asterisk = typeid_cast(asts[i].get())) + if (typeid_cast(asts[i].get())) { ASTs all_columns; for (const auto & column_name_type : columns) From a4544ac498830703f8044cd56d0d06fc35d387e5 Mon Sep 17 00:00:00 2001 From: Alexey Milovidov Date: Mon, 26 Feb 2018 06:47:32 +0300 Subject: [PATCH 3/4] Fixed error [#CLICKHOUSE-2] --- dbms/src/Parsers/IParserBase.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dbms/src/Parsers/IParserBase.cpp b/dbms/src/Parsers/IParserBase.cpp index c1a17805068..dffb1d7597d 100644 --- a/dbms/src/Parsers/IParserBase.cpp +++ b/dbms/src/Parsers/IParserBase.cpp @@ -22,7 +22,7 @@ bool IParserBase::parse(Pos & pos, ASTPtr & node, Expected & expected) node = nullptr; pos = begin; } - else + else if (node) node->range = StringRange(begin, pos); return res; From 5c450708e1d32b35e736c66f69f8bf137136245f Mon Sep 17 00:00:00 2001 From: Alexey Milovidov Date: Mon, 26 Feb 2018 07:47:27 +0300 Subject: [PATCH 4/4] Fixed bad code #1947 --- dbms/src/Parsers/ExpressionElementParsers.cpp | 5 +++-- dbms/src/Parsers/ParserCreateQuery.cpp | 2 +- dbms/src/Parsers/ParserCreateQuery.h | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/dbms/src/Parsers/ExpressionElementParsers.cpp b/dbms/src/Parsers/ExpressionElementParsers.cpp index 9463b737d82..5727d058c22 100644 --- a/dbms/src/Parsers/ExpressionElementParsers.cpp +++ b/dbms/src/Parsers/ExpressionElementParsers.cpp @@ -319,6 +319,7 @@ bool ParserCastExpression::parseImpl(Pos & pos, ASTPtr & node, Expected & expect { /// CAST(expression AS type) const auto type = first_argument->tryGetAlias(); + if (type.empty()) { /// there is only one argument and it has no alias @@ -610,7 +611,7 @@ bool ParserAliasImpl::parseImpl(Pos & pos, ASTPtr & node, Expe ParserKeyword s_as("AS"); ParserIdentifier id_p; - bool has_as_word = s_as.parse(pos, node, expected); + bool has_as_word = s_as.ignore(pos, expected); if (!allow_alias_without_as_keyword && !has_as_word) return false; @@ -747,7 +748,7 @@ bool ParserWithOptionalAliasImpl::parseImpl(Pos & pos, ASTPtr & nod ASTPtr alias_node; if (ParserAlias(allow_alias_without_as_keyword_now).parse(pos, alias_node, expected)) { - String alias_name = typeid_cast(*alias_node).name; + String alias_name = typeid_cast(*alias_node).name; if (ASTWithAlias * ast_with_alias = dynamic_cast(node.get())) { diff --git a/dbms/src/Parsers/ParserCreateQuery.cpp b/dbms/src/Parsers/ParserCreateQuery.cpp index 24c111afc3d..84ed3874be3 100644 --- a/dbms/src/Parsers/ParserCreateQuery.cpp +++ b/dbms/src/Parsers/ParserCreateQuery.cpp @@ -80,7 +80,7 @@ bool ParserIdentifierWithOptionalParameters::parseImpl(Pos & pos, ASTPtr & node, bool ParserTypeInCastExpression::parseImpl(Pos & pos, ASTPtr & node, Expected & expected) { - if (ParserIdentifierWithOptionalParameters::parseImpl(pos, node, expected)) + if (ParserIdentifierWithOptionalParameters().parse(pos, node, expected)) { const auto & id_with_params = typeid_cast(*node); node = std::make_shared(String{ id_with_params.range.first, id_with_params.range.second }); diff --git a/dbms/src/Parsers/ParserCreateQuery.h b/dbms/src/Parsers/ParserCreateQuery.h index 4225fa9b8ca..6c0c7a21d52 100644 --- a/dbms/src/Parsers/ParserCreateQuery.h +++ b/dbms/src/Parsers/ParserCreateQuery.h @@ -48,7 +48,7 @@ protected: bool parseImpl(Pos & pos, ASTPtr & node, Expected & expected); }; -class ParserTypeInCastExpression : public ParserIdentifierWithOptionalParameters +class ParserTypeInCastExpression : public IParserBase { protected: const char * getName() const { return "type in cast expression"; }