Skip to content

Commit

Permalink
commit
Browse files Browse the repository at this point in the history
  • Loading branch information
AEsir777 committed Oct 6, 2023
1 parent 3cf3539 commit 92033ec
Show file tree
Hide file tree
Showing 21 changed files with 485 additions and 256 deletions.
1 change: 1 addition & 0 deletions dataset/load-from-test/bracket_fail.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"(()"
4 changes: 4 additions & 0 deletions dataset/load-from-test/change_config.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
list | str
'(this | is a word | normal | )'|'try escape ~~'
'(escape | is escape success? ~~)'|' ~' ( ) do not need to escape sepeical | ()'
'(~~ ~' not work also this "~'" )'|'th'
1 change: 1 addition & 0 deletions dataset/load-from-test/delim_fail.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"((hello),(bdfadf),)"
1 change: 1 addition & 0 deletions dataset/load-from-test/quote_fail.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
'[23, 432, 234]'
Empty file.
7 changes: 7 additions & 0 deletions dataset/load-from-test/should_pass.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
"[[1,3,423,124,43242],[432]]"
" [ [ 1 ,3, 423 , 124,43242 ] , [ 432 ]]"
"[ [ 1 ,3, 423 , 124,43242 ] , [432]] "
"[,[], [1, 2, 3]]"
"[null, NULL, Null, nUll, nuLl, nulL, nuLL, NUll, NuLl, NulL, [1, 2, 3]]"
"[[], [], [] ]"
"[, ,]"
8 changes: 6 additions & 2 deletions src/binder/bind/bind_graph_pattern.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "catalog/rel_table_schema.h"
#include "common/exception/binder.h"
#include "common/string_utils.h"
#include "function/cast/cast_utils.h"
#include "main/client_context.h"

