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

Rework header file to get rid of using namespace #1248

Merged
merged 1 commit into from
Feb 7, 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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
14 changes: 8 additions & 6 deletions src/binder/bind/bind_copy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,25 @@
#include "binder/expression/literal_expression.h"
#include "parser/copy_csv/copy_csv.h"

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

namespace kuzu {
namespace binder {

unique_ptr<BoundStatement> Binder::bindCopy(const Statement& statement) {
std::unique_ptr<BoundStatement> Binder::bindCopy(const Statement& statement) {
auto& copyCSV = (CopyCSV&)statement;
auto catalogContent = catalog.getReadOnlyVersion();
auto tableName = copyCSV.getTableName();
validateTableExist(catalog, tableName);
auto isNodeTable = catalogContent->containNodeTable(tableName);
auto tableID = catalogContent->getTableID(tableName);
auto filePath = copyCSV.getCSVFileName();
auto csvReaderConfig = bindParsingOptions(copyCSV.getParsingOptions());
return make_unique<BoundCopy>(CopyDescription(filePath, csvReaderConfig), tableID, tableName);
}

CSVReaderConfig Binder::bindParsingOptions(
const unordered_map<string, unique_ptr<ParsedExpression>>* parsingOptions) {
const std::unordered_map<std::string, std::unique_ptr<ParsedExpression>>* parsingOptions) {
CSVReaderConfig csvReaderConfig;
for (auto& parsingOption : *parsingOptions) {
auto copyOptionName = parsingOption.first;
Expand All @@ -41,7 +43,7 @@ CSVReaderConfig Binder::bindParsingOptions(
"The value type of parsing csv option " + copyOptionName + " must be string.");
}
auto copyOptionValue =
((LiteralExpression&)(*boundCopyOptionExpression)).value->getValue<string>();
((LiteralExpression&)(*boundCopyOptionExpression)).value->getValue<std::string>();
bindStringParsingOptions(csvReaderConfig, copyOptionName, copyOptionValue);
} else {
throw BinderException("Unrecognized parsing csv option: " + copyOptionName + ".");
Expand All @@ -51,7 +53,7 @@ CSVReaderConfig Binder::bindParsingOptions(
}

void Binder::bindStringParsingOptions(
CSVReaderConfig& csvReaderConfig, const string& optionName, string& optionValue) {
CSVReaderConfig& csvReaderConfig, const std::string& optionName, std::string& optionValue) {
auto parsingOptionValue = bindParsingOptionValue(optionValue);
if (optionName == "ESCAPE") {
csvReaderConfig.escapeChar = parsingOptionValue;
Expand All @@ -66,7 +68,7 @@ void Binder::bindStringParsingOptions(
}
}

char Binder::bindParsingOptionValue(string value) {
char Binder::bindParsingOptionValue(std::string value) {
if (value.length() > 2 || (value.length() == 2 && value[0] != '\\')) {
throw BinderException("Copy csv option value can only be a single character with an "
"optional escape character.");
Expand Down
37 changes: 21 additions & 16 deletions src/binder/bind/bind_ddl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,15 @@
#include "parser/ddl/rename_property.h"
#include "parser/ddl/rename_table.h"

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

namespace kuzu {
namespace binder {

unique_ptr<BoundStatement> Binder::bindCreateNodeClause(const Statement& statement) {
auto& createNodeClause = (CreateNodeClause&)statement;
std::unique_ptr<BoundStatement> Binder::bindCreateNodeClause(const Statement& statement) {
auto& createNodeClause = (parser::CreateNodeClause&)statement;
auto tableName = createNodeClause.getTableName();
if (catalog.getReadOnlyVersion()->containTable(tableName)) {
throw BinderException("Node " + tableName + " already exists.");
Expand All @@ -31,7 +35,7 @@ unique_ptr<BoundStatement> Binder::bindCreateNodeClause(const Statement& stateme
tableName, std::move(boundPropertyNameDataTypes), primaryKeyIdx);
}

unique_ptr<BoundStatement> Binder::bindCreateRelClause(const Statement& statement) {
std::unique_ptr<BoundStatement> Binder::bindCreateRelClause(const Statement& statement) {
auto& createRelClause = (CreateRelClause&)statement;
auto tableName = createRelClause.getTableName();
if (catalog.getReadOnlyVersion()->containTable(tableName)) {
Expand All @@ -41,15 +45,15 @@ unique_ptr<BoundStatement> Binder::bindCreateRelClause(const Statement& statemen
bindPropertyNameDataTypes(createRelClause.getPropertyNameDataTypes());
auto relMultiplicity = getRelMultiplicityFromString(createRelClause.getRelMultiplicity());
auto relConnections = createRelClause.getRelConnections();
vector<pair<table_id_t, table_id_t>> srcDstTableIDs;
std::vector<std::pair<table_id_t, table_id_t>> srcDstTableIDs;
for (auto& [srcTableName, dstTableName] : relConnections) {
srcDstTableIDs.emplace_back(bindNodeTableID(srcTableName), bindNodeTableID(dstTableName));
}
return make_unique<BoundCreateRelClause>(
tableName, std::move(propertyNameDataTypes), relMultiplicity, srcDstTableIDs);
}

unique_ptr<BoundStatement> Binder::bindDropTable(const Statement& statement) {
std::unique_ptr<BoundStatement> Binder::bindDropTable(const Statement& statement) {
auto& dropTable = (DropTable&)statement;
auto tableName = dropTable.getTableName();
validateTableExist(catalog, tableName);
Expand All @@ -61,7 +65,7 @@ unique_ptr<BoundStatement> Binder::bindDropTable(const Statement& statement) {
return make_unique<BoundDropTable>(tableID, tableName);
}

unique_ptr<BoundStatement> Binder::bindRenameTable(const Statement& statement) {
std::unique_ptr<BoundStatement> Binder::bindRenameTable(const Statement& statement) {
auto renameTable = (RenameTable&)statement;
auto tableName = renameTable.getTableName();
auto catalogContent = catalog.getReadOnlyVersion();
Expand All @@ -73,7 +77,7 @@ unique_ptr<BoundStatement> Binder::bindRenameTable(const Statement& statement) {
catalogContent->getTableID(tableName), tableName, renameTable.getNewName());
}

unique_ptr<BoundStatement> Binder::bindAddProperty(const Statement& statement) {
std::unique_ptr<BoundStatement> Binder::bindAddProperty(const Statement& statement) {
auto& addProperty = (AddProperty&)statement;
auto tableName = addProperty.getTableName();
validateTableExist(catalog, tableName);
Expand All @@ -89,7 +93,7 @@ unique_ptr<BoundStatement> Binder::bindAddProperty(const Statement& statement) {
tableID, addProperty.getPropertyName(), dataType, defaultVal, tableName);
}

unique_ptr<BoundStatement> Binder::bindDropProperty(const Statement& statement) {
std::unique_ptr<BoundStatement> Binder::bindDropProperty(const Statement& statement) {
auto& dropProperty = (DropProperty&)statement;
auto tableName = dropProperty.getTableName();
validateTableExist(catalog, tableName);
Expand All @@ -106,7 +110,7 @@ unique_ptr<BoundStatement> Binder::bindDropProperty(const Statement& statement)
return make_unique<BoundDropProperty>(tableID, propertyID, tableName);
}

unique_ptr<BoundStatement> Binder::bindRenameProperty(const Statement& statement) {
std::unique_ptr<BoundStatement> Binder::bindRenameProperty(const Statement& statement) {
auto& renameProperty = (RenameProperty&)statement;
auto tableName = renameProperty.getTableName();
validateTableExist(catalog, tableName);
Expand All @@ -122,10 +126,10 @@ unique_ptr<BoundStatement> Binder::bindRenameProperty(const Statement& statement
tableID, tableName, propertyID, renameProperty.getNewName());
}

vector<PropertyNameDataType> Binder::bindPropertyNameDataTypes(
vector<pair<string, string>> propertyNameDataTypes) {
vector<PropertyNameDataType> boundPropertyNameDataTypes;
unordered_set<string> boundPropertyNames;
std::vector<PropertyNameDataType> Binder::bindPropertyNameDataTypes(
std::vector<std::pair<std::string, std::string>> propertyNameDataTypes) {
std::vector<PropertyNameDataType> boundPropertyNameDataTypes;
std::unordered_set<std::string> boundPropertyNames;
for (auto& propertyNameDataType : propertyNameDataTypes) {
if (boundPropertyNames.contains(propertyNameDataType.first)) {
throw BinderException(StringUtils::string_format(
Expand All @@ -145,7 +149,7 @@ vector<PropertyNameDataType> Binder::bindPropertyNameDataTypes(
}

uint32_t Binder::bindPrimaryKey(
string pkColName, vector<pair<string, string>> propertyNameDataTypes) {
std::string pkColName, std::vector<std::pair<std::string, std::string>> propertyNameDataTypes) {
uint32_t primaryKeyIdx = UINT32_MAX;
for (auto i = 0u; i < propertyNameDataTypes.size(); i++) {
if (propertyNameDataTypes[i].first == pkColName) {
Expand All @@ -159,13 +163,14 @@ uint32_t Binder::bindPrimaryKey(
auto primaryKey = propertyNameDataTypes[primaryKeyIdx];
StringUtils::toUpper(primaryKey.second);
// We only support INT64 and STRING column as the primary key.
if ((primaryKey.second != string("INT64")) && (primaryKey.second != string("STRING"))) {
if ((primaryKey.second != std::string("INT64")) &&
(primaryKey.second != std::string("STRING"))) {
throw BinderException("Invalid primary key type: " + primaryKey.second + ".");
}
return primaryKeyIdx;
}

property_id_t Binder::bindPropertyName(TableSchema* tableSchema, const string& propertyName) {
property_id_t Binder::bindPropertyName(TableSchema* tableSchema, const std::string& propertyName) {
for (auto& property : tableSchema->properties) {
if (property.name == propertyName) {
return property.propertyID;
Expand Down
Loading