Skip to content

Commit

Permalink
Refactored the types and additional test cases for the Type->String +…
Browse files Browse the repository at this point in the history
… String->Type methods. Yes, this is a shameless attempt on my part to increase our code coverage...
  • Loading branch information
apavlo committed Oct 21, 2017
1 parent da28c40 commit 02670da
Show file tree
Hide file tree
Showing 5 changed files with 599 additions and 53 deletions.
17 changes: 13 additions & 4 deletions src/include/type/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -617,6 +617,9 @@ enum class CreateType {
CONSTRAINT = 4, // constraint create type
TRIGGER = 5 // trigger create type
};
std::string CreateTypeToString(CreateType type);
CreateType StringToCreateType(const std::string &str);
std::ostream &operator<<(std::ostream &os, const CreateType &type);

//===--------------------------------------------------------------------===//
// Drop Types
Expand All @@ -630,9 +633,9 @@ enum class DropType {
CONSTRAINT = 4, // constraint drop type
TRIGGER = 5 // trigger drop type
};
std::string CreateTypeToString(CreateType type);
CreateType StringToCreateType(const std::string &str);
std::ostream &operator<<(std::ostream &os, const CreateType &type);
std::string DropTypeToString(DropType type);
DropType StringToDropType(const std::string &str);
std::ostream &operator<<(std::ostream &os, const DropType &type);

//===--------------------------------------------------------------------===//
// Statement Types
Expand Down Expand Up @@ -867,6 +870,7 @@ enum class FKConstrMatchType {
//===--------------------------------------------------------------------===//
// Set Operation Types
//===--------------------------------------------------------------------===//

enum class SetOpType {
INVALID = INVALID_TYPE_ID,
INTERSECT = 1,
Expand Down Expand Up @@ -1245,13 +1249,18 @@ typedef std::vector<DirectMap> DirectMapList;
//===--------------------------------------------------------------------===//
// Optimizer
//===--------------------------------------------------------------------===//

enum class PropertyType {
INVALID = INVALID_TYPE_ID,
PREDICATE,
COLUMNS,
DISTINCT,
SORT,
LIMIT,
};
std::string PropertyTypeToString(PropertyType type);
PropertyType StringToPropertyType(const std::string &str);
std::ostream &operator<<(std::ostream &os, const PropertyType &type);

namespace expression {
class AbstractExpression;
Expand Down Expand Up @@ -1282,7 +1291,7 @@ typedef std::unordered_set<std::shared_ptr<expression::AbstractExpression>,
expression::ExprHasher,
expression::ExprEqualCmp> ExprSet;

std::string PropertyTypeToString(PropertyType type);


//===--------------------------------------------------------------------===//
// Wire protocol typedefs
Expand Down
8 changes: 8 additions & 0 deletions src/optimizer/child_property_generator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,10 @@ void ChildPropertyGenerator::AggregateHelper(const BaseOperatorNode *op) {
provided_property.AddProperty(prop);
break;
}
default: {
LOG_ERROR("Unexpected PropertyType '%s'",
PropertyTypeToString(prop->Type()).c_str());
}
}
}
// Add child PropertySort for SortGroupBy if not already do so
Expand Down Expand Up @@ -393,6 +397,10 @@ void ChildPropertyGenerator::JoinHelper(const BaseOperatorNode *op) {

break;
}
default: {
LOG_ERROR("Unexpected PropertyType '%s'",
PropertyTypeToString(prop->Type()).c_str());
}
}
}