using namespace kuzu::common;
Expand Down Expand Up @@ -424,10 +425,13 @@ std::shared_ptr<RelExpression> Binder::createRecursiveQueryRel(const parser::Rel
std::pair<uint64_t, uint64_t> Binder::bindVariableLengthRelBound(
const kuzu::parser::RelPattern& relPattern) {
auto recursiveInfo = relPattern.getRecursiveInfo();
auto lowerBound = TypeUtils::convertToUint32(recursiveInfo->lowerBound.c_str());
uint32_t lowerBound;
function::StringCastUtils::simpleIntegerCast(recursiveInfo->lowerBound.c_str(),
recursiveInfo->lowerBound.length(), lowerBound);
auto upperBound = clientContext->varLengthExtendMaxDepth;
if (!recursiveInfo->upperBound.empty()) {
upperBound = TypeUtils::convertToUint32(recursiveInfo->upperBound.c_str());
function::StringCastUtils::simpleIntegerCast(recursiveInfo->upperBound.c_str(),
recursiveInfo->upperBound.length(), upperBound);
}
if (lowerBound > upperBound) {
throw BinderException(
Expand Down
10 changes: 0 additions & 10 deletions src/common/type_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,6 @@
namespace kuzu {
namespace common {

uint32_t TypeUtils::convertToUint32(const char* data) {
std::istringstream iss(data);
uint32_t val;
if (!(iss >> val)) {
throw ConversionException(
StringUtils::string_format("Failed to convert {} to uint32_t", data));
}
return val;
}

std::string TypeUtils::castValueToString(
const LogicalType& dataType, uint8_t* value, void* vector) {
auto valueVector = reinterpret_cast<ValueVector*>(vector);
Expand Down
1 change: 1 addition & 0 deletions src/function/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ add_library(kuzu_function
built_in_aggregate_functions.cpp
built_in_vector_functions.cpp
built_in_table_functions.cpp
cast_utils.cpp
comparison_functions.cpp
find_function.cpp
scalar_macro_function.cpp
Expand Down
57 changes: 57 additions & 0 deletions src/function/cast_utils.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#include "function/cast/cast_utils.h"

namespace kuzu {
namespace function {

bool StringCastUtils::tryCastToBool(const char* input, uint64_t len, bool& result) {
common::StringUtils::removeCStringWhiteSpaces(input, len);

switch (len) {
case 1: {
char c = std::tolower(*input);
if (c == 't' || c == '1') {
result = true;
return true;
} else if (c == 'f' || c == '0') {
result = false;
return true;
}
return false;
}
case 4: {
auto t = std::tolower(input[0]);
auto r = std::tolower(input[1]);
auto u = std::tolower(input[2]);
auto e = std::tolower(input[3]);
if (t == 't' && r == 'r' && u == 'u' && e == 'e') {
result = true;
return true;
}
return false;
}
case 5: {
auto f = std::tolower(input[0]);
auto a = std::tolower(input[1]);
auto l = std::tolower(input[2]);
auto s = std::tolower(input[3]);
auto e = std::tolower(input[4]);
if (f == 'f' && a == 'a' && l == 'l' && s == 's' && e == 'e') {
result = false;
return true;
}
return false;
}
default:
return false;
}
}

void StringCastUtils::castStringToBool(const char* input, uint64_t len, bool& result) {
if (!tryCastToBool(input, len, result)) {
throw common::ConversionException(
"Cast failed. " + std::string{input, len} + " is not in BOOL range.");
}
}

} // namespace function
} // namespace kuzu
1 change: 0 additions & 1 deletion src/include/common/type_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ namespace common {
class TypeUtils {

public:
static uint32_t convertToUint32(const char* data);
template<typename T>
static inline std::string toString(const T& val, void* valueVector = nullptr) {
static_assert(std::is_same<T, int64_t>::value || std::is_same<T, int32_t>::value ||
Expand Down
47 changes: 24 additions & 23 deletions src/include/function/cast/cast_functions.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

#include <cassert>

#include "cast_utils.h"
#include "common/exception/runtime.h"
#include "common/string_utils.h"
#include "common/type_utils.h"
#include "common/types/blob.h"
#include "common/vector/value_vector.h"
#include "numeric_cast.h"

namespace kuzu {
namespace function {
Expand Down Expand Up @@ -88,7 +88,8 @@ inline std::string CastToString::castToStringWithVector(

struct CastToBool {
static inline void operation(common::ku_string_t& input, bool& result) {
if (!tryCastToBool(reinterpret_cast<const char*>(input.getData()), input.len, result)) {
if (!StringCastUtils::tryCastToBool(
reinterpret_cast<const char*>(input.getData()), input.len, result)) {
throw common::ConversionException{common::StringUtils::string_format(
"Value {} is not a valid boolean", input.getAsString())};
}
Expand All @@ -107,13 +108,13 @@ struct CastToDouble {

template<>
inline void CastToDouble::operation(char*& input, double_t& result) {
doubleCast<double_t>(
StringCastUtils::doubleCast<double_t>(
input, strlen(input), result, common::LogicalType{common::LogicalTypeID::DOUBLE});
}

template<>
inline void CastToDouble::operation(common::ku_string_t& input, double_t& result) {
doubleCast<double_t>((char*)input.getData(), input.len, result,
StringCastUtils::doubleCast<double_t>((char*)input.getData(), input.len, result,
common::LogicalType{common::LogicalTypeID::DOUBLE});
}

Expand All @@ -129,13 +130,13 @@ struct CastToFloat {

template<>
inline void CastToFloat::operation(char*& input, float_t& result) {
doubleCast<float_t>(
StringCastUtils::doubleCast<float_t>(
input, strlen(input), result, common::LogicalType{common::LogicalTypeID::FLOAT});
}

template<>
inline void CastToFloat::operation(common::ku_string_t& input, float_t& result) {
doubleCast<float_t>((char*)input.getData(), input.len, result,
StringCastUtils::doubleCast<float_t>((char*)input.getData(), input.len, result,
common::LogicalType{common::LogicalTypeID::FLOAT});
}

Expand All @@ -151,13 +152,13 @@ struct CastToInt64 {

template<>
inline void CastToInt64::operation(char*& input, int64_t& result) {
simpleIntegerCast<int64_t, true>(
StringCastUtils::simpleIntegerCast<int64_t, true>(
input, strlen(input), result, common::LogicalType{common::LogicalTypeID::INT64});
}

template<>
inline void CastToInt64::operation(common::ku_string_t& input, int64_t& result) {
simpleIntegerCast<int64_t, true>((char*)input.getData(), input.len, result,
StringCastUtils::simpleIntegerCast<int64_t, true>((char*)input.getData(), input.len, result,
common::LogicalType{common::LogicalTypeID::INT64});
}

Expand All @@ -173,7 +174,7 @@ struct CastToSerial {

template<>
inline void CastToSerial::operation(common::ku_string_t& input, int64_t& result) {
simpleIntegerCast<int64_t>((char*)input.getData(), input.len, result,
StringCastUtils::simpleIntegerCast<int64_t>((char*)input.getData(), input.len, result,
common::LogicalType{common::LogicalTypeID::INT64});
}

Expand All @@ -189,13 +190,13 @@ struct CastToInt32 {

template<>
inline void CastToInt32::operation(char*& input, int32_t& result) {
simpleIntegerCast<int32_t, true>(
StringCastUtils::simpleIntegerCast<int32_t, true>(
input, strlen(input), result, common::LogicalType{common::LogicalTypeID::INT32});
}

template<>
inline void CastToInt32::operation(common::ku_string_t& input, int32_t& result) {
simpleIntegerCast<int32_t, true>((char*)input.getData(), input.len, result,
StringCastUtils::simpleIntegerCast<int32_t, true>((char*)input.getData(), input.len, result,
common::LogicalType{common::LogicalTypeID::INT32});
}

Expand All @@ -211,13 +212,13 @@ struct CastToInt16 {

template<>
inline void CastToInt16::operation(common::ku_string_t& input, int16_t& result) {
simpleIntegerCast<int16_t, true>((char*)input.getData(), input.len, result,
StringCastUtils::simpleIntegerCast<int16_t, true>((char*)input.getData(), input.len, result,
common::LogicalType{common::LogicalTypeID::INT16});
}

template<>
inline void CastToInt16::operation(char*& input, int16_t& result) {
simpleIntegerCast<int16_t, true>(
StringCastUtils::simpleIntegerCast<int16_t, true>(
input, strlen(input), result, common::LogicalType{common::LogicalTypeID::INT16});
}

Expand All @@ -233,13 +234,13 @@ struct CastToInt8 {

template<>
inline void CastToInt8::operation(common::ku_string_t& input, int8_t& result) {
simpleIntegerCast<int8_t, true>((char*)input.getData(), input.len, result,
StringCastUtils::simpleIntegerCast<int8_t, true>((char*)input.getData(), input.len, result,
common::LogicalType{common::LogicalTypeID::INT8});
}

template<>
inline void CastToInt8::operation(char*& input, int8_t& result) {
simpleIntegerCast<int8_t, true>(
StringCastUtils::simpleIntegerCast<int8_t, true>(
input, strlen(input), result, common::LogicalType{common::LogicalTypeID::INT8});
}

Expand All @@ -255,13 +256,13 @@ struct CastToUInt64 {

template<>
inline void CastToUInt64::operation(common::ku_string_t& input, uint64_t& result) {
simpleIntegerCast<uint64_t, false>((char*)input.getData(), input.len, result,
StringCastUtils::simpleIntegerCast<uint64_t, false>((char*)input.getData(), input.len, result,
common::LogicalType{common::LogicalTypeID::UINT64});
}

template<>
inline void CastToUInt64::operation(char*& input, uint64_t& result) {
simpleIntegerCast<uint64_t, false>(
StringCastUtils::simpleIntegerCast<uint64_t, false>(
input, strlen(input), result, common::LogicalType{common::LogicalTypeID::UINT64});
}

Expand All @@ -277,13 +278,13 @@ struct CastToUInt32 {

template<>
inline void CastToUInt32::operation(common::ku_string_t& input, uint32_t& result) {
simpleIntegerCast<uint32_t, false>((char*)input.getData(), input.len, result,
StringCastUtils::simpleIntegerCast<uint32_t, false>((char*)input.getData(), input.len, result,
common::LogicalType{common::LogicalTypeID::UINT32});
}

template<>
inline void CastToUInt32::operation(char*& input, uint32_t& result) {
simpleIntegerCast<uint32_t, false>(
StringCastUtils::simpleIntegerCast<uint32_t, false>(
input, strlen(input), result, common::LogicalType{common::LogicalTypeID::UINT32});
}

Expand All @@ -299,13 +300,13 @@ struct CastToUInt16 {

template<>
inline void CastToUInt16::operation(common::ku_string_t& input, uint16_t& result) {
simpleIntegerCast<uint16_t, false>((char*)input.getData(), input.len, result,
StringCastUtils::simpleIntegerCast<uint16_t, false>((char*)input.getData(), input.len, result,
common::LogicalType{common::LogicalTypeID::UINT16});
}

template<>
inline void CastToUInt16::operation(char*& input, uint16_t& result) {
simpleIntegerCast<uint16_t, false>(
StringCastUtils::simpleIntegerCast<uint16_t, false>(
input, strlen(input), result, common::LogicalType{common::LogicalTypeID::UINT16});
}

Expand All @@ -321,13 +322,13 @@ struct CastToUInt8 {

template<>
inline void CastToUInt8::operation(common::ku_string_t& input, uint8_t& result) {
simpleIntegerCast<uint8_t, false>((char*)input.getData(), input.len, result,
StringCastUtils::simpleIntegerCast<uint8_t, false>((char*)input.getData(), input.len, result,
common::LogicalType{common::LogicalTypeID::UINT8});
}

template<>
inline void CastToUInt8::operation(char*& input, uint8_t& result) {
simpleIntegerCast<uint8_t, false>(
StringCastUtils::simpleIntegerCast<uint8_t, false>(
input, strlen(input), result, common::LogicalType{common::LogicalTypeID::UINT8});
}

Expand Down
Loading

0 comments on commit 92033ec

Please sign in to comment.