Skip to content

Commit

Permalink
refactor to use wrapper function to wrap all the codes in
Browse files Browse the repository at this point in the history
cast_string_to_function.h
  • Loading branch information
AEsir777 committed Oct 26, 2023
1 parent ecf1dd2 commit d5ebb51
Show file tree
Hide file tree
Showing 37 changed files with 1,748 additions and 1,678 deletions.
12 changes: 6 additions & 6 deletions dataset/load-from-test/fixed_list/fixed_list_correct.csv
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"[23123.4342133123]"
"[-4321312.42343255]"
"[43213123454.34324]"
"[-1.344455]"
"[-4212.4234]"
"[-2]"
"[23123.4342133123]","T","1 month 2 days"
"[-4321312.42343255]",true,1 year 3 days
"[43213123454.34324]",false,12 years 3 months 30 days
"[-1.344455]",F,3 days
"[-4212.4234]",0,null
"[-2]",1,10 months
6 changes: 3 additions & 3 deletions dataset/load-from-test/fixed_list/fixed_list_int64.csv
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
"[4234234, 4234535, -3242342]"
"[4234234, 4234535, 0]"
"[4234234, 0, -3242342]"
"[4234234, 4234535, -3242342]","2022-06-06","2022-11-22 15:12:22"
"[4234234, 4234535, 0]","2013-02-21","1970-01-01 00:00:00.004666-10"
"[4234234, 0, -3242342]","2019-12-30","1970-01-01 10:11:00.004666+10:11"
6 changes: 3 additions & 3 deletions src/binder/bind/bind_graph_pattern.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include "catalog/rel_table_schema.h"
#include "common/exception/binder.h"
#include "common/string_format.h"
#include "function/cast/cast_utils.h"
#include "function/cast/functions/cast_string_to_functions.h"
#include "main/client_context.h"

using namespace kuzu::common;
Expand Down Expand Up @@ -428,11 +428,11 @@ std::pair<uint64_t, uint64_t> Binder::bindVariableLengthRelBound(
const kuzu::parser::RelPattern& relPattern) {
auto recursiveInfo = relPattern.getRecursiveInfo();
uint32_t lowerBound;
function::simpleIntegerCast(
function::CastStringToTypes::operation(
recursiveInfo->lowerBound.c_str(), recursiveInfo->lowerBound.length(), lowerBound);
auto upperBound = clientContext->varLengthExtendMaxDepth;
if (!recursiveInfo->upperBound.empty()) {
function::simpleIntegerCast(
function::CastStringToTypes::operation(
recursiveInfo->upperBound.c_str(), recursiveInfo->upperBound.length(), upperBound);
}
if (lowerBound > upperBound) {
Expand Down
8 changes: 4 additions & 4 deletions src/c_api/value.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include "common/types/value/node.h"
#include "common/types/value/recursive_rel.h"
#include "common/types/value/rel.h"
#include "function/cast/cast_functions.h"
#include "function/cast/functions/cast_string_to_functions.h"
#include "main/kuzu.h"

using namespace kuzu::common;
Expand Down Expand Up @@ -269,10 +269,10 @@ kuzu_int128_t kuzu_int128_t_from_string(const char* str) {
int128_t int128_val = 0;
kuzu_int128_t c_int128;
try {
kuzu::function::CastToInt128::operation(str, int128_val);
kuzu::function::CastStringToTypes::operation(str, strlen(str), int128_val);
c_int128.low = int128_val.low;
c_int128.high = int128_val.high;
} catch (kuzu::common::ConversionException& e) {
} catch (ConversionException& e) {
c_int128.low = 0;
c_int128.high = 0;
}
Expand All @@ -283,7 +283,7 @@ char* kuzu_int128_t_to_string(kuzu_int128_t int128_val) {
int128_t c_int128;
c_int128.low = int128_val.low;
c_int128.high = int128_val.high;
return convertToOwnedCString(kuzu::common::Int128_t::ToString(c_int128));
return convertToOwnedCString(TypeUtils::toString(c_int128));
}
// TODO: bind all int128_t supported functions

Expand Down
3 changes: 2 additions & 1 deletion src/function/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ add_library(kuzu_function
built_in_aggregate_functions.cpp
built_in_vector_functions.cpp
built_in_table_functions.cpp
cast_utils.cpp
cast_string_non_nested_functions.cpp
cast_string_to_functions.cpp
comparison_functions.cpp
find_function.cpp
scalar_macro_function.cpp
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#include "function/cast/cast_utils.h"
#include "function/cast/functions/cast_string_non_nested_functions.h"

#include "common/string_format.h"

namespace kuzu {
namespace function {
Expand Down Expand Up @@ -48,8 +50,8 @@ bool tryCastToBool(const char* input, uint64_t len, bool& result) {

void 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.");
throw common::ConversionException{
common::stringFormat("Value {} is not a valid boolean", std::string{input, len})};
}
}

Expand Down
Loading

0 comments on commit d5ebb51

Please sign in to comment.