Expand Down
155 changes: 127 additions & 28 deletions src/type/types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,9 @@ std::string CreateTypeToString(CreateType type) {
case CreateType::CONSTRAINT: {
return "CONSTRAINT";
}
case CreateType::TRIGGER: {
return "TRIGGER";
}
default: {
throw ConversionException(StringUtil::Format(
"No string conversion for CreateType value '%d'",
Expand All @@ -359,6 +362,8 @@ CreateType StringToCreateType(const std::string& str) {
return CreateType::INDEX;
} else if (upper_str == "CONSTRAINT") {
return CreateType::CONSTRAINT;
} else if (upper_str == "TRIGGER") {
return CreateType::TRIGGER;
} else {
throw ConversionException(StringUtil::Format(
"No CreateType conversion from string '%s'", upper_str.c_str()));
Expand All @@ -370,50 +375,104 @@ std::ostream& operator<<(std::ostream& os, const CreateType& type) {
return os;
}

std::string DropTypeToString(DropType type) {
switch (type) {
case DropType::INVALID: {
return "INVALID";
}
case DropType::DB: {
return "DB";
}
case DropType::TABLE: {
return "TABLE";
}
case DropType::INDEX: {
return "INDEX";
}
case DropType::CONSTRAINT: {
return "CONSTRAINT";
}
case DropType::TRIGGER: {
return "TRIGGER";
}
default: {
throw ConversionException(StringUtil::Format(
"No string conversion for DropType value '%d'",
static_cast<int>(type)));
}
}
return "INVALID";
}

DropType StringToDropType(const std::string& str) {
std::string upper_str = StringUtil::Upper(str);
if (upper_str == "INVALID") {
return DropType::INVALID;
} else if (upper_str == "DB") {
return DropType::DB;
} else if (upper_str == "TABLE") {
return DropType::TABLE;
} else if (upper_str == "INDEX") {
return DropType::INDEX;
} else if (upper_str == "CONSTRAINT") {
return DropType::CONSTRAINT;
} else if (upper_str == "TRIGGER") {
return DropType::TRIGGER;
} else {
throw ConversionException(StringUtil::Format(
"No DropType conversion from string '%s'", upper_str.c_str()));
}
return DropType::INVALID;
}
std::ostream& operator<<(std::ostream& os, const DropType& type) {
os << DropTypeToString(type);
return os;
}

//===--------------------------------------------------------------------===//
// Statement - String Utilities
//===--------------------------------------------------------------------===//

std::string StatementTypeToString(StatementType type) {
switch (type) {
case StatementType::INVALID: {
return "INVALID";
}
case StatementType::SELECT: {
return "SELECT";
}
case StatementType::ALTER: {
return "ALTER";
case StatementType::INSERT: {
return "INSERT";
}
case StatementType::CREATE: {
return "CREATE";
case StatementType::UPDATE: {
return "UPDATE";
}
case StatementType::DELETE: {
return "DELETE";
}
case StatementType::CREATE: {
return "CREATE";
}
case StatementType::DROP: {
return "DROP";
}
case StatementType::EXECUTE: {
return "EXECUTE";
}
case StatementType::COPY: {
return "COPY";
}
case StatementType::INSERT: {
return "INSERT";
}
case StatementType::INVALID: {
return "INVALID";
}
case StatementType::PREPARE: {
return "PREPARE";
}
case StatementType::EXECUTE: {
return "EXECUTE";
}
case StatementType::RENAME: {
return "RENAME";
}
case StatementType::ALTER: {
return "ALTER";
}
case StatementType::TRANSACTION: {
return "TRANSACTION";
}
case StatementType::UPDATE: {
return "UPDATE";
case StatementType::COPY: {
return "COPY";
}
case StatementType::ANALYZE: {
return "ANALYZE";
Expand Down Expand Up @@ -455,6 +514,8 @@ StatementType StringToStatementType(const std::string& str) {
return StatementType::TRANSACTION;
} else if (upper_str == "COPY") {
return StatementType::COPY;
} else if (upper_str == "ANALYZE") {
return StatementType::ANALYZE;
} else {
throw ConversionException(StringUtil::Format(
"No StatementType conversion from string '%s'", upper_str.c_str()));
Expand Down Expand Up @@ -2599,25 +2660,63 @@ std::ostream& operator<<(std::ostream& os, const GCVersionType& type) {
//===--------------------------------------------------------------------===//
// Optimizer
//===--------------------------------------------------------------------===//

std::string PropertyTypeToString(PropertyType type) {
switch (type) {
case PropertyType::SORT:
return "SORT";
case PropertyType::COLUMNS:
return "COLUMNS";
case PropertyType::PREDICATE:
case PropertyType::INVALID: {
return "INVALID";
}
case PropertyType::PREDICATE: {
return "PREDICATE";
case PropertyType::DISTINCT:
}
case PropertyType::COLUMNS: {
return "COLUMNS";
}
case PropertyType::DISTINCT: {
return "DISTINCT";
case PropertyType::LIMIT:
}
case PropertyType::SORT: {
return "SORT";
}
case PropertyType::LIMIT: {
return "LIMIT";
default:
throw ConversionException(StringUtil::Format("No string conversion for PropertyType value '%d'",
static_cast<int>(type)));
}
default: {
throw ConversionException(StringUtil::Format(
"No string conversion for PropertyType value '%d'",
static_cast<int>(type)));
}
}
return "INVALID";
}

PropertyType StringToPropertyType(const std::string& str) {
std::string upper_str = StringUtil::Upper(str);
if (upper_str == "INVALID") {
return PropertyType::INVALID;
} else if (upper_str == "PREDICATE") {
return PropertyType::PREDICATE;
} else if (upper_str == "COLUMNS") {
return PropertyType::COLUMNS;
} else if (upper_str == "DISTINCT") {
return PropertyType::DISTINCT;
} else if (upper_str == "SORT") {
return PropertyType::SORT;
} else if (upper_str == "LIMIT") {
return PropertyType::LIMIT;
} else {
throw ConversionException(
StringUtil::Format("No PropertyType conversion from string '%s'",
upper_str.c_str()));
}
return PropertyType::INVALID;
}

std::ostream& operator<<(std::ostream& os, const PropertyType& type) {
os << PropertyTypeToString(type);
return os;
}

//===--------------------------------------------------------------------===//
// Network Message types
//===--------------------------------------------------------------------===//
Expand Down
Loading

0 comments on commit 02670da

Please sign in to comment.