Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean up usage of common:: prefix in cpp files and fix clang warnings #1908

Merged
merged 1 commit into from
Aug 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions src/binder/bind/bind_create_macro.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,17 @@
#include "common/string_utils.h"
#include "parser/create_macro.h"

using namespace kuzu::common;
using namespace kuzu::parser;

namespace kuzu {
namespace binder {

std::unique_ptr<BoundStatement> Binder::bindCreateMacro(const parser::Statement& statement) {
auto& createMacro = reinterpret_cast<const parser::CreateMacro&>(statement);
std::unique_ptr<BoundStatement> Binder::bindCreateMacro(const Statement& statement) {
auto& createMacro = reinterpret_cast<const CreateMacro&>(statement);
auto macroName = createMacro.getMacroName();
if (catalog.getReadOnlyVersion()->containMacro(macroName)) {
throw common::BinderException{
common::StringUtils::string_format("Macro {} already exists.", macroName)};
throw BinderException{StringUtils::string_format("Macro {} already exists.", macroName)};

Check warning on line 16 in src/binder/bind/bind_create_macro.cpp

View check run for this annotation

Codecov / codecov/patch

src/binder/bind/bind_create_macro.cpp#L16

Added line #L16 was not covered by tests
}
parser::default_macro_args defaultArgs;
for (auto& defaultArg : createMacro.getDefaultArgs()) {
Expand Down
27 changes: 13 additions & 14 deletions src/binder/bind/bind_ddl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,9 @@ uint32_t Binder::bindPrimaryKey(const std::string& pkColName,
StringUtils::toUpper(primaryKey.second);
// We only support INT64, STRING and SERIAL column as the primary key.
switch (LogicalTypeUtils::dataTypeFromString(primaryKey.second).getLogicalTypeID()) {
case common::LogicalTypeID::INT64:
case common::LogicalTypeID::STRING:
case common::LogicalTypeID::SERIAL:
case LogicalTypeID::INT64:
case LogicalTypeID::STRING:
case LogicalTypeID::SERIAL:
break;
default:
throw BinderException(
Expand All @@ -194,34 +194,33 @@ property_id_t Binder::bindPropertyName(TableSchema* tableSchema, const std::stri
tableSchema->tableName + " table doesn't have property: " + propertyName + ".");
}

std::unique_ptr<common::LogicalType> Binder::bindDataType(const std::string& dataType) {
std::unique_ptr<LogicalType> Binder::bindDataType(const std::string& dataType) {
auto boundType = LogicalTypeUtils::dataTypeFromString(dataType);
if (boundType.getLogicalTypeID() == common::LogicalTypeID::FIXED_LIST) {
auto validNumericTypes = common::LogicalTypeUtils::getNumericalLogicalTypeIDs();
auto childType = common::FixedListType::getChildType(&boundType);
auto numElementsInList = common::FixedListType::getNumElementsInList(&boundType);
if (boundType.getLogicalTypeID() == LogicalTypeID::FIXED_LIST) {
auto validNumericTypes = LogicalTypeUtils::getNumericalLogicalTypeIDs();
auto childType = FixedListType::getChildType(&boundType);
auto numElementsInList = FixedListType::getNumElementsInList(&boundType);
if (find(validNumericTypes.begin(), validNumericTypes.end(),
childType->getLogicalTypeID()) == validNumericTypes.end()) {
throw common::BinderException(
"The child type of a fixed list must be a numeric type. Given: " +
common::LogicalTypeUtils::dataTypeToString(*childType) + ".");
throw BinderException("The child type of a fixed list must be a numeric type. Given: " +
LogicalTypeUtils::dataTypeToString(*childType) + ".");
}
if (numElementsInList == 0) {
// Note: the parser already guarantees that the number of elements is a non-negative
// number. However, we still need to check whether the number of elements is 0.
throw common::BinderException(
throw BinderException(
"The number of elements in a fixed list must be greater than 0. Given: " +
std::to_string(numElementsInList) + ".");
}
auto numElementsPerPage = storage::PageUtils::getNumElementsInAPage(
storage::StorageUtils::getDataTypeSize(boundType), true /* hasNull */);
if (numElementsPerPage == 0) {
throw common::BinderException(
throw BinderException(
StringUtils::string_format("Cannot store a fixed list of size {} in a page.",
storage::StorageUtils::getDataTypeSize(boundType)));
}
}
return std::make_unique<common::LogicalType>(boundType);
return std::make_unique<LogicalType>(boundType);
}

} // namespace binder
Expand Down
51 changes: 23 additions & 28 deletions src/binder/bind/bind_graph_pattern.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,23 +71,23 @@

std::shared_ptr<Expression> Binder::createPathExpression(
const std::string& pathName, const expression_vector& children) {
std::unordered_set<common::table_id_t> nodeTableIDSet;
std::unordered_set<common::table_id_t> relTableIDSet;
std::unordered_set<table_id_t> nodeTableIDSet;
std::unordered_set<table_id_t> relTableIDSet;
for (auto& child : children) {
switch (child->getDataType().getLogicalTypeID()) {
case common::LogicalTypeID::NODE: {
case LogicalTypeID::NODE: {
auto node = (NodeExpression*)child.get();
for (auto tableID : node->getTableIDs()) {
nodeTableIDSet.insert(tableID);
}
} break;
case common::LogicalTypeID::REL: {
case LogicalTypeID::REL: {
auto rel = (RelExpression*)child.get();
for (auto tableID : rel->getTableIDs()) {
relTableIDSet.insert(tableID);
}
} break;
case common::LogicalTypeID::RECURSIVE_REL: {
case LogicalTypeID::RECURSIVE_REL: {
auto recursiveRel = (RelExpression*)child.get();
auto recursiveInfo = recursiveRel->getRecursiveInfo();
for (auto tableID : recursiveInfo->node->getTableIDs()) {
Expand All @@ -101,10 +101,9 @@
throw NotImplementedException("Binder::createPathExpression");
}
}
auto nodeTableIDs =
std::vector<common::table_id_t>{nodeTableIDSet.begin(), nodeTableIDSet.end()};
auto nodeTableIDs = std::vector<table_id_t>{nodeTableIDSet.begin(), nodeTableIDSet.end()};
std::sort(nodeTableIDs.begin(), nodeTableIDs.end());
auto relTableIDs = std::vector<common::table_id_t>{relTableIDSet.begin(), relTableIDSet.end()};
auto relTableIDs = std::vector<table_id_t>{relTableIDSet.begin(), relTableIDSet.end()};
std::sort(relTableIDs.begin(), relTableIDs.end());
auto node = createQueryNode(InternalKeyword::ANONYMOUS, nodeTableIDs);
auto rel = createNonRecursiveQueryRel(
Expand Down Expand Up @@ -215,7 +214,7 @@
directionType = RelDirectionType::BOTH;
} break;
default:
throw common::NotImplementedException("Binder::bindQueryRel");
throw NotImplementedException("Binder::bindQueryRel");

Check warning on line 217 in src/binder/bind/bind_graph_pattern.cpp

View check run for this annotation

Codecov / codecov/patch

src/binder/bind/bind_graph_pattern.cpp#L217

Added line #L217 was not covered by tests
}
// bind variable length
std::shared_ptr<RelExpression> queryRel;
Expand Down Expand Up @@ -249,7 +248,7 @@
}

std::shared_ptr<RelExpression> Binder::createNonRecursiveQueryRel(const std::string& parsedName,
const std::vector<common::table_id_t>& tableIDs, std::shared_ptr<NodeExpression> srcNode,
const std::vector<table_id_t>& tableIDs, std::shared_ptr<NodeExpression> srcNode,
std::shared_ptr<NodeExpression> dstNode, RelDirectionType directionType) {
auto queryRel = make_shared<RelExpression>(LogicalType(LogicalTypeID::REL),
getUniqueExpressionName(parsedName), parsedName, tableIDs, std::move(srcNode),
Expand All @@ -269,27 +268,25 @@
relFields.push_back(std::make_unique<StructField>(
propertyExpression->getPropertyName(), propertyExpression->getDataType().copy()));
}
common::RelType::setExtraTypeInfo(
RelType::setExtraTypeInfo(
queryRel->getDataTypeReference(), std::make_unique<StructTypeInfo>(std::move(relFields)));
return queryRel;
}

std::shared_ptr<RelExpression> Binder::createRecursiveQueryRel(const parser::RelPattern& relPattern,
const std::vector<common::table_id_t>& tableIDs, std::shared_ptr<NodeExpression> srcNode,
const std::vector<table_id_t>& tableIDs, std::shared_ptr<NodeExpression> srcNode,
std::shared_ptr<NodeExpression> dstNode, RelDirectionType directionType) {
std::unordered_set<common::table_id_t> recursiveNodeTableIDs;
std::unordered_set<table_id_t> recursiveNodeTableIDs;
for (auto relTableID : tableIDs) {
auto relTableSchema = catalog.getReadOnlyVersion()->getRelTableSchema(relTableID);
recursiveNodeTableIDs.insert(relTableSchema->getSrcTableID());
recursiveNodeTableIDs.insert(relTableSchema->getDstTableID());
}
auto recursiveRelPatternInfo = relPattern.getRecursiveInfo();
auto tmpNode = createQueryNode(
InternalKeyword::ANONYMOUS, std::vector<common::table_id_t>{recursiveNodeTableIDs.begin(),
recursiveNodeTableIDs.end()});
auto tmpNodeCopy = createQueryNode(
InternalKeyword::ANONYMOUS, std::vector<common::table_id_t>{recursiveNodeTableIDs.begin(),
recursiveNodeTableIDs.end()});
auto tmpNode = createQueryNode(InternalKeyword::ANONYMOUS,
std::vector<table_id_t>{recursiveNodeTableIDs.begin(), recursiveNodeTableIDs.end()});
auto tmpNodeCopy = createQueryNode(InternalKeyword::ANONYMOUS,
std::vector<table_id_t>{recursiveNodeTableIDs.begin(), recursiveNodeTableIDs.end()});
auto prevScope = saveScope();
scope->clear();
auto tmpRel = createNonRecursiveQueryRel(
Expand Down Expand Up @@ -394,8 +391,8 @@
}

std::shared_ptr<NodeExpression> Binder::createQueryNode(
const std::string& parsedName, const std::vector<common::table_id_t>& tableIDs) {
auto queryNode = make_shared<NodeExpression>(LogicalType(common::LogicalTypeID::NODE),
const std::string& parsedName, const std::vector<table_id_t>& tableIDs) {
auto queryNode = make_shared<NodeExpression>(LogicalType(LogicalTypeID::NODE),
getUniqueExpressionName(parsedName), parsedName, tableIDs);
queryNode->setAlias(parsedName);
bindQueryNodeProperties(*queryNode);
Expand All @@ -411,7 +408,7 @@
nodeFields.push_back(std::make_unique<StructField>(
propertyExpression->getPropertyName(), propertyExpression->getDataType().copy()));
}
common::NodeType::setExtraTypeInfo(
NodeType::setExtraTypeInfo(
queryNode->getDataTypeReference(), std::make_unique<StructTypeInfo>(std::move(nodeFields)));
return queryNode;
}
Expand All @@ -434,10 +431,9 @@
}
}

std::vector<common::table_id_t> Binder::bindNodeTableIDs(
const std::vector<std::string>& tableNames) {
std::vector<table_id_t> Binder::bindNodeTableIDs(const std::vector<std::string>& tableNames) {
if (catalog.getReadOnlyVersion()->getNodeTableIDs().empty()) {
throw common::BinderException("No node table exists in database.");
throw BinderException("No node table exists in database.");
}
std::unordered_set<table_id_t> tableIDs;
if (tableNames.empty()) {
Expand All @@ -454,10 +450,9 @@
return result;
}

std::vector<common::table_id_t> Binder::bindRelTableIDs(
const std::vector<std::string>& tableNames) {
std::vector<table_id_t> Binder::bindRelTableIDs(const std::vector<std::string>& tableNames) {
if (catalog.getReadOnlyVersion()->getRelTableIDs().empty()) {
throw common::BinderException("No rel table exists in database.");
throw BinderException("No rel table exists in database.");
}
std::unordered_set<table_id_t> tableIDs;
if (tableNames.empty()) {
Expand Down
8 changes: 4 additions & 4 deletions src/binder/bind/bind_projection_clause.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ static bool isAggregateExpression(
if (expression->hasAlias() && scope->contains(expression->getAlias())) {
return false;
}
if (expression->expressionType == common::AGGREGATE_FUNCTION) {
if (expression->expressionType == AGGREGATE_FUNCTION) {
return true;
}
for (auto& child : ExpressionChildrenCollector::collectChildren(*expression)) {
Expand All @@ -81,7 +81,7 @@ static expression_vector getAggregateExpressions(
if (expression->hasAlias() && scope->contains(expression->getAlias())) {
return result;
}
if (expression->expressionType == common::AGGREGATE_FUNCTION) {
if (expression->expressionType == AGGREGATE_FUNCTION) {
result.push_back(expression);
return result;
}
Expand Down Expand Up @@ -165,7 +165,7 @@ expression_vector Binder::bindProjectionExpressions(
const parsed_expression_vector& projectionExpressions) {
expression_vector result;
for (auto& expression : projectionExpressions) {
if (expression->getExpressionType() == common::ExpressionType::STAR) {
if (expression->getExpressionType() == ExpressionType::STAR) {
// Rewrite star expression as all expression in scope.
if (scope->empty()) {
throw BinderException(
Expand All @@ -174,7 +174,7 @@ expression_vector Binder::bindProjectionExpressions(
for (auto& expr : scope->getExpressions()) {
result.push_back(expr);
}
} else if (expression->getExpressionType() == common::ExpressionType::PROPERTY) {
} else if (expression->getExpressionType() == ExpressionType::PROPERTY) {
auto propertyExpression = (ParsedPropertyExpression*)expression.get();
if (propertyExpression->isStar()) {
// Rewrite property star expression
Expand Down
4 changes: 2 additions & 2 deletions src/binder/bind/bind_reading_clause.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,15 @@ std::unique_ptr<BoundReadingClause> Binder::bindUnwindClause(const ReadingClause
boundExpression =
ExpressionBinder::implicitCastIfNecessary(boundExpression, LogicalTypeID::VAR_LIST);
auto aliasExpression = createVariable(
unwindClause.getAlias(), *common::VarListType::getChildType(&boundExpression->dataType));
unwindClause.getAlias(), *VarListType::getChildType(&boundExpression->dataType));
return make_unique<BoundUnwindClause>(std::move(boundExpression), std::move(aliasExpression));
}

std::unique_ptr<BoundReadingClause> Binder::bindInQueryCall(const ReadingClause& readingClause) {
auto& callStatement = reinterpret_cast<const parser::InQueryCallClause&>(readingClause);
auto tableFunctionDefinition =
catalog.getBuiltInTableFunction()->mathTableFunction(callStatement.getFuncName());
auto inputValues = std::vector<common::Value>{};
auto inputValues = std::vector<Value>{};
for (auto& parameter : callStatement.getParameters()) {
auto boundExpr = expressionBinder.bindLiteralExpression(*parameter);
inputValues.push_back(*reinterpret_cast<LiteralExpression*>(boundExpr.get())->getValue());
Expand Down
5 changes: 3 additions & 2 deletions src/binder/bind/bind_standalone_call.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@
#include "binder/bound_standalone_call.h"
#include "parser/standalone_call.h"

using namespace kuzu::common;

namespace kuzu {
namespace binder {

std::unique_ptr<BoundStatement> Binder::bindStandaloneCall(const parser::Statement& statement) {
auto& callStatement = reinterpret_cast<const parser::StandaloneCall&>(statement);
auto option = main::DBConfig::getOptionByName(callStatement.getOptionName());
if (option == nullptr) {
throw common::BinderException{
"Invalid option name: " + callStatement.getOptionName() + "."};
throw BinderException{"Invalid option name: " + callStatement.getOptionName() + "."};
}
auto optionValue = expressionBinder.bindLiteralExpression(*callStatement.getOptionValue());
// TODO(Ziyi): add casting rule for option value.
Expand Down
5 changes: 3 additions & 2 deletions src/binder/bind_expression/bind_case_expression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "binder/expression_binder.h"
#include "parser/expression/parsed_case_expression.h"

using namespace kuzu::common;
using namespace kuzu::parser;

namespace kuzu {
Expand Down Expand Up @@ -33,7 +34,7 @@ std::shared_ptr<Expression> ExpressionBinder::bindCaseExpression(
boundWhen = implicitCastIfNecessary(boundWhen, boundCase->dataType);
// rewrite "CASE a.age WHEN 1" as "CASE WHEN a.age = 1"
boundWhen = bindComparisonExpression(
common::EQUALS, std::vector<std::shared_ptr<Expression>>{boundCase, boundWhen});
EQUALS, std::vector<std::shared_ptr<Expression>>{boundCase, boundWhen});
auto boundThen = bindExpression(*caseAlternative->thenExpression);
boundThen = implicitCastIfNecessary(boundThen, outDataType);
boundCaseExpression->addCaseAlternative(boundWhen, boundThen);
Expand All @@ -42,7 +43,7 @@ std::shared_ptr<Expression> ExpressionBinder::bindCaseExpression(
for (auto i = 0u; i < parsedCaseExpression.getNumCaseAlternative(); ++i) {
auto caseAlternative = parsedCaseExpression.getCaseAlternative(i);
auto boundWhen = bindExpression(*caseAlternative->whenExpression);
boundWhen = implicitCastIfNecessary(boundWhen, common::LogicalTypeID::BOOL);
boundWhen = implicitCastIfNecessary(boundWhen, LogicalTypeID::BOOL);
auto boundThen = bindExpression(*caseAlternative->thenExpression);
boundThen = implicitCastIfNecessary(boundThen, outDataType);
boundCaseExpression->addCaseAlternative(boundWhen, boundThen);
Expand Down
10 changes: 5 additions & 5 deletions src/binder/bind_expression/bind_comparison_expression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "binder/expression/function_expression.h"
#include "binder/expression_binder.h"

using namespace kuzu::common;
using namespace kuzu::parser;

namespace kuzu {
Expand All @@ -18,10 +19,10 @@ std::shared_ptr<Expression> ExpressionBinder::bindComparisonExpression(
}

std::shared_ptr<Expression> ExpressionBinder::bindComparisonExpression(
common::ExpressionType expressionType, const expression_vector& children) {
ExpressionType expressionType, const expression_vector& children) {
auto builtInFunctions = binder->catalog.getBuiltInVectorFunctions();
auto functionName = expressionTypeToString(expressionType);
std::vector<common::LogicalType> childrenTypes;
std::vector<LogicalType> childrenTypes;
for (auto& child : children) {
childrenTypes.push_back(child->dataType);
}
Expand All @@ -32,7 +33,7 @@ std::shared_ptr<Expression> ExpressionBinder::bindComparisonExpression(
implicitCastIfNecessary(children[i], function->parameterTypeIDs[i]));
}
auto bindData =
std::make_unique<function::FunctionBindData>(common::LogicalType(function->returnTypeID));
std::make_unique<function::FunctionBindData>(LogicalType(function->returnTypeID));
auto uniqueExpressionName =
ScalarFunctionExpression::getUniqueName(function->name, childrenAfterCast);
return make_shared<ScalarFunctionExpression>(functionName, expressionType, std::move(bindData),
Expand All @@ -42,8 +43,7 @@ std::shared_ptr<Expression> ExpressionBinder::bindComparisonExpression(

std::shared_ptr<Expression> ExpressionBinder::createEqualityComparisonExpression(
std::shared_ptr<Expression> left, std::shared_ptr<Expression> right) {
return bindComparisonExpression(
common::EQUALS, expression_vector{std::move(left), std::move(right)});
return bindComparisonExpression(EQUALS, expression_vector{std::move(left), std::move(right)});
}

} // namespace binder
Expand Down
Loading
Loading