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

Remove spdlog/fmt from header #1451

Merged
merged 1 commit into from
Apr 6, 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
1 change: 1 addition & 0 deletions src/binder/bind/bind_copy.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "binder/binder.h"
#include "binder/copy/bound_copy.h"
#include "binder/expression/literal_expression.h"
#include "common/string_utils.h"
#include "parser/copy_csv/copy_csv.h"

using namespace kuzu::common;
Expand Down
1 change: 1 addition & 0 deletions src/binder/bind/bind_ddl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "binder/ddl/bound_drop_table.h"
#include "binder/ddl/bound_rename_property.h"
#include "binder/ddl/bound_rename_table.h"
#include "common/string_utils.h"
#include "parser/ddl/add_property.h"
#include "parser/ddl/create_node_clause.h"
#include "parser/ddl/create_rel_clause.h"
Expand Down
1 change: 1 addition & 0 deletions src/binder/bind_expression/bind_function_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/literal_expression.h"
#include "binder/expression_binder.h"
#include "common/string_utils.h"
#include "function/schema/vector_label_operations.h"
#include "parser/expression/parsed_function_expression.h"

Expand Down
1 change: 1 addition & 0 deletions src/binder/binder.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "binder/binder.h"

#include "binder/expression/variable_expression.h"
#include "common/string_utils.h"

using namespace kuzu::common;
using namespace kuzu::parser;
Expand Down
1 change: 1 addition & 0 deletions src/catalog/catalog.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "catalog/catalog.h"

#include "common/string_utils.h"
#include "spdlog/spdlog.h"
#include "storage/storage_utils.h"

Expand Down
2 changes: 1 addition & 1 deletion src/catalog/catalog_structs.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "catalog/catalog_structs.h"

#include "common/exception.h"
#include "common/utils.h"
#include "common/string_utils.h"

using namespace kuzu::common;

Expand Down
3 changes: 2 additions & 1 deletion src/common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ add_library(kuzu_common
null_mask.cpp
profiler.cpp
type_utils.cpp
utils.cpp)
utils.cpp
string_utils.cpp)

set(ALL_OBJECT_FILES
${ALL_OBJECT_FILES} $<TARGET_OBJECTS:kuzu_common>
Expand Down
1 change: 1 addition & 0 deletions src/common/assert.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "common/assert.h"

#include "common/exception.h"
#include "common/string_utils.h"
#include "common/utils.h"

namespace kuzu {
Expand Down
1 change: 1 addition & 0 deletions src/common/file_utils.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "common/file_utils.h"

#include "common/exception.h"
#include "common/string_utils.h"
#include "common/utils.h"

namespace kuzu {
Expand Down
1 change: 1 addition & 0 deletions src/common/logging_level_utils.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "common/logging_level_utils.h"

#include "common/string_utils.h"
#include "common/utils.h"

namespace kuzu {
Expand Down
23 changes: 23 additions & 0 deletions src/common/string_utils.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include "common/string_utils.h"

#include <vector>

namespace kuzu {
namespace common {

std::vector<std::string> StringUtils::split(
const std::string& input, const std::string& delimiter) {
auto result = std::vector<std::string>();
auto prevPos = 0u;
auto currentPos = input.find(delimiter, prevPos);
while (currentPos != std::string::npos) {
result.push_back(input.substr(prevPos, currentPos - prevPos));
prevPos = currentPos + 1;
currentPos = input.find(delimiter, prevPos);
}
result.push_back(input.substr(prevPos));
return result;
}

} // namespace common
} // namespace kuzu
2 changes: 1 addition & 1 deletion src/common/type_utils.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "common/type_utils.h"

#include "common/exception.h"
#include "common/utils.h"
#include "common/string_utils.h"

namespace kuzu {
namespace common {
Expand Down
1 change: 1 addition & 0 deletions src/common/types/date_t.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include "common/assert.h"
#include "common/exception.h"
#include "common/string_utils.h"
#include "common/types/cast_helpers.h"
#include "common/types/timestamp_t.h"
#include "common/utils.h"
Expand Down
1 change: 1 addition & 0 deletions src/common/types/dtime_t.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "common/types/dtime_t.h"

#include "common/exception.h"
#include "common/string_utils.h"
#include "common/types/cast_helpers.h"
#include "common/types/date_t.h"
#include "common/utils.h"
Expand Down
1 change: 1 addition & 0 deletions src/common/types/interval_t.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "common/types/interval_t.h"

#include "common/exception.h"
#include "common/string_utils.h"
#include "common/types/cast_helpers.h"
#include "common/types/timestamp_t.h"
#include "common/utils.h"
Expand Down
2 changes: 2 additions & 0 deletions src/common/types/value.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "common/types/value.h"

#include "common/string_utils.h"

namespace kuzu {
namespace common {

Expand Down
15 changes: 0 additions & 15 deletions src/common/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,20 +59,5 @@ std::string LoggerUtils::getLoggerName(LoggerConstants::LoggerEnum loggerEnum) {
}
}
}

std::vector<std::string> StringUtils::split(
const std::string& input, const std::string& delimiter) {
auto result = std::vector<std::string>();
auto prevPos = 0u;
auto currentPos = input.find(delimiter, prevPos);
while (currentPos != std::string::npos) {
result.push_back(input.substr(prevPos, currentPos - prevPos));
prevPos = currentPos + 1;
currentPos = input.find(delimiter, prevPos);
}
result.push_back(input.substr(prevPos));
return result;
}

} // namespace common
} // namespace kuzu
45 changes: 45 additions & 0 deletions src/include/common/string_utils.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#pragma once

#include <algorithm>
#include <cstring>
#include <sstream>
#include <string>

#include "spdlog/fmt/fmt.h"

namespace kuzu {
namespace common {

class StringUtils {

public:
template<typename... Args>
inline static std::string string_format(const std::string& format, Args... args) {
return fmt::format(fmt::runtime(format), args...);
}

static std::vector<std::string> split(const std::string& input, const std::string& delimiter);

static void toUpper(std::string& input) {
std::transform(input.begin(), input.end(), input.begin(), ::toupper);
}

static void toLower(std::string& input) {
std::transform(input.begin(), input.end(), input.begin(), ::tolower);
}

static bool CharacterIsSpace(char c) {
return c == ' ' || c == '\t' || c == '\n' || c == '\v' || c == '\f' || c == '\r';
}

static bool CharacterIsDigit(char c) { return c >= '0' && c <= '9'; }

static std::string getLongStringErrorMessage(
const char* strToInsert, uint64_t maxAllowedStrSize) {
return string_format("Maximum length of strings is {}. Input string's length is {}.",
maxAllowedStrSize, strlen(strToInsert), strToInsert);
}
};

} // namespace common
} // namespace kuzu
32 changes: 0 additions & 32 deletions src/include/common/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

#include "common/constants.h"
#include "exception.h"
#include "spdlog/fmt/fmt.h"

namespace spdlog {
class logger;
Expand All @@ -31,37 +30,6 @@ class LoggerUtils {
static std::string getLoggerName(LoggerConstants::LoggerEnum loggerEnum);
};

class StringUtils {

public:
template<typename... Args>
inline static std::string string_format(const std::string& format, Args... args) {
return fmt::format(fmt::runtime(format), args...);
}

static std::vector<std::string> split(const std::string& input, const std::string& delimiter);

static void toUpper(std::string& input) {
std::transform(input.begin(), input.end(), input.begin(), ::toupper);
}

static void toLower(std::string& input) {
std::transform(input.begin(), input.end(), input.begin(), ::tolower);
}

static bool CharacterIsSpace(char c) {
return c == ' ' || c == '\t' || c == '\n' || c == '\v' || c == '\f' || c == '\r';
}

static bool CharacterIsDigit(char c) { return c >= '0' && c <= '9'; }

static std::string getLongStringErrorMessage(
const char* strToInsert, uint64_t maxAllowedStrSize) {
return string_format("Maximum length of strings is {}. Input string's length is {}.",
maxAllowedStrSize, strlen(strToInsert), strToInsert);
}
};

template<typename FROM, typename TO>
std::unique_ptr<TO> ku_static_unique_pointer_cast(std::unique_ptr<FROM>&& old) {
return std::unique_ptr<TO>{static_cast<TO*>(old.release())};
Expand Down
4 changes: 2 additions & 2 deletions src/include/function/hash/hash_operations.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ inline common::hash_t combineHashScalar(common::hash_t a, common::hash_t b) {
struct Hash {
template<class T>
static inline void operation(const T& key, common::hash_t& result) {
throw common::RuntimeException(common::StringUtils::string_format(
"Hash type: {} is not supported.", typeid(T).name()));
throw common::RuntimeException(
"Hash type: " + std::string(typeid(T).name()) + " is not supported.");
}

template<class T>
Expand Down
9 changes: 1 addition & 8 deletions src/include/storage/storage_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,7 @@ struct StorageVersionInfo {
return {{"0.0.3", 1}};
}

static storage_version_t getStorageVersion() {
auto storageVersionInfo = getStorageVersionInfo();
if (!storageVersionInfo.contains(KUZU_STORAGE_VERSION)) {
throw common::RuntimeException(common::StringUtils::string_format(
"Invalid storage version name: {}", KUZU_STORAGE_VERSION));
}
return storageVersionInfo.at(KUZU_STORAGE_VERSION);
}
static storage_version_t getStorageVersion();

static constexpr const char* MAGIC_BYTES = "KUZU";
};
Expand Down
62 changes: 12 additions & 50 deletions src/include/storage/storage_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,23 +76,11 @@ struct PageUtils {
class StorageUtils {

public:
static inline std::string getNodeIndexFName(const std::string& directory,
const common::table_id_t& tableID, common::DBFileType dbFileType) {
auto fName = common::StringUtils::string_format("n-{}", tableID);
return appendWALFileSuffixIfNecessary(
common::FileUtils::joinPath(
directory, fName + common::StorageConstants::INDEX_FILE_SUFFIX),
dbFileType);
}
static std::string getNodeIndexFName(const std::string& directory,
const common::table_id_t& tableID, common::DBFileType dbFileType);

static inline std::string getNodePropertyColumnFName(const std::string& directory,
const common::table_id_t& tableID, uint32_t propertyID, common::DBFileType dbFileType) {
auto fName = common::StringUtils::string_format("n-{}-{}", tableID, propertyID);
return appendWALFileSuffixIfNecessary(
common::FileUtils::joinPath(
directory, fName + common::StorageConstants::COLUMN_FILE_SUFFIX),
dbFileType);
}
static std::string getNodePropertyColumnFName(const std::string& directory,
const common::table_id_t& tableID, uint32_t propertyID, common::DBFileType dbFileType);

static inline StorageStructureIDAndFName getNodePropertyColumnStructureIDAndFName(
const std::string& directory, const catalog::Property& property) {
Expand Down Expand Up @@ -129,15 +117,9 @@ class StorageUtils {
fName);
}

static inline std::string getAdjColumnFName(const std::string& directory,
static std::string getAdjColumnFName(const std::string& directory,
const common::table_id_t& relTableID, const common::RelDirection& relDirection,
common::DBFileType dbFileType) {
auto fName = common::StringUtils::string_format("r-{}-{}", relTableID, relDirection);
return appendWALFileSuffixIfNecessary(
common::FileUtils::joinPath(
directory, fName + common::StorageConstants::COLUMN_FILE_SUFFIX),
dbFileType);
}
common::DBFileType dbFileType);

static inline StorageStructureIDAndFName getAdjColumnStructureIDAndFName(
const std::string& directory, const common::table_id_t& relTableID,
Expand All @@ -148,26 +130,13 @@ class StorageUtils {
StorageStructureID::newAdjColumnID(relTableID, relDirection), fName);
}

static inline std::string getAdjListsFName(const std::string& directory,
static std::string getAdjListsFName(const std::string& directory,
const common::table_id_t& relTableID, const common::RelDirection& relDirection,
common::DBFileType dbFileType) {
auto fName = common::StringUtils::string_format("r-{}-{}", relTableID, relDirection);
return appendWALFileSuffixIfNecessary(
common::FileUtils::joinPath(
directory, fName + common::StorageConstants::LISTS_FILE_SUFFIX),
dbFileType);
}
common::DBFileType dbFileType);

static inline std::string getRelPropertyColumnFName(const std::string& directory,
static std::string getRelPropertyColumnFName(const std::string& directory,
const common::table_id_t& relTableID, const common::RelDirection& relDirection,
const uint32_t propertyID, common::DBFileType dbFileType) {
auto fName =
common::StringUtils::string_format("r-{}-{}-{}", relTableID, relDirection, propertyID);
return appendWALFileSuffixIfNecessary(
common::FileUtils::joinPath(
directory, fName + common::StorageConstants::COLUMN_FILE_SUFFIX),
dbFileType);
}
uint32_t propertyID, common::DBFileType dbFileType);

static inline StorageStructureIDAndFName getRelPropertyColumnStructureIDAndFName(
const std::string& directory, const common::table_id_t& relTableID,
Expand All @@ -179,16 +148,9 @@ class StorageUtils {
fName);
}

static inline std::string getRelPropertyListsFName(const std::string& directory,
static std::string getRelPropertyListsFName(const std::string& directory,
const common::table_id_t& relTableID, const common::RelDirection& relDirection,
const uint32_t propertyID, common::DBFileType dbFileType) {
auto fName =
common::StringUtils::string_format("r-{}-{}-{}", relTableID, relDirection, propertyID);
return appendWALFileSuffixIfNecessary(
common::FileUtils::joinPath(
directory, fName + common::StorageConstants::LISTS_FILE_SUFFIX),
dbFileType);
}
uint32_t propertyID, common::DBFileType dbFileType);

static inline std::string getListHeadersFName(std::string baseListFName) {
return appendSuffixOrInsertBeforeWALSuffix(std::move(baseListFName), ".headers");
Expand Down
2 changes: 1 addition & 1 deletion src/parser/antlr_parser/parser_error_listener.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "parser/antlr_parser/parser_error_listener.h"

#include "common/exception.h"
#include "common/utils.h"
#include "common/string_utils.h"

using namespace antlr4;
using namespace kuzu::common;
Expand Down
Loading