diff --git a/.gitignore b/.gitignore index b042060fcd9..551e8cfedca 100644 --- a/.gitignore +++ b/.gitignore @@ -277,6 +277,7 @@ distribute/* *.bin cmake_build .cmake_build +cmake-build-debug # Bison/Flex sql_parser.cpp diff --git a/src/executor/aggregate_executor.cpp b/src/executor/aggregate_executor.cpp index dd6991a53bd..41f4ef5b999 100644 --- a/src/executor/aggregate_executor.cpp +++ b/src/executor/aggregate_executor.cpp @@ -103,17 +103,17 @@ bool AggregateExecutor::DExecute() { if (nullptr == aggregator.get()) { // Initialize the aggregator switch (node.GetAggregateStrategy()) { - case AGGREGATE_TYPE_HASH: + case AggregateType::HASH: LOG_TRACE("Use HashAggregator"); aggregator.reset(new HashAggregator( &node, output_table, executor_context_, tile->GetColumnCount())); break; - case AGGREGATE_TYPE_SORTED: + case AggregateType::SORTED: LOG_TRACE("Use SortedAggregator"); aggregator.reset(new SortedAggregator( &node, output_table, executor_context_, tile->GetColumnCount())); break; - case AGGREGATE_TYPE_PLAIN: + case AggregateType::PLAIN: LOG_TRACE("Use PlainAggregator"); aggregator.reset( new PlainAggregator(&node, output_table, executor_context_)); diff --git a/src/include/type/types.h b/src/include/type/types.h index 5292b47bf6c..e88dac1e885 100644 --- a/src/include/type/types.h +++ b/src/include/type/types.h @@ -613,12 +613,15 @@ std::ostream &operator<<(std::ostream &os, const JoinType &type); // Aggregate Types //===--------------------------------------------------------------------===// -enum AggregateType { - AGGREGATE_TYPE_INVALID = INVALID_TYPE_ID, - AGGREGATE_TYPE_SORTED = 1, - AGGREGATE_TYPE_HASH = 2, - AGGREGATE_TYPE_PLAIN = 3 // no group-by +enum class AggregateType { + INVALID = INVALID_TYPE_ID, + SORTED = 1, + HASH = 2, + PLAIN = 3 // no group-by }; +std::string AggregateTypeToString(AggregateType type); +JoinType StringToAggregateType(const std::string &str); +std::ostream &operator<<(std::ostream &os, const AggregateType &type); // ------------------------------------------------------------------ // Expression Quantifier Types diff --git a/src/main/sdbench/sdbench_workload.cpp b/src/main/sdbench/sdbench_workload.cpp index e37036f0ffe..ca4df8e7490 100644 --- a/src/main/sdbench/sdbench_workload.cpp +++ b/src/main/sdbench/sdbench_workload.cpp @@ -911,7 +911,7 @@ static void AggregateQueryHelper(const std::vector &tuple_key_attrs, planner::AggregatePlan aggregation_node( std::move(proj_info), std::move(aggregate_predicate), std::move(agg_terms), std::move(group_by_columns), output_table_schema, - AGGREGATE_TYPE_PLAIN); + AggregateType::PLAIN); executor::AggregateExecutor aggregation_executor(&aggregation_node, context.get()); diff --git a/src/optimizer/simple_optimizer.cpp b/src/optimizer/simple_optimizer.cpp index 2dbd279f360..b064be939a7 100644 --- a/src/optimizer/simple_optimizer.cpp +++ b/src/optimizer/simple_optimizer.cpp @@ -89,7 +89,7 @@ std::shared_ptr SimpleOptimizer::BuildPelotonPlanTree( LOG_TRACE("Processing SELECT..."); auto select_stmt = (parser::SelectStatement*)parse_tree2; LOG_TRACE("SELECT Info: %s", select_stmt->GetInfo().c_str()); - auto agg_type = AGGREGATE_TYPE_PLAIN; // default aggregator + auto agg_type = AggregateType::PLAIN; // default aggregator std::vector group_by_columns; auto group_by = select_stmt->group_by; expression::AbstractExpression* having = nullptr; @@ -535,7 +535,7 @@ std::shared_ptr SimpleOptimizer::BuildPelotonPlanTree( // Column name else { // There are columns in the query - agg_type = AGGREGATE_TYPE_HASH; + agg_type = AggregateType::HASH; std::string col_name(expr->GetExpressionName()); oid_t old_col_id = target_table->GetSchema()->GetColumnID(col_name); @@ -1192,7 +1192,7 @@ SimpleOptimizer::CreateHackingNestedLoopJoinPlan( output_table_schema.get()->GetInfo().c_str()); std::unique_ptr agg_plan(new planner::AggregatePlan( std::move(proj_info), std::move(predicate), std::move(agg_terms), - std::move(group_by_columns), output_table_schema, AGGREGATE_TYPE_PLAIN)); + std::move(group_by_columns), output_table_schema, AggregateType::PLAIN)); LOG_DEBUG("Aggregation plan constructed"); agg_plan->AddChild(std::move(nested_join_plan_node)); diff --git a/src/type/types.cpp b/src/type/types.cpp index 31e9cbdb334..c082b5ec45a 100644 --- a/src/type/types.cpp +++ b/src/type/types.cpp @@ -1268,6 +1268,55 @@ std::ostream& operator<<(std::ostream& os, const JoinType& type) { return os; } +//===--------------------------------------------------------------------===// +// AggregateType - String Utilities +//===--------------------------------------------------------------------===// +std::string AggregateTypeToString(AggregateType type) { + switch (type) { + case AggregateType::INVALID: { + return "INVALID"; + } + case AggregateType::SORTED: { + return "SORTED"; + } + case AggregateType::HASH: { + return "HASH"; + } + case AggregateType::PLAIN: { + return "PLAIN"; + } + default: { + throw ConversionException(StringUtil::Format( + "No string conversion for AggregateType value '%d'", + static_cast(type))); + } + } + return "INVALID"; +} + +AggregateType StringToAggregateType(const std::string &str) { + std::string upper_str = StringUtil::Upper(str); + if (upper_str == "INVALID") { + return AggregateType::INVALID; + } else if (upper_str == "SORTED") { + return AggregateType::SORTED; + } else if (upper_str == "HASH") { + return AggregateType::HASH; + } else if (upper_str == "PLAIN") { + return AggregateType::PLAIN; + } else { + throw ConversionException( + StringUtil::Format("No AggregateType conversion from string '%s'", + upper_str.c_str())); + } + return AggregateType::INVALID; +} + +std::ostream &operator<<(std::ostream &os, const AggregateType &type) { + os << AggregateTypeToString(type); + return os; +} + //===--------------------------------------------------------------------===// // PayloadType - String Utilities //===--------------------------------------------------------------------===// diff --git a/test/executor/aggregate_test.cpp b/test/executor/aggregate_test.cpp index e684b20ade7..97c401d1f20 100644 --- a/test/executor/aggregate_test.cpp +++ b/test/executor/aggregate_test.cpp @@ -91,7 +91,7 @@ TEST_F(AggregateTests, SortedDistinctTest) { // OK) Create the plan node planner::AggregatePlan node(std::move(proj_info), std::move(predicate), std::move(agg_terms), std::move(group_by_columns), - output_table_schema, AGGREGATE_TYPE_SORTED); + output_table_schema, AggregateType::SORTED); // Create and set up executor txn = txn_manager.BeginTransaction(); @@ -193,7 +193,7 @@ TEST_F(AggregateTests, SortedSumGroupByTest) { // OK) Create the plan node planner::AggregatePlan node(std::move(proj_info), std::move(predicate), std::move(agg_terms), std::move(group_by_columns), - output_table_schema, AGGREGATE_TYPE_SORTED); + output_table_schema, AggregateType::SORTED); // Create and set up executor txn = txn_manager.BeginTransaction(); @@ -299,7 +299,7 @@ TEST_F(AggregateTests, SortedSumMaxGroupByTest) { // OK) Create the plan node planner::AggregatePlan node(std::move(proj_info), std::move(predicate), std::move(agg_terms), std::move(group_by_columns), - output_table_schema, AGGREGATE_TYPE_SORTED); + output_table_schema, AggregateType::SORTED); // Create and set up executor txn = txn_manager.BeginTransaction(); @@ -420,7 +420,7 @@ TEST_F(AggregateTests, MinMaxTest) { // OK) Create the plan node planner::AggregatePlan node(std::move(proj_info), std::move(predicate), std::move(agg_terms), std::move(group_by_columns), - output_table_schema, AGGREGATE_TYPE_PLAIN); + output_table_schema, AggregateType::PLAIN); // Create and set up executor txn = txn_manager.BeginTransaction(); @@ -517,7 +517,7 @@ TEST_F(AggregateTests, HashDistinctTest) { // OK) Create the plan node planner::AggregatePlan node(std::move(proj_info), std::move(predicate), std::move(agg_terms), std::move(group_by_columns), - output_table_schema, AGGREGATE_TYPE_HASH); + output_table_schema, AggregateType::HASH); // Create and set up executor txn = txn_manager.BeginTransaction(); @@ -609,7 +609,7 @@ TEST_F(AggregateTests, HashSumGroupByTest) { // OK) Create the plan node planner::AggregatePlan node(std::move(proj_info), std::move(predicate), std::move(agg_terms), std::move(group_by_columns), - output_table_schema, AGGREGATE_TYPE_HASH); + output_table_schema, AggregateType::HASH); // Create and set up executor txn = txn_manager.BeginTransaction(); @@ -705,7 +705,7 @@ TEST_F(AggregateTests, HashCountDistinctGroupByTest) { // OK) Create the plan node planner::AggregatePlan node(std::move(proj_info), std::move(predicate), std::move(agg_terms), std::move(group_by_columns), - output_table_schema, AGGREGATE_TYPE_HASH); + output_table_schema, AggregateType::HASH); // Create and set up executor txn = txn_manager.BeginTransaction(); @@ -820,7 +820,7 @@ TEST_F(AggregateTests, PlainSumCountDistinctTest) { // OK) Create the plan node planner::AggregatePlan node(std::move(proj_info), std::move(predicate), std::move(agg_terms), std::move(group_by_columns), - output_table_schema, AGGREGATE_TYPE_PLAIN); + output_table_schema, AggregateType::PLAIN); // Create and set up executor txn = txn_manager.BeginTransaction();