Skip to content

Commit

Permalink
AggregateType
Browse files Browse the repository at this point in the history
  • Loading branch information
allisonwang committed Jan 19, 2017
1 parent 50e943a commit f86f91a
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 20 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,7 @@ distribute/*
*.bin
cmake_build
.cmake_build
cmake-build-debug

# Bison/Flex
sql_parser.cpp
Expand Down
6 changes: 3 additions & 3 deletions src/executor/aggregate_executor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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_));
Expand Down
13 changes: 8 additions & 5 deletions src/include/type/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/main/sdbench/sdbench_workload.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -911,7 +911,7 @@ static void AggregateQueryHelper(const std::vector<oid_t> &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());
Expand Down
6 changes: 3 additions & 3 deletions src/optimizer/simple_optimizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ std::shared_ptr<planner::AbstractPlan> 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<oid_t> group_by_columns;
auto group_by = select_stmt->group_by;
expression::AbstractExpression* having = nullptr;
Expand Down Expand Up @@ -535,7 +535,7 @@ std::shared_ptr<planner::AbstractPlan> 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);

Expand Down Expand Up @@ -1192,7 +1192,7 @@ SimpleOptimizer::CreateHackingNestedLoopJoinPlan(
output_table_schema.get()->GetInfo().c_str());
std::unique_ptr<planner::AggregatePlan> 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));
Expand Down
49 changes: 49 additions & 0 deletions src/type/types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<int>(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
//===--------------------------------------------------------------------===//
Expand Down
16 changes: 8 additions & 8 deletions test/executor/aggregate_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit f86f91a

Please sign in to comment.