From 9d51ca54ead7033f325170014482f13d2b998d2b Mon Sep 17 00:00:00 2001 From: AEsir777 Date: Thu, 2 Nov 2023 16:22:29 -0400 Subject: [PATCH] finish CAST(item, type) function --- .../load-from-test/union/union_correct1.csv | 9 + src/binder/bind/bind_graph_pattern.cpp | 6 +- .../bind_function_expression.cpp | 38 +- src/binder/expression/function_expression.cpp | 4 + src/c_api/value.cpp | 2 +- src/common/types/ku_string.cpp | 9 + .../function_evaluator.cpp | 17 +- src/function/built_in_functions.cpp | 25 + src/function/cast_string_to_functions.cpp | 200 +++++-- src/function/vector_blob_functions.cpp | 4 +- src/function/vector_cast_functions.cpp | 115 +++- src/function/vector_list_functions.cpp | 7 +- src/function/vector_path_functions.cpp | 12 +- src/function/vector_string_functions.cpp | 25 +- src/function/vector_struct_functions.cpp | 4 +- src/function/vector_union_functions.cpp | 4 +- .../binder/expression/function_expression.h | 4 +- src/include/binder/expression_binder.h | 6 +- src/include/common/enums/expression_type.h | 1 + src/include/common/types/ku_string.h | 1 + .../expression_evaluator/function_evaluator.h | 4 +- .../boolean/vector_boolean_functions.h | 4 +- src/include/function/built_in_function.h | 2 + .../cast/functions/cast_string_to_functions.h | 290 +++------- .../function/cast/vector_cast_functions.h | 10 +- .../comparison/vector_comparison_functions.h | 2 +- src/include/function/function.h | 8 + .../function/list/vector_list_functions.h | 2 +- .../function/null/vector_null_functions.h | 2 +- .../function/path/vector_path_functions.h | 6 +- src/include/function/scalar_function.h | 52 +- .../function/schema/vector_label_functions.h | 2 +- .../function/string/vector_string_functions.h | 29 +- .../function/struct/vector_struct_functions.h | 2 +- src/include/function/udf_function.h | 6 +- .../function/unary_function_executor.h | 27 +- .../function/union/vector_union_functions.h | 2 +- src/parser/transform/transform_expression.cpp | 8 +- .../operator/persistent/copy_to_csv.cpp | 2 +- test/main/udf_test.cpp | 12 +- test/test_files/tinysnb/cast/cast_error.test | 266 +++++++++- .../cast/cast_string_to_nested_types.test | 71 +++ test/test_files/tinysnb/function/cast.test | 498 +++++++++++++++++- test/test_files/tinysnb/function/list.test | 21 + 44 files changed, 1458 insertions(+), 363 deletions(-) create mode 100644 dataset/load-from-test/union/union_correct1.csv diff --git a/dataset/load-from-test/union/union_correct1.csv b/dataset/load-from-test/union/union_correct1.csv new file mode 100644 index 00000000000..51f0e550d66 --- /dev/null +++ b/dataset/load-from-test/union/union_correct1.csv @@ -0,0 +1,9 @@ +"false","34","255","18446744073709551615",fsdfa +" true ","432","0","-1.43241543","543fasf" +" 34234 ","4294967295","65535",-128,432 +" -42342345 ","-1","-1","-129",fasf +" T ","2022-06-06","4324.123","-32768",fds +"TRUE","2019-03-19","-12.3432","32768","" +"1","-2147483648","1970-01-01 00:00:00.004666-10","-32769",fsdxcv +"0","0","2014-05-12 12:11:59",4324254534123134324321.4343252435,"fsaf" +" F","-4325"," 14 ",18446744073709551616," dfsa" \ No newline at end of file diff --git a/src/binder/bind/bind_graph_pattern.cpp b/src/binder/bind/bind_graph_pattern.cpp index 694aeb0ec29..29919a0ec55 100644 --- a/src/binder/bind/bind_graph_pattern.cpp +++ b/src/binder/bind/bind_graph_pattern.cpp @@ -398,11 +398,13 @@ std::pair Binder::bindVariableLengthRelBound( auto recursiveInfo = relPattern.getRecursiveInfo(); uint32_t lowerBound; function::CastStringToTypes::operation( - recursiveInfo->lowerBound.c_str(), recursiveInfo->lowerBound.length(), lowerBound); + ku_string_t{recursiveInfo->lowerBound.c_str(), recursiveInfo->lowerBound.length()}, + lowerBound); auto upperBound = clientContext->varLengthExtendMaxDepth; if (!recursiveInfo->upperBound.empty()) { function::CastStringToTypes::operation( - recursiveInfo->upperBound.c_str(), recursiveInfo->upperBound.length(), upperBound); + ku_string_t{recursiveInfo->upperBound.c_str(), recursiveInfo->upperBound.length()}, + upperBound); } if (lowerBound > upperBound) { throw BinderException( diff --git a/src/binder/bind_expression/bind_function_expression.cpp b/src/binder/bind_expression/bind_function_expression.cpp index 88aed511b93..5ca09b1374f 100644 --- a/src/binder/bind_expression/bind_function_expression.cpp +++ b/src/binder/bind_expression/bind_function_expression.cpp @@ -42,6 +42,18 @@ std::shared_ptr ExpressionBinder::bindFunctionExpression( std::shared_ptr ExpressionBinder::bindScalarFunctionExpression( const ParsedExpression& parsedExpression, const std::string& functionName) { expression_vector children; + + if (functionName == "CAST") { + if (parsedExpression.getNumChildren() != 2) { + throw BinderException("Cannot match a built-in function for given function CAST"); + } + auto str = parsedExpression.getChild(1)->toString(); + auto type = binder->bindDataType(str.substr(1, str.length() - 2)); // trim off "" + children.push_back(bindExpression(*parsedExpression.getChild(0))); + + return bindScalarFunctionExpression(children, functionName, type.get()); + } + for (auto i = 0u; i < parsedExpression.getNumChildren(); ++i) { auto child = bindExpression(*parsedExpression.getChild(i)); children.push_back(std::move(child)); @@ -78,6 +90,30 @@ std::shared_ptr ExpressionBinder::bindScalarFunctionExpression( function->compileFunc, uniqueExpressionName); } +std::shared_ptr ExpressionBinder::bindScalarFunctionExpression( + const expression_vector& children, const std::string& functionName, const LogicalType* type) { + auto builtInFunctions = binder->catalog.getBuiltInFunctions(); + std::vector childrenTypes; + for (auto& child : children) { + childrenTypes.push_back(&child->dataType); + } + auto function = reinterpret_cast( + builtInFunctions->matchCastScalarFunction(functionName, childrenTypes, type)); + expression_vector childrenAfterCast; + for (auto i = 0u; i < children.size(); ++i) { + auto targetType = + function->isVarLength ? function->parameterTypeIDs[0] : function->parameterTypeIDs[i]; + childrenAfterCast.push_back(implicitCastIfNecessary(children[i], targetType)); + } + std::unique_ptr bindData; + bindData = std::make_unique(LogicalType(function->returnTypeID)); + auto uniqueExpressionName = + ScalarFunctionExpression::getUniqueName(function->name, childrenAfterCast); + return make_shared(functionName, FUNCTION, std::move(bindData), + std::move(childrenAfterCast), function->execFunc, function->selectFunc, + function->compileFunc, uniqueExpressionName); +} + std::shared_ptr ExpressionBinder::bindAggregateFunctionExpression( const ParsedExpression& parsedExpression, const std::string& functionName, bool isDistinct) { auto builtInFunctions = binder->catalog.getBuiltInFunctions(); @@ -253,7 +289,7 @@ std::shared_ptr ExpressionBinder::bindLabelFunction(const Expression auto bindData = std::make_unique(LogicalType(LogicalTypeID::STRING)); auto uniqueExpressionName = ScalarFunctionExpression::getUniqueName(LABEL_FUNC_NAME, children); - return make_shared(LABEL_FUNC_NAME, FUNCTION, std::move(bindData), + return std::make_shared(LABEL_FUNC_NAME, FUNCTION, std::move(bindData), std::move(children), execFunc, nullptr, uniqueExpressionName); } diff --git a/src/binder/expression/function_expression.cpp b/src/binder/expression/function_expression.cpp index f3f4dd21f50..d0f4e4e09a9 100644 --- a/src/binder/expression/function_expression.cpp +++ b/src/binder/expression/function_expression.cpp @@ -18,6 +18,10 @@ std::string ScalarFunctionExpression::getUniqueName( std::string ScalarFunctionExpression::toStringInternal() const { auto result = functionName + "("; result += ExpressionUtil::toString(children); + if (functionName == "CAST") { + result += ", "; + result += common::LogicalTypeUtils::dataTypeToString(bindData->resultType); + } result += ")"; return result; } diff --git a/src/c_api/value.cpp b/src/c_api/value.cpp index c8a189d5fe0..d4250e185a6 100644 --- a/src/c_api/value.cpp +++ b/src/c_api/value.cpp @@ -267,7 +267,7 @@ kuzu_int128_t kuzu_int128_t_from_string(const char* str) { int128_t int128_val = 0; kuzu_int128_t c_int128; try { - kuzu::function::CastStringToTypes::operation(str, strlen(str), int128_val); + kuzu::function::CastStringToTypes::operation(ku_string_t{str, strlen(str)}, int128_val); c_int128.low = int128_val.low; c_int128.high = int128_val.high; } catch (ConversionException& e) { diff --git a/src/common/types/ku_string.cpp b/src/common/types/ku_string.cpp index 1f81183426b..f1db589b9c0 100644 --- a/src/common/types/ku_string.cpp +++ b/src/common/types/ku_string.cpp @@ -3,6 +3,15 @@ namespace kuzu { namespace common { +ku_string_t::ku_string_t(const char* value, uint64_t length) : len(length) { + if (isShortString(length)) { + memcpy(prefix, value, length); + return; + } + overflowPtr = (uint64_t)(value); + memcpy(prefix, value, PREFIX_LENGTH); +} + void ku_string_t::set(const std::string& value) { set(value.data(), value.length()); } diff --git a/src/expression_evaluator/function_evaluator.cpp b/src/expression_evaluator/function_evaluator.cpp index 46b37062e27..b53c9a6eabc 100644 --- a/src/expression_evaluator/function_evaluator.cpp +++ b/src/expression_evaluator/function_evaluator.cpp @@ -11,9 +11,10 @@ namespace evaluator { void FunctionExpressionEvaluator::init(const ResultSet& resultSet, MemoryManager* memoryManager) { ExpressionEvaluator::init(resultSet, memoryManager); - execFunc = ((binder::ScalarFunctionExpression&)*expression).execFunc; + auto expr = reinterpret_cast(expression.get()); + execFunc = expr->execFunc; if (expression->dataType.getLogicalTypeID() == LogicalTypeID::BOOL) { - selectFunc = ((binder::ScalarFunctionExpression&)*expression).selectFunc; + selectFunc = expr->selectFunc; } } @@ -21,8 +22,16 @@ void FunctionExpressionEvaluator::evaluate() { for (auto& child : children) { child->evaluate(); } + auto expr = reinterpret_cast(expression.get()); + if (expr->getFunctionName() == "CAST" && + parameters[0]->dataType.getLogicalTypeID() == LogicalTypeID::STRING) { + execFunc(parameters, *resultVector, + &reinterpret_cast(expr->getBindData()) + ->csvConfig); + return; + } if (execFunc != nullptr) { - execFunc(parameters, *resultVector); + execFunc(parameters, *resultVector, nullptr); } } @@ -34,7 +43,7 @@ bool FunctionExpressionEvaluator::select(SelectionVector& selVector) { // implemented (e.g. list_contains). We should remove this if statement eventually. if (selectFunc == nullptr) { assert(resultVector->dataType.getLogicalTypeID() == LogicalTypeID::BOOL); - execFunc(parameters, *resultVector); + execFunc(parameters, *resultVector, nullptr); auto numSelectedValues = 0u; for (auto i = 0u; i < resultVector->state->selVector->selectedSize; ++i) { auto pos = resultVector->state->selVector->selectedPositions[i]; diff --git a/src/function/built_in_functions.cpp b/src/function/built_in_functions.cpp index 0ab534eb4e8..60c576b52c0 100644 --- a/src/function/built_in_functions.cpp +++ b/src/function/built_in_functions.cpp @@ -87,6 +87,30 @@ Function* BuiltInFunctions::matchScalarFunction( return candidateFunctions[0]; } +Function* BuiltInFunctions::matchCastScalarFunction( + const std::string& name, const std::vector& inputTypes, const LogicalType* type) { + auto& functionSet = functions.at(name); + std::vector candidateFunctions; + uint32_t minCost = UINT32_MAX; + for (auto& function : functionSet) { + auto func = reinterpret_cast(function.get()); + if (func->returnTypeID == type->getLogicalTypeID()) { + if (func->parameterTypeIDs[0] == inputTypes[0]->getLogicalTypeID()) { + candidateFunctions.push_back(function.get()); + break; + } + if (inputTypes[0]->getLogicalTypeID() == LogicalTypeID::ANY) { + if (func->parameterTypeIDs[0] == LogicalTypeID::STRING) { + candidateFunctions.push_back(function.get()); + break; + } + } + } + } + validateNonEmptyCandidateFunctions(candidateFunctions, name, inputTypes); + return candidateFunctions[0]; +} + AggregateFunction* BuiltInFunctions::matchAggregateFunction( const std::string& name, const std::vector& inputTypes, bool isDistinct) { auto& functionSet = functions.at(name); @@ -597,6 +621,7 @@ void BuiltInFunctions::registerCastFunctions() { functions.insert({CAST_TO_UINT8_FUNC_NAME, CastToUInt8Function::getFunctionSet()}); functions.insert({CAST_TO_INT128_FUNC_NAME, CastToInt128Function::getFunctionSet()}); functions.insert({CAST_TO_BOOL_FUNC_NAME, CastToBoolFunction::getFunctionSet()}); + functions.insert({CAST_FUNC_NAME, CastAnyFunction::getFunctionSet()}); } void BuiltInFunctions::registerListFunctions() { diff --git a/src/function/cast_string_to_functions.cpp b/src/function/cast_string_to_functions.cpp index 80d38e319ab..798f2df672d 100644 --- a/src/function/cast_string_to_functions.cpp +++ b/src/function/cast_string_to_functions.cpp @@ -13,26 +13,118 @@ using namespace kuzu::common; namespace kuzu { namespace function { +// ---------------------- cast String to Types Helper ------------------------------ // +struct CastStringToTypesHelper { + template + static void cast(const char* input, uint64_t len, T& result, ValueVector* /*vector*/ = nullptr, + uint64_t /*rowToAdd*/ = 0, const CSVReaderConfig* /*csvReaderConfig*/ = nullptr) { + simpleIntegerCast(input, len, result, LogicalType{LogicalTypeID::INT64}); + } +}; + +template<> +inline void CastStringToTypesHelper::cast(const char* input, uint64_t len, int128_t& result, + ValueVector* /*vector*/, uint64_t /*rowToAdd*/, const CSVReaderConfig* /*csvReaderConfig*/) { + simpleInt128Cast(input, len, result); +} + +template<> +inline void CastStringToTypesHelper::cast(const char* input, uint64_t len, int32_t& result, + ValueVector* /*vector*/, uint64_t /*rowToAdd*/, const CSVReaderConfig* /*csvReaderConfig*/) { + simpleIntegerCast(input, len, result, LogicalType{LogicalTypeID::INT32}); +} + +template<> +inline void CastStringToTypesHelper::cast(const char* input, uint64_t len, int16_t& result, + ValueVector* /*vector*/, uint64_t /*rowToAdd*/, const CSVReaderConfig* /*csvReaderConfig*/) { + simpleIntegerCast(input, len, result, LogicalType{LogicalTypeID::INT16}); +} + +template<> +inline void CastStringToTypesHelper::cast(const char* input, uint64_t len, int8_t& result, + ValueVector* /*vector*/, uint64_t /*rowToAdd*/, const CSVReaderConfig* /*csvReaderConfig*/) { + simpleIntegerCast(input, len, result, LogicalType{LogicalTypeID::INT8}); +} + +template<> +inline void CastStringToTypesHelper::cast(const char* input, uint64_t len, uint64_t& result, + ValueVector* /*vector*/, uint64_t /*rowToAdd*/, const CSVReaderConfig* /*csvReaderConfig*/) { + simpleIntegerCast(input, len, result, LogicalType{LogicalTypeID::UINT64}); +} + +template<> +inline void CastStringToTypesHelper::cast(const char* input, uint64_t len, uint32_t& result, + ValueVector* /*vector*/, uint64_t /*rowToAdd*/, const CSVReaderConfig* /*csvReaderConfig*/) { + simpleIntegerCast(input, len, result, LogicalType{LogicalTypeID::UINT32}); +} + +template<> +inline void CastStringToTypesHelper::cast(const char* input, uint64_t len, uint16_t& result, + ValueVector* /*vector*/, uint64_t /*rowToAdd*/, const CSVReaderConfig* /*csvReaderConfig*/) { + simpleIntegerCast(input, len, result, LogicalType{LogicalTypeID::UINT16}); +} + +template<> +inline void CastStringToTypesHelper::cast(const char* input, uint64_t len, uint8_t& result, + ValueVector* /*vector*/, uint64_t /*rowToAdd*/, const CSVReaderConfig* /*csvReaderConfig*/) { + simpleIntegerCast(input, len, result, LogicalType{LogicalTypeID::UINT8}); +} + +template<> +inline void CastStringToTypesHelper::cast(const char* input, uint64_t len, float_t& result, + ValueVector* /*vector*/, uint64_t /*rowToAdd*/, const CSVReaderConfig* /*csvReaderConfig*/) { + doubleCast(input, len, result, LogicalType{LogicalTypeID::FLOAT}); +} + +template<> +inline void CastStringToTypesHelper::cast(const char* input, uint64_t len, double_t& result, + ValueVector* /*vector*/, uint64_t /*rowToAdd*/, const CSVReaderConfig* /*csvReaderConfig*/) { + doubleCast(input, len, result, LogicalType{LogicalTypeID::DOUBLE}); +} + +template<> +inline void CastStringToTypesHelper::cast(const char* input, uint64_t len, bool& result, + ValueVector* /*vector*/, uint64_t /*rowToAdd*/, const CSVReaderConfig* /*csvReaderConfig*/) { + castStringToBool(input, len, result); +} + +template<> +inline void CastStringToTypesHelper::cast(const char* input, uint64_t len, date_t& result, + ValueVector* /*vector*/, uint64_t /*rowToAdd*/, const CSVReaderConfig* /*csvReaderConfig*/) { + result = Date::fromCString(input, len); +} + +template<> +inline void CastStringToTypesHelper::cast(const char* input, uint64_t len, timestamp_t& result, + ValueVector* /*vector*/, uint64_t /*rowToAdd*/, const CSVReaderConfig* /*csvReaderConfig*/) { + result = Timestamp::fromCString(input, len); +} + +template<> +inline void CastStringToTypesHelper::cast(const char* input, uint64_t len, interval_t& result, + ValueVector* /*vector*/, uint64_t /*rowToAdd*/, const CSVReaderConfig* /*csvReaderConfig*/) { + result = Interval::fromCString(input, len); +} + // ---------------------- cast String to Blob ------------------------------ // template<> -void CastStringToTypes::operation( - common::ku_string_t& input, common::blob_t& result, common::ValueVector& resultVector) { - result.value.len = common::Blob::getBlobSize(input); - if (!common::ku_string_t::isShortString(result.value.len)) { - auto overflowBuffer = common::StringVector::getInMemOverflowBuffer(&resultVector); +void CastStringToTypes::operation(const ku_string_t& input, blob_t& result, + ValueVector* resultVector, uint64_t /*rowToAdd*/, const CSVReaderConfig* /*CSVReaderConfig*/) { + result.value.len = Blob::getBlobSize(input); + if (!ku_string_t::isShortString(result.value.len)) { + auto overflowBuffer = StringVector::getInMemOverflowBuffer(resultVector); auto overflowPtr = overflowBuffer->allocateSpace(result.value.len); result.value.overflowPtr = reinterpret_cast(overflowPtr); - common::Blob::fromString( - reinterpret_cast(input.getData()), input.len, overflowPtr); - memcpy(result.value.prefix, overflowPtr, common::ku_string_t::PREFIX_LENGTH); + Blob::fromString(reinterpret_cast(input.getData()), input.len, overflowPtr); + memcpy(result.value.prefix, overflowPtr, ku_string_t::PREFIX_LENGTH); } else { - common::Blob::fromString( + Blob::fromString( reinterpret_cast(input.getData()), input.len, result.value.prefix); } } template<> -void CastStringToTypes::operation(const char* input, uint64_t len, common::blob_t& /*result*/, +void CastStringToTypesHelper::cast(const char* input, uint64_t len, blob_t& /*result*/, ValueVector* vector, uint64_t rowToAdd, const CSVReaderConfig* /*CSVReaderConfig*/) { // base case: blob storage::TableCopyUtils::validateStrLen(len); @@ -200,7 +292,7 @@ static inline void startListCast(const char* input, uint64_t len, T split, } template<> -void CastStringToTypes::operation(const char* input, uint64_t len, list_entry_t& /*result*/, +void CastStringToTypesHelper::cast(const char* input, uint64_t len, list_entry_t& /*result*/, ValueVector* vector, uint64_t rowToAdd, const CSVReaderConfig* csvReaderConfig) { // calculate the number of elements in array CountPartOperation state; @@ -214,6 +306,13 @@ void CastStringToTypes::operation(const char* input, uint64_t len, list_entry_t& startListCast(input, len, split, csvReaderConfig, vector); } +template<> +void CastStringToTypes::operation(const ku_string_t& input, list_entry_t& result, + ValueVector* resultVector, uint64_t rowToAdd, const CSVReaderConfig* CSVReaderConfig) { + CastStringToTypesHelper::cast(reinterpret_cast(input.getData()), input.len, result, + resultVector, rowToAdd, CSVReaderConfig); +} + // ---------------------- cast String to FixedList ------------------------------ // template struct SplitStringFixedListOperation { @@ -231,7 +330,7 @@ struct SplitStringFixedListOperation { throw ConversionException("Cast failed. NULL is not allowed for FIXEDLIST."); } auto type = FixedListType::getChildType(&resultVector->dataType); - function::CastStringToTypes::operation(start, str.length(), value); + CastStringToTypesHelper::cast(start, str.length(), value); resultVector->setValue(offset, value); offset++; } @@ -379,7 +478,7 @@ static bool splitCStringMap( } template<> -void CastStringToTypes::operation(const char* input, uint64_t len, common::map_entry_t& /*result*/, +void CastStringToTypesHelper::cast(const char* input, uint64_t len, map_entry_t& /*result*/, ValueVector* vector, uint64_t rowToAdd, const CSVReaderConfig* csvReaderConfig) { // count the number of maps in map CountPartOperation state; @@ -396,6 +495,13 @@ void CastStringToTypes::operation(const char* input, uint64_t len, common::map_e } } +template<> +void CastStringToTypes::operation(const ku_string_t& input, map_entry_t& result, + ValueVector* resultVector, uint64_t rowToAdd, const CSVReaderConfig* CSVReaderConfig) { + CastStringToTypesHelper::cast(reinterpret_cast(input.getData()), input.len, result, + resultVector, rowToAdd, CSVReaderConfig); +} + // ---------------------- cast String to Struct ------------------------------ // static bool parseStructFieldName(const char*& input, const char* end) { while (input < end) { @@ -486,7 +592,7 @@ static bool tryCastStringToStruct(const char* input, uint64_t len, ValueVector* } template<> -void CastStringToTypes::operation(const char* input, uint64_t len, struct_entry_t& /*result*/, +void CastStringToTypesHelper::cast(const char* input, uint64_t len, struct_entry_t& /*result*/, ValueVector* vector, uint64_t rowToAdd, const CSVReaderConfig* csvReaderConfig) { if (!tryCastStringToStruct(input, len, vector, rowToAdd, csvReaderConfig)) { throw ConversionException("Cast failed. " + std::string{input, len} + " is not in " + @@ -494,6 +600,13 @@ void CastStringToTypes::operation(const char* input, uint64_t len, struct_entry_ } } +template<> +void CastStringToTypes::operation(const ku_string_t& input, struct_entry_t& result, + ValueVector* resultVector, uint64_t rowToAdd, const CSVReaderConfig* CSVReaderConfig) { + CastStringToTypesHelper::cast(reinterpret_cast(input.getData()), input.len, result, + resultVector, rowToAdd, CSVReaderConfig); +} + // ---------------------- cast String to Union ------------------------------ // template static inline void testAndSetValue(ValueVector* vector, uint64_t rowToAdd, T result, bool success) { @@ -512,6 +625,11 @@ static bool tryCastUnionField( success = function::tryCastToBool(input, len, result); testAndSetValue(vector, rowToAdd, result, success); } break; + case LogicalTypeID::INT128: { + int128_t result; + success = function::trySimpleInt128Cast(input, len, result); + testAndSetValue(vector, rowToAdd, result, success); + } break; case LogicalTypeID::INT64: { int64_t result; success = function::trySimpleIntegerCast(input, len, result); @@ -589,7 +707,7 @@ static bool tryCastUnionField( } template<> -void CastStringToTypes::operation(const char* input, uint64_t len, union_entry_t& /*result*/, +void CastStringToTypesHelper::cast(const char* input, uint64_t len, union_entry_t& /*result*/, ValueVector* vector, uint64_t rowToAdd, const CSVReaderConfig* /*CSVReaderConfig**/) { auto& type = vector->dataType; union_field_idx_t selectedFieldIdx = INVALID_STRUCT_FIELD_IDX; @@ -616,6 +734,13 @@ void CastStringToTypes::operation(const char* input, uint64_t len, union_entry_t ->setNull(rowToAdd, false /* isNull */); } +template<> +void CastStringToTypes::operation(const ku_string_t& input, union_entry_t& result, + ValueVector* resultVector, uint64_t rowToAdd, const CSVReaderConfig* CSVReaderConfig) { + CastStringToTypesHelper::cast(reinterpret_cast(input.getData()), input.len, result, + resultVector, rowToAdd, CSVReaderConfig); +} + void CastStringToTypes::copyStringToVector(ValueVector* vector, uint64_t rowToAdd, std::string_view strVal, const CSVReaderConfig* csvReaderConfig) { auto& type = vector->dataType; @@ -629,67 +754,68 @@ void CastStringToTypes::copyStringToVector(ValueVector* vector, uint64_t rowToAd switch (type.getLogicalTypeID()) { case LogicalTypeID::INT128: { int128_t val; - operation(strVal.data(), strVal.length(), val); + CastStringToTypesHelper::cast(strVal.data(), strVal.length(), val); vector->setValue(rowToAdd, val); } break; case LogicalTypeID::INT64: { int64_t val; - operation(strVal.data(), strVal.length(), val); + CastStringToTypesHelper::cast(strVal.data(), strVal.length(), val); vector->setValue(rowToAdd, val); } break; case LogicalTypeID::INT32: { int32_t val; - operation(strVal.data(), strVal.length(), val); + CastStringToTypesHelper::cast(strVal.data(), strVal.length(), val); vector->setValue(rowToAdd, val); } break; case LogicalTypeID::INT16: { int16_t val; - operation(strVal.data(), strVal.length(), val); + CastStringToTypesHelper::cast(strVal.data(), strVal.length(), val); vector->setValue(rowToAdd, val); } break; case LogicalTypeID::INT8: { int8_t val; - operation(strVal.data(), strVal.length(), val); + CastStringToTypesHelper::cast(strVal.data(), strVal.length(), val); vector->setValue(rowToAdd, val); } break; case LogicalTypeID::UINT64: { uint64_t val; - operation(strVal.data(), strVal.length(), val); + CastStringToTypesHelper::cast(strVal.data(), strVal.length(), val); vector->setValue(rowToAdd, val); } break; case LogicalTypeID::UINT32: { uint32_t val; - operation(strVal.data(), strVal.length(), val); + CastStringToTypesHelper::cast(strVal.data(), strVal.length(), val); vector->setValue(rowToAdd, val); } break; case LogicalTypeID::UINT16: { uint16_t val; - operation(strVal.data(), strVal.length(), val); + CastStringToTypesHelper::cast(strVal.data(), strVal.length(), val); vector->setValue(rowToAdd, val); } break; case LogicalTypeID::UINT8: { uint8_t val; - operation(strVal.data(), strVal.length(), val); + CastStringToTypesHelper::cast(strVal.data(), strVal.length(), val); vector->setValue(rowToAdd, val); } break; case LogicalTypeID::FLOAT: { float_t val; - operation(strVal.data(), strVal.length(), val); + CastStringToTypesHelper::cast(strVal.data(), strVal.length(), val); vector->setValue(rowToAdd, val); } break; case LogicalTypeID::DOUBLE: { double_t val; - operation(strVal.data(), strVal.length(), val); + CastStringToTypesHelper::cast(strVal.data(), strVal.length(), val); vector->setValue(rowToAdd, val); } break; case LogicalTypeID::BOOL: { bool val; - operation(strVal.data(), strVal.length(), val); + CastStringToTypesHelper::cast(strVal.data(), strVal.length(), val); vector->setValue(rowToAdd, val); } break; case LogicalTypeID::BLOB: { blob_t val; - operation(strVal.data(), strVal.length(), val, vector, rowToAdd, csvReaderConfig); + CastStringToTypesHelper::cast( + strVal.data(), strVal.length(), val, vector, rowToAdd, csvReaderConfig); } break; case LogicalTypeID::STRING: { storage::TableCopyUtils::validateStrLen(strVal.length()); @@ -700,26 +826,28 @@ void CastStringToTypes::copyStringToVector(ValueVector* vector, uint64_t rowToAd } break; case LogicalTypeID::DATE: { date_t val; - operation(strVal.data(), strVal.length(), val); + CastStringToTypesHelper::cast(strVal.data(), strVal.length(), val); vector->setValue(rowToAdd, val); } break; case LogicalTypeID::TIMESTAMP: { timestamp_t val; - operation(strVal.data(), strVal.length(), val); + CastStringToTypesHelper::cast(strVal.data(), strVal.length(), val); vector->setValue(rowToAdd, val); } break; case LogicalTypeID::INTERVAL: { interval_t val; - operation(strVal.data(), strVal.length(), val); + CastStringToTypesHelper::cast(strVal.data(), strVal.length(), val); vector->setValue(rowToAdd, val); } break; case LogicalTypeID::MAP: { map_entry_t val; - operation(strVal.data(), strVal.length(), val, vector, rowToAdd, csvReaderConfig); + CastStringToTypesHelper::cast( + strVal.data(), strVal.length(), val, vector, rowToAdd, csvReaderConfig); } break; case LogicalTypeID::VAR_LIST: { list_entry_t val; - operation(strVal.data(), strVal.length(), val, vector, rowToAdd, csvReaderConfig); + CastStringToTypesHelper::cast( + strVal.data(), strVal.length(), val, vector, rowToAdd, csvReaderConfig); } break; case LogicalTypeID::FIXED_LIST: { // TODO: add fix list function wrapper @@ -727,11 +855,13 @@ void CastStringToTypes::copyStringToVector(ValueVector* vector, uint64_t rowToAd } break; case LogicalTypeID::STRUCT: { struct_entry_t val; - operation(strVal.data(), strVal.length(), val, vector, rowToAdd, csvReaderConfig); + CastStringToTypesHelper::cast( + strVal.data(), strVal.length(), val, vector, rowToAdd, csvReaderConfig); } break; case LogicalTypeID::UNION: { union_entry_t val; - operation(strVal.data(), strVal.length(), val, vector, rowToAdd, csvReaderConfig); + CastStringToTypesHelper::cast( + strVal.data(), strVal.length(), val, vector, rowToAdd, csvReaderConfig); } break; default: { // LCOV_EXCL_START throw NotImplementedException("CastStringToTypes::operation"); diff --git a/src/function/vector_blob_functions.cpp b/src/function/vector_blob_functions.cpp index 1de9d1110d7..3f0509ef0df 100644 --- a/src/function/vector_blob_functions.cpp +++ b/src/function/vector_blob_functions.cpp @@ -23,7 +23,7 @@ function_set EncodeFunctions::getFunctionSet() { function_set definitions; definitions.push_back(make_unique(ENCODE_FUNC_NAME, std::vector{LogicalTypeID::STRING}, LogicalTypeID::BLOB, - VectorStringFunction::UnaryStringExecFunction, nullptr, + ScalarFunction::UnaryStringExecFunction, nullptr, false /* isVarLength */)); return definitions; } @@ -32,7 +32,7 @@ function_set DecodeFunctions::getFunctionSet() { function_set definitions; definitions.push_back(make_unique(DECODE_FUNC_NAME, std::vector{LogicalTypeID::BLOB}, LogicalTypeID::STRING, - VectorStringFunction::UnaryStringExecFunction, nullptr, + ScalarFunction::UnaryStringExecFunction, nullptr, false /* isVarLength */)); return definitions; } diff --git a/src/function/vector_cast_functions.cpp b/src/function/vector_cast_functions.cpp index c01592ab0d7..8e59dee8f5f 100644 --- a/src/function/vector_cast_functions.cpp +++ b/src/function/vector_cast_functions.cpp @@ -127,20 +127,21 @@ void CastFunction::bindImplicitCastFunc( } case LogicalTypeID::DATE: { assert(sourceTypeID == LogicalTypeID::STRING); - func = &ScalarFunction::UnaryStringExecFunction; + func = &ScalarFunction::UnaryCastStringExecFunction; return; } case LogicalTypeID::TIMESTAMP: { assert(sourceTypeID == LogicalTypeID::STRING || sourceTypeID == LogicalTypeID::DATE); func = sourceTypeID == LogicalTypeID::STRING ? - &ScalarFunction::UnaryStringExecFunction : &ScalarFunction::UnaryExecFunction; return; } case LogicalTypeID::INTERVAL: { assert(sourceTypeID == LogicalTypeID::STRING); - func = &ScalarFunction::UnaryStringExecFunction; + func = &ScalarFunction::UnaryCastStringExecFunction; return; } default: @@ -194,8 +195,8 @@ void castFixedListToString( resultVector.setValue(resultPos, result); } -void fixedListCastExecFunction( - const std::vector>& params, common::ValueVector& result) { +void fixedListCastExecFunction(const std::vector>& params, + common::ValueVector& result, void* /*dataPtr*/ = nullptr) { assert(params.size() == 1); auto param = params[0]; if (param->state->isFlat()) { @@ -455,5 +456,109 @@ function_set CastToUInt8Function::getFunctionSet() { return result; } +function_set CastAnyFunction::getFunctionSet() { + function_set result; + // cast string to + result.push_back( + CastFunction::bindCastStringToFunction(CAST_FUNC_NAME, LogicalTypeID::DATE)); + result.push_back(CastFunction::bindCastStringToFunction( + CAST_FUNC_NAME, LogicalTypeID::TIMESTAMP)); + result.push_back(CastFunction::bindCastStringToFunction( + CAST_FUNC_NAME, LogicalTypeID::INTERVAL)); + result.push_back( + CastFunction::bindCastStringToFunction(CAST_FUNC_NAME, LogicalTypeID::BLOB)); + result.push_back( + CastFunction::bindCastStringToFunction(CAST_FUNC_NAME, LogicalTypeID::BOOL)); + result.push_back( + CastFunction::bindCastStringToFunction(CAST_FUNC_NAME, LogicalTypeID::DOUBLE)); + result.push_back( + CastFunction::bindCastStringToFunction(CAST_FUNC_NAME, LogicalTypeID::FLOAT)); + result.push_back( + CastFunction::bindCastStringToFunction(CAST_FUNC_NAME, LogicalTypeID::INT128)); + result.push_back( + CastFunction::bindCastStringToFunction(CAST_FUNC_NAME, LogicalTypeID::INT64)); + result.push_back( + CastFunction::bindCastStringToFunction(CAST_FUNC_NAME, LogicalTypeID::SERIAL)); + result.push_back( + CastFunction::bindCastStringToFunction(CAST_FUNC_NAME, LogicalTypeID::INT32)); + result.push_back( + CastFunction::bindCastStringToFunction(CAST_FUNC_NAME, LogicalTypeID::INT16)); + result.push_back( + CastFunction::bindCastStringToFunction(CAST_FUNC_NAME, LogicalTypeID::INT8)); + result.push_back( + CastFunction::bindCastStringToFunction(CAST_FUNC_NAME, LogicalTypeID::UINT64)); + result.push_back( + CastFunction::bindCastStringToFunction(CAST_FUNC_NAME, LogicalTypeID::UINT32)); + result.push_back( + CastFunction::bindCastStringToFunction(CAST_FUNC_NAME, LogicalTypeID::UINT16)); + result.push_back( + CastFunction::bindCastStringToFunction(CAST_FUNC_NAME, LogicalTypeID::UINT8)); + result.push_back(CastFunction::bindCastStringToFunction( + CAST_FUNC_NAME, LogicalTypeID::VAR_LIST)); + result.push_back( + CastFunction::bindCastStringToFunction(CAST_FUNC_NAME, LogicalTypeID::MAP)); + result.push_back(CastFunction::bindCastStringToFunction( + CAST_FUNC_NAME, LogicalTypeID::STRUCT)); + result.push_back(CastFunction::bindCastStringToFunction( + CAST_FUNC_NAME, LogicalTypeID::UNION)); + // cast to other types + for (auto& type : LogicalTypeUtils::getAllValidLogicTypes()) { + scalar_exec_func execFunc; + CastToStringFunction::getUnaryCastToStringExecFunction(type.getLogicalTypeID(), execFunc); + auto func = std::make_unique(CAST_FUNC_NAME, + std::vector{type.getLogicalTypeID()}, LogicalTypeID::STRING, execFunc); + result.push_back(std::move(func)); + } + for (auto typeID : LogicalTypeUtils::getNumericalLogicalTypeIDs()) { + result.push_back(CastFunction::bindNumericCastFunction( + CAST_FUNC_NAME, typeID, LogicalTypeID::DOUBLE)); + } + for (auto typeID : LogicalTypeUtils::getNumericalLogicalTypeIDs()) { + result.push_back(CastFunction::bindNumericCastFunction( + CAST_TO_FLOAT_FUNC_NAME, typeID, LogicalTypeID::FLOAT)); + } + for (auto typeID : LogicalTypeUtils::getNumericalLogicalTypeIDs()) { + result.push_back(CastFunction::bindNumericCastFunction( + CAST_TO_INT128_FUNC_NAME, typeID, LogicalTypeID::INT128)); + } + for (auto typeID : LogicalTypeUtils::getNumericalLogicalTypeIDs()) { + result.push_back(CastFunction::bindNumericCastFunction( + CAST_TO_SERIAL_FUNC_NAME, typeID, LogicalTypeID::SERIAL)); + } + for (auto typeID : LogicalTypeUtils::getNumericalLogicalTypeIDs()) { + result.push_back(CastFunction::bindNumericCastFunction( + CAST_TO_INT64_FUNC_NAME, typeID, LogicalTypeID::INT64)); + } + for (auto typeID : LogicalTypeUtils::getNumericalLogicalTypeIDs()) { + result.push_back(CastFunction::bindNumericCastFunction( + CAST_TO_INT32_FUNC_NAME, typeID, LogicalTypeID::INT32)); + } + for (auto typeID : LogicalTypeUtils::getNumericalLogicalTypeIDs()) { + result.push_back(CastFunction::bindNumericCastFunction( + CAST_TO_INT16_FUNC_NAME, typeID, LogicalTypeID::INT16)); + } + for (auto typeID : LogicalTypeUtils::getNumericalLogicalTypeIDs()) { + result.push_back(CastFunction::bindNumericCastFunction( + CAST_TO_INT8_FUNC_NAME, typeID, LogicalTypeID::INT8)); + } + for (auto typeID : LogicalTypeUtils::getNumericalLogicalTypeIDs()) { + result.push_back(CastFunction::bindNumericCastFunction( + CAST_TO_UINT64_FUNC_NAME, typeID, LogicalTypeID::UINT64)); + } + for (auto typeID : LogicalTypeUtils::getNumericalLogicalTypeIDs()) { + result.push_back(CastFunction::bindNumericCastFunction( + CAST_TO_UINT32_FUNC_NAME, typeID, LogicalTypeID::UINT32)); + } + for (auto typeID : LogicalTypeUtils::getNumericalLogicalTypeIDs()) { + result.push_back(CastFunction::bindNumericCastFunction( + CAST_TO_UINT16_FUNC_NAME, typeID, LogicalTypeID::UINT16)); + } + for (auto typeID : LogicalTypeUtils::getNumericalLogicalTypeIDs()) { + result.push_back(CastFunction::bindNumericCastFunction( + CAST_TO_UINT8_FUNC_NAME, typeID, LogicalTypeID::UINT8)); + } + return result; +} + } // namespace function } // namespace kuzu diff --git a/src/function/vector_list_functions.cpp b/src/function/vector_list_functions.cpp index c276f1fc28c..9821fcaeee8 100644 --- a/src/function/vector_list_functions.cpp +++ b/src/function/vector_list_functions.cpp @@ -33,8 +33,8 @@ static std::string getListFunctionIncompatibleChildrenTypeErrorMsg( LogicalTypeUtils::dataTypeToString(right) + "."); } -void ListCreationFunction::execFunc( - const std::vector>& parameters, ValueVector& result) { +void ListCreationFunction::execFunc(const std::vector>& parameters, + ValueVector& result, void* /*dataPtr*/) { assert(result.dataType.getLogicalTypeID() == LogicalTypeID::VAR_LIST); result.resetAuxiliaryBuffer(); for (auto selectedPos = 0u; selectedPos < result.state->selVector->selectedSize; @@ -139,7 +139,8 @@ function_set SizeFunction::getFunctionSet() { template static void BinaryExecListExtractFunction( - const std::vector>& params, common::ValueVector& result) { + const std::vector>& params, common::ValueVector& result, + void* /*dataPtr*/ = nullptr) { assert(params.size() == 2); BinaryFunctionExecutor::executeListExtract( *params[0], *params[1], result); diff --git a/src/function/vector_path_functions.cpp b/src/function/vector_path_functions.cpp index 9b75a2ad493..bcbe9591568 100644 --- a/src/function/vector_path_functions.cpp +++ b/src/function/vector_path_functions.cpp @@ -87,8 +87,8 @@ void PropertiesFunction::compileFunc(FunctionBindData* bindData, ListVector::setDataVector(result.get(), fieldVector); } -void PropertiesFunction::execFunc( - const std::vector>& parameters, ValueVector& result) { +void PropertiesFunction::execFunc(const std::vector>& parameters, + ValueVector& result, void* /*dataPtr*/) { if (parameters[0]->state->isFlat()) { auto inputPos = parameters[0]->state->selVector->selectedPositions[0]; if (parameters[0]->isNull(inputPos)) { @@ -123,8 +123,8 @@ function_set IsTrailFunction::getFunctionSet() { return functionSet; } -void IsTrailFunction::execFunc( - const std::vector>& parameters, ValueVector& result) { +void IsTrailFunction::execFunc(const std::vector>& parameters, + ValueVector& result, void* /*dataPtr*/) { UnaryPathExecutor::executeRelIDs(*parameters[0], result); } @@ -141,8 +141,8 @@ function_set IsACyclicFunction::getFunctionSet() { return functionSet; } -void IsACyclicFunction::execFunc( - const std::vector>& parameters, ValueVector& result) { +void IsACyclicFunction::execFunc(const std::vector>& parameters, + ValueVector& result, void* /*dataPtr*/) { UnaryPathExecutor::executeNodeIDs(*parameters[0], result); } diff --git a/src/function/vector_string_functions.cpp b/src/function/vector_string_functions.cpp index 340173c93a2..ef10b7ff3dc 100644 --- a/src/function/vector_string_functions.cpp +++ b/src/function/vector_string_functions.cpp @@ -136,7 +136,7 @@ function_set ConcatFunction::getFunctionSet() { functionSet.emplace_back(make_unique(CONCAT_FUNC_NAME, std::vector{LogicalTypeID::STRING, LogicalTypeID::STRING}, LogicalTypeID::STRING, - BinaryStringExecFunction, + ScalarFunction::BinaryStringExecFunction, false /* isVarLength */)); return functionSet; } @@ -167,7 +167,8 @@ function_set LeftFunction::getFunctionSet() { function_set functionSet; functionSet.emplace_back(make_unique(LEFT_FUNC_NAME, std::vector{LogicalTypeID::STRING, LogicalTypeID::INT64}, - LogicalTypeID::STRING, BinaryStringExecFunction, + LogicalTypeID::STRING, + ScalarFunction::BinaryStringExecFunction, false /* isVarLength */)); return functionSet; } @@ -178,7 +179,7 @@ function_set LpadFunction::getFunctionSet() { std::vector{ LogicalTypeID::STRING, LogicalTypeID::INT64, LogicalTypeID::STRING}, LogicalTypeID::STRING, - TernaryStringExecFunction, + ScalarFunction::TernaryStringExecFunction, false /* isVarLength */)); return functionSet; } @@ -187,7 +188,7 @@ function_set RepeatFunction::getFunctionSet() { function_set functionSet; functionSet.emplace_back(make_unique(REPEAT_FUNC_NAME, std::vector{LogicalTypeID::STRING, LogicalTypeID::INT64}, - LogicalTypeID::STRING, BinaryStringExecFunction, + LogicalTypeID::STRING, ScalarFunction::BinaryStringExecFunction, false /* isVarLength */)); return functionSet; } @@ -196,7 +197,7 @@ function_set RightFunction::getFunctionSet() { function_set functionSet; functionSet.emplace_back(make_unique(RIGHT_FUNC_NAME, std::vector{LogicalTypeID::STRING, LogicalTypeID::INT64}, - LogicalTypeID::STRING, BinaryStringExecFunction, + LogicalTypeID::STRING, ScalarFunction::BinaryStringExecFunction, false /* isVarLength */)); return functionSet; } @@ -207,7 +208,7 @@ function_set RpadFunction::getFunctionSet() { std::vector{ LogicalTypeID::STRING, LogicalTypeID::INT64, LogicalTypeID::STRING}, LogicalTypeID::STRING, - TernaryStringExecFunction, + ScalarFunction::TernaryStringExecFunction, false /* isVarLength */)); return functionSet; } @@ -229,7 +230,7 @@ function_set SubStrFunction::getFunctionSet() { std::vector{ LogicalTypeID::STRING, LogicalTypeID::INT64, LogicalTypeID::INT64}, LogicalTypeID::STRING, - TernaryStringExecFunction, + ScalarFunction::TernaryStringExecFunction, false /* isVarLength */)); return functionSet; } @@ -264,7 +265,7 @@ function_set RegexpReplaceFunction::getFunctionSet() { std::vector{ LogicalTypeID::STRING, LogicalTypeID::STRING, LogicalTypeID::STRING}, LogicalTypeID::STRING, - TernaryStringExecFunction, false /* isVarLength */)); return functionSet; @@ -275,13 +276,13 @@ function_set RegexpExtractFunction::getFunctionSet() { functionSet.emplace_back(make_unique(REGEXP_EXTRACT_FUNC_NAME, std::vector{LogicalTypeID::STRING, LogicalTypeID::STRING}, LogicalTypeID::STRING, - BinaryStringExecFunction, + ScalarFunction::BinaryStringExecFunction, false /* isVarLength */)); functionSet.emplace_back(make_unique(REGEXP_EXTRACT_FUNC_NAME, std::vector{ LogicalTypeID::STRING, LogicalTypeID::STRING, LogicalTypeID::INT64}, LogicalTypeID::STRING, - TernaryStringExecFunction, + ScalarFunction::TernaryStringExecFunction, false /* isVarLength */)); return functionSet; } @@ -291,13 +292,13 @@ function_set RegexpExtractAllFunction::getFunctionSet() { functionSet.emplace_back(make_unique(REGEXP_EXTRACT_FUNC_NAME, std::vector{LogicalTypeID::STRING, LogicalTypeID::STRING}, LogicalTypeID::VAR_LIST, - BinaryStringExecFunction, nullptr, + ScalarFunction::BinaryStringExecFunction, nullptr, bindFunc, false /* isVarLength */)); functionSet.emplace_back(make_unique(REGEXP_EXTRACT_FUNC_NAME, std::vector{ LogicalTypeID::STRING, LogicalTypeID::STRING, LogicalTypeID::INT64}, LogicalTypeID::VAR_LIST, - TernaryStringExecFunction, nullptr, bindFunc, false /* isVarLength */)); return functionSet; diff --git a/src/function/vector_struct_functions.cpp b/src/function/vector_struct_functions.cpp index 32a425e3c98..fed3c744368 100644 --- a/src/function/vector_struct_functions.cpp +++ b/src/function/vector_struct_functions.cpp @@ -35,8 +35,8 @@ std::unique_ptr StructPackFunctions::bindFunc( return std::make_unique(resultType); } -void StructPackFunctions::execFunc( - const std::vector>& parameters, ValueVector& result) { +void StructPackFunctions::execFunc(const std::vector>& parameters, + ValueVector& result, void* /*dataPtr*/) { for (auto i = 0u; i < parameters.size(); i++) { auto& parameter = parameters[i]; if (parameter->state == result.state) { diff --git a/src/function/vector_union_functions.cpp b/src/function/vector_union_functions.cpp index 2abca59f8da..1e608aaab9b 100644 --- a/src/function/vector_union_functions.cpp +++ b/src/function/vector_union_functions.cpp @@ -35,8 +35,8 @@ std::unique_ptr UnionValueFunction::bindFunc( return std::make_unique(resultType); } -void UnionValueFunction::execFunc( - const std::vector>& /*parameters*/, ValueVector& result) { +void UnionValueFunction::execFunc(const std::vector>& /*parameters*/, + ValueVector& result, void* /*dataPtr*/) { UnionVector::setTagField(&result, UnionType::TAG_FIELD_IDX); } diff --git a/src/include/binder/expression/function_expression.h b/src/include/binder/expression/function_expression.h index d4357b425c7..3cefe670961 100644 --- a/src/include/binder/expression/function_expression.h +++ b/src/include/binder/expression/function_expression.h @@ -54,8 +54,8 @@ class ScalarFunctionExpression : public FunctionExpression { function::scalar_compile_func compileFunc, const std::string& uniqueName) : FunctionExpression{std::move(functionName), expressionType, std::move(bindData), std::move(children), uniqueName}, - execFunc{std::move(execFunc)}, selectFunc{std::move(selectFunc)}, compileFunc{std::move( - compileFunc)} {} + execFunc{std::move(execFunc)}, selectFunc{std::move(selectFunc)}, + compileFunc{std::move(compileFunc)} {} static std::string getUniqueName(const std::string& functionName, expression_vector& children); diff --git a/src/include/binder/expression_binder.h b/src/include/binder/expression_binder.h index 59011f7cc1b..751be27f179 100644 --- a/src/include/binder/expression_binder.h +++ b/src/include/binder/expression_binder.h @@ -61,8 +61,10 @@ class ExpressionBinder { std::shared_ptr bindScalarFunctionExpression( const parser::ParsedExpression& parsedExpression, const std::string& functionName); - std::shared_ptr bindScalarFunctionExpression( - const expression_vector& children, const std::string& functionName); + std::shared_ptr bindScalarFunctionExpression(const expression_vector& children, + const std::string& functionName); + std::shared_ptr bindScalarFunctionExpression(const expression_vector& children, + const std::string& functionName, const common::LogicalType* type); std::shared_ptr bindAggregateFunctionExpression( const parser::ParsedExpression& parsedExpression, const std::string& functionName, bool isDistinct); diff --git a/src/include/common/enums/expression_type.h b/src/include/common/enums/expression_type.h index 9e2a1cfd076..87abf22c255 100644 --- a/src/include/common/enums/expression_type.h +++ b/src/include/common/enums/expression_type.h @@ -20,6 +20,7 @@ const std::string MAX_FUNC_NAME = "MAX"; const std::string COLLECT_FUNC_NAME = "COLLECT"; // cast +const std::string CAST_FUNC_NAME = "CAST"; const std::string CAST_DATE_FUNC_NAME = "DATE"; const std::string CAST_TO_DATE_FUNC_NAME = "TO_DATE"; const std::string CAST_TO_TIMESTAMP_FUNC_NAME = "TIMESTAMP"; diff --git a/src/include/common/types/ku_string.h b/src/include/common/types/ku_string.h index 273a04ae3ae..73d27d3b064 100644 --- a/src/include/common/types/ku_string.h +++ b/src/include/common/types/ku_string.h @@ -21,6 +21,7 @@ struct ku_string_t { }; ku_string_t() : len{0}, overflowPtr{0} {} + ku_string_t(const char* value, uint64_t length); static bool isShortString(uint32_t len) { return len <= SHORT_STR_LENGTH; } diff --git a/src/include/expression_evaluator/function_evaluator.h b/src/include/expression_evaluator/function_evaluator.h index f49197ff150..440b84337c9 100644 --- a/src/include/expression_evaluator/function_evaluator.h +++ b/src/include/expression_evaluator/function_evaluator.h @@ -10,8 +10,8 @@ class FunctionExpressionEvaluator : public ExpressionEvaluator { public: FunctionExpressionEvaluator(std::shared_ptr expression, std::vector> children) - : ExpressionEvaluator{std::move(children)}, - expression{std::move(expression)}, execFunc{nullptr}, selectFunc{nullptr} {} + : ExpressionEvaluator{std::move(children)}, expression{std::move(expression)}, + execFunc{nullptr}, selectFunc{nullptr} {} void init( const processor::ResultSet& resultSet, storage::MemoryManager* memoryManager) override; diff --git a/src/include/function/boolean/vector_boolean_functions.h b/src/include/function/boolean/vector_boolean_functions.h index 43f1eba249a..2b5e1ed58e4 100644 --- a/src/include/function/boolean/vector_boolean_functions.h +++ b/src/include/function/boolean/vector_boolean_functions.h @@ -18,7 +18,7 @@ class VectorBooleanFunction { template static void BinaryBooleanExecFunction( const std::vector>& params, - common::ValueVector& result) { + common::ValueVector& result, void* /*dataPtr*/ = nullptr) { assert(params.size() == 2); BinaryBooleanFunctionExecutor::execute(*params[0], *params[1], result); } @@ -34,7 +34,7 @@ class VectorBooleanFunction { template static void UnaryBooleanExecFunction( const std::vector>& params, - common::ValueVector& result) { + common::ValueVector& result, void* /*dataPtr*/ = nullptr) { assert(params.size() == 1); UnaryBooleanOperationExecutor::execute(*params[0], result); } diff --git a/src/include/function/built_in_function.h b/src/include/function/built_in_function.h index b99ec06a88a..ece15a14a76 100644 --- a/src/include/function/built_in_function.h +++ b/src/include/function/built_in_function.h @@ -24,6 +24,8 @@ class BuiltInFunctions { // functions. Function* matchScalarFunction( const std::string& name, const std::vector& inputTypes); + Function* matchCastScalarFunction(const std::string& name, + const std::vector& inputTypes, const common::LogicalType* type); AggregateFunction* matchAggregateFunction(const std::string& name, const std::vector& inputTypes, bool isDistinct); diff --git a/src/include/function/cast/functions/cast_string_to_functions.h b/src/include/function/cast/functions/cast_string_to_functions.h index b7c3bcbb781..351216bb1e3 100644 --- a/src/include/function/cast/functions/cast_string_to_functions.h +++ b/src/include/function/cast/functions/cast_string_to_functions.h @@ -6,276 +6,158 @@ #include "common/types/blob.h" #include "common/vector/value_vector.h" +using namespace kuzu::common; + namespace kuzu { namespace function { struct CastStringToTypes { - static void copyStringToVector(common::ValueVector* vector, uint64_t rowToAdd, - std::string_view strVal, const common::CSVReaderConfig* csvReaderConfig); + static void copyStringToVector(ValueVector* vector, uint64_t rowToAdd, std::string_view strVal, + const CSVReaderConfig* csvReaderConfig); template - static inline bool tryCast(const char* input, uint64_t len, T& result) { + static inline bool tryCast(const ku_string_t& input, T& result) { // try cast for signed integer types - return trySimpleIntegerCast(input, len, result); + return trySimpleIntegerCast( + reinterpret_cast(input.getData()), input.len, result); } template - static inline void operation( - common::ku_string_t& input, T& result, common::ValueVector& /*resultVector*/) { + static inline void operation(const ku_string_t& input, T& result, + ValueVector* /*resultVector*/ = nullptr, uint64_t /*rowToAdd*/ = 0, + const CSVReaderConfig* /*CSVReaderConfig*/ = nullptr) { // base case: int64 - simpleIntegerCast((char*)input.getData(), input.len, result, - common::LogicalType{common::LogicalTypeID::INT64}); - } - - template - static void operation(const char* input, uint64_t len, T& result, - common::ValueVector* /*vector*/ = nullptr, uint64_t /*rowToAdd*/ = 0, - const common::CSVReaderConfig* /*csvReaderConfig*/ = nullptr) { - simpleIntegerCast( - input, len, result, common::LogicalType{common::LogicalTypeID::INT64}); + simpleIntegerCast(reinterpret_cast(input.getData()), input.len, + result, LogicalType{LogicalTypeID::INT64}); } }; template<> -inline void CastStringToTypes::operation( - common::ku_string_t& input, common::int128_t& result, common::ValueVector& /*resultVector*/) { - simpleInt128Cast((char*)input.getData(), input.len, result); +inline void CastStringToTypes::operation(const ku_string_t& input, int128_t& result, + ValueVector* /*resultVector*/, uint64_t /*rowToAdd*/, + const CSVReaderConfig* /*CSVReaderConfig*/) { + simpleInt128Cast(reinterpret_cast(input.getData()), input.len, result); } template<> -inline void CastStringToTypes::operation( - common::ku_string_t& input, int32_t& result, common::ValueVector& /*resultVector*/) { - simpleIntegerCast((char*)input.getData(), input.len, result, - common::LogicalType{common::LogicalTypeID::INT32}); +inline void CastStringToTypes::operation(const ku_string_t& input, int32_t& result, + ValueVector* /*resultVector*/, uint64_t /*rowToAdd*/, + const CSVReaderConfig* /*CSVReaderConfig*/) { + simpleIntegerCast(reinterpret_cast(input.getData()), input.len, result, + LogicalType{LogicalTypeID::INT32}); } template<> -inline void CastStringToTypes::operation( - common::ku_string_t& input, int16_t& result, common::ValueVector& /*resultVector*/) { - simpleIntegerCast((char*)input.getData(), input.len, result, - common::LogicalType{common::LogicalTypeID::INT16}); +inline void CastStringToTypes::operation(const ku_string_t& input, int16_t& result, + ValueVector* /*resultVector*/, uint64_t /*rowToAdd*/, + const CSVReaderConfig* /*CSVReaderConfig*/) { + simpleIntegerCast(reinterpret_cast(input.getData()), input.len, result, + LogicalType{LogicalTypeID::INT16}); } template<> -inline void CastStringToTypes::operation( - common::ku_string_t& input, int8_t& result, common::ValueVector& /*resultVector*/) { - simpleIntegerCast((char*)input.getData(), input.len, result, - common::LogicalType{common::LogicalTypeID::INT8}); +inline void CastStringToTypes::operation(const ku_string_t& input, int8_t& result, + ValueVector* /*resultVector*/, uint64_t /*rowToAdd*/, + const CSVReaderConfig* /*CSVReaderConfig*/) { + simpleIntegerCast(reinterpret_cast(input.getData()), input.len, result, + LogicalType{LogicalTypeID::INT8}); } template<> -inline void CastStringToTypes::operation( - common::ku_string_t& input, uint64_t& result, common::ValueVector& /*resultVector*/) { - simpleIntegerCast((char*)input.getData(), input.len, result, - common::LogicalType{common::LogicalTypeID::UINT64}); +inline void CastStringToTypes::operation(const ku_string_t& input, uint64_t& result, + ValueVector* /*resultVector*/, uint64_t /*rowToAdd*/, + const CSVReaderConfig* /*CSVReaderConfig*/) { + simpleIntegerCast(reinterpret_cast(input.getData()), input.len, + result, LogicalType{LogicalTypeID::UINT64}); } template<> -inline void CastStringToTypes::operation( - common::ku_string_t& input, uint32_t& result, common::ValueVector& /*resultVector*/) { - simpleIntegerCast((char*)input.getData(), input.len, result, - common::LogicalType{common::LogicalTypeID::UINT32}); +inline void CastStringToTypes::operation(const ku_string_t& input, uint32_t& result, + ValueVector* /*resultVector*/, uint64_t /*rowToAdd*/, + const CSVReaderConfig* /*CSVReaderConfig*/) { + simpleIntegerCast(reinterpret_cast(input.getData()), input.len, + result, LogicalType{LogicalTypeID::UINT32}); } template<> -inline void CastStringToTypes::operation( - common::ku_string_t& input, uint16_t& result, common::ValueVector& /*resultVector*/) { - simpleIntegerCast((char*)input.getData(), input.len, result, - common::LogicalType{common::LogicalTypeID::UINT16}); +inline void CastStringToTypes::operation(const ku_string_t& input, uint16_t& result, + ValueVector* /*resultVector*/, uint64_t /*rowToAdd*/, + const CSVReaderConfig* /*CSVReaderConfig*/) { + simpleIntegerCast(reinterpret_cast(input.getData()), input.len, + result, LogicalType{LogicalTypeID::UINT16}); } template<> -inline void CastStringToTypes::operation( - common::ku_string_t& input, uint8_t& result, common::ValueVector& /*resultVector*/) { - simpleIntegerCast((char*)input.getData(), input.len, result, - common::LogicalType{common::LogicalTypeID::UINT8}); +inline void CastStringToTypes::operation(const ku_string_t& input, uint8_t& result, + ValueVector* /*resultVector*/, uint64_t /*rowToAdd*/, + const CSVReaderConfig* /*CSVReaderConfig*/) { + simpleIntegerCast(reinterpret_cast(input.getData()), input.len, + result, LogicalType{LogicalTypeID::UINT8}); } template<> -inline void CastStringToTypes::operation( - common::ku_string_t& input, float_t& result, common::ValueVector& /*resultVector*/) { - doubleCast((char*)input.getData(), input.len, result, - common::LogicalType{common::LogicalTypeID::FLOAT}); +inline void CastStringToTypes::operation(const ku_string_t& input, float_t& result, + ValueVector* /*resultVector*/, uint64_t /*rowToAdd*/, + const CSVReaderConfig* /*CSVReaderConfig*/) { + doubleCast(reinterpret_cast(input.getData()), input.len, result, + LogicalType{LogicalTypeID::FLOAT}); } template<> -inline void CastStringToTypes::operation( - common::ku_string_t& input, double_t& result, common::ValueVector& /*resultVector*/) { - doubleCast((char*)input.getData(), input.len, result, - common::LogicalType{common::LogicalTypeID::DOUBLE}); +inline void CastStringToTypes::operation(const ku_string_t& input, double_t& result, + ValueVector* /*resultVector*/, uint64_t /*rowToAdd*/, + const CSVReaderConfig* /*CSVReaderConfig*/) { + doubleCast(reinterpret_cast(input.getData()), input.len, result, + LogicalType{LogicalTypeID::DOUBLE}); } template<> -inline void CastStringToTypes::operation( - common::ku_string_t& input, common::date_t& result, common::ValueVector& /*resultVector*/) { - result = common::Date::fromCString((const char*)input.getData(), input.len); +inline void CastStringToTypes::operation(const ku_string_t& input, date_t& result, + ValueVector* /*resultVector*/, uint64_t /*rowToAdd*/, + const CSVReaderConfig* /*CSVReaderConfig*/) { + result = Date::fromCString((const char*)input.getData(), input.len); } template<> -inline void CastStringToTypes::operation(common::ku_string_t& input, common::timestamp_t& result, - common::ValueVector& /*resultVector*/) { - result = common::Timestamp::fromCString((const char*)input.getData(), input.len); +inline void CastStringToTypes::operation(const ku_string_t& input, timestamp_t& result, + ValueVector* /*resultVector*/, uint64_t /*rowToAdd*/, + const CSVReaderConfig* /*CSVReaderConfig*/) { + result = Timestamp::fromCString((const char*)input.getData(), input.len); } template<> -inline void CastStringToTypes::operation( - common::ku_string_t& input, common::interval_t& result, common::ValueVector& /*resultVector*/) { - result = common::Interval::fromCString((const char*)input.getData(), input.len); +inline void CastStringToTypes::operation(const ku_string_t& input, interval_t& result, + ValueVector* /*resultVector*/, uint64_t /*rowToAdd*/, + const CSVReaderConfig* /*CSVReaderConfig*/) { + result = Interval::fromCString((const char*)input.getData(), input.len); } template<> -inline void CastStringToTypes::operation( - common::ku_string_t& input, bool& result, common::ValueVector& /*resultVector*/) { +inline void CastStringToTypes::operation(const ku_string_t& input, bool& result, + ValueVector* /*resultVector*/, uint64_t /*rowToAdd*/, + const CSVReaderConfig* /*CSVReaderConfig*/) { castStringToBool(reinterpret_cast(input.getData()), input.len, result); } template<> -void CastStringToTypes::operation( - common::ku_string_t& input, common::blob_t& result, common::ValueVector& resultVector); - -template<> -void CastStringToTypes::operation( - common::ku_string_t& input, common::list_entry_t& result, common::ValueVector& resultVector); - -template<> -void CastStringToTypes::operation( - common::ku_string_t& input, common::map_entry_t& result, common::ValueVector& resultVector); - -template<> -void CastStringToTypes::operation( - common::ku_string_t& input, common::union_entry_t& result, common::ValueVector& resultVector); - -template<> -void CastStringToTypes::operation( - common::ku_string_t& input, common::struct_entry_t& result, common::ValueVector& resultVector); - -template<> -inline void CastStringToTypes::operation(const char* input, uint64_t len, common::int128_t& result, - common::ValueVector* /*vector*/, uint64_t /*rowToAdd*/, - const common::CSVReaderConfig* /*csvReaderConfig*/) { - simpleInt128Cast(input, len, result); -} - -template<> -inline void CastStringToTypes::operation(const char* input, uint64_t len, int32_t& result, - common::ValueVector* /*vector*/, uint64_t /*rowToAdd*/, - const common::CSVReaderConfig* /*csvReaderConfig*/) { - simpleIntegerCast( - input, len, result, common::LogicalType{common::LogicalTypeID::INT32}); -} - -template<> -inline void CastStringToTypes::operation(const char* input, uint64_t len, int16_t& result, - common::ValueVector* /*vector*/, uint64_t /*rowToAdd*/, - const common::CSVReaderConfig* /*csvReaderConfig*/) { - simpleIntegerCast( - input, len, result, common::LogicalType{common::LogicalTypeID::INT16}); -} - -template<> -inline void CastStringToTypes::operation(const char* input, uint64_t len, int8_t& result, - common::ValueVector* /*vector*/, uint64_t /*rowToAdd*/, - const common::CSVReaderConfig* /*csvReaderConfig*/) { - simpleIntegerCast(input, len, result, common::LogicalType{common::LogicalTypeID::INT8}); -} - -template<> -inline void CastStringToTypes::operation(const char* input, uint64_t len, uint64_t& result, - common::ValueVector* /*vector*/, uint64_t /*rowToAdd*/, - const common::CSVReaderConfig* /*csvReaderConfig*/) { - simpleIntegerCast( - input, len, result, common::LogicalType{common::LogicalTypeID::UINT64}); -} - -template<> -inline void CastStringToTypes::operation(const char* input, uint64_t len, uint32_t& result, - common::ValueVector* /*vector*/, uint64_t /*rowToAdd*/, - const common::CSVReaderConfig* /*csvReaderConfig*/) { - simpleIntegerCast( - input, len, result, common::LogicalType{common::LogicalTypeID::UINT32}); -} - -template<> -inline void CastStringToTypes::operation(const char* input, uint64_t len, uint16_t& result, - common::ValueVector* /*vector*/, uint64_t /*rowToAdd*/, - const common::CSVReaderConfig* /*csvReaderConfig*/) { - simpleIntegerCast( - input, len, result, common::LogicalType{common::LogicalTypeID::UINT16}); -} - -template<> -inline void CastStringToTypes::operation(const char* input, uint64_t len, uint8_t& result, - common::ValueVector* /*vector*/, uint64_t /*rowToAdd*/, - const common::CSVReaderConfig* /*csvReaderConfig*/) { - simpleIntegerCast( - input, len, result, common::LogicalType{common::LogicalTypeID::UINT8}); -} - -template<> -inline void CastStringToTypes::operation(const char* input, uint64_t len, float_t& result, - common::ValueVector* /*vector*/, uint64_t /*rowToAdd*/, - const common::CSVReaderConfig* /*csvReaderConfig*/) { - doubleCast(input, len, result, common::LogicalType{common::LogicalTypeID::FLOAT}); -} - -template<> -inline void CastStringToTypes::operation(const char* input, uint64_t len, double_t& result, - common::ValueVector* /*vector*/, uint64_t /*rowToAdd*/, - const common::CSVReaderConfig* /*csvReaderConfig*/) { - doubleCast(input, len, result, common::LogicalType{common::LogicalTypeID::DOUBLE}); -} - -template<> -inline void CastStringToTypes::operation(const char* input, uint64_t len, bool& result, - common::ValueVector* /*vector*/, uint64_t /*rowToAdd*/, - const common::CSVReaderConfig* /*csvReaderConfig*/) { - castStringToBool(input, len, result); -} - -template<> -inline void CastStringToTypes::operation(const char* input, uint64_t len, common::date_t& result, - common::ValueVector* /*vector*/, uint64_t /*rowToAdd*/, - const common::CSVReaderConfig* /*csvReaderConfig*/) { - result = common::Date::fromCString(input, len); -} - -template<> -inline void CastStringToTypes::operation(const char* input, uint64_t len, - common::timestamp_t& result, common::ValueVector* /*vector*/, uint64_t /*rowToAdd*/, - const common::CSVReaderConfig* /*csvReaderConfig*/) { - result = common::Timestamp::fromCString(input, len); -} - -template<> -inline void CastStringToTypes::operation(const char* input, uint64_t len, - common::interval_t& result, common::ValueVector* /*vector*/, uint64_t /*rowToAdd*/, - const common::CSVReaderConfig* /*csvReaderConfig*/) { - result = common::Interval::fromCString(input, len); -} - -template<> -void CastStringToTypes::operation(const char* input, uint64_t len, common::blob_t& result, - common::ValueVector* vector, uint64_t rowToAdd, const common::CSVReaderConfig* csvReaderConfig); +void CastStringToTypes::operation(const ku_string_t& input, blob_t& result, + ValueVector* resultVector, uint64_t rowToAdd, const CSVReaderConfig* CSVReaderConfig); template<> -void CastStringToTypes::operation(const char* input, uint64_t len, - common::list_entry_t& result, common::ValueVector* vector, uint64_t rowToAdd, - const common::CSVReaderConfig* csvReaderConfig); +void CastStringToTypes::operation(const ku_string_t& input, list_entry_t& result, + ValueVector* resultVector, uint64_t rowToAdd, const CSVReaderConfig* CSVReaderConfig); template<> -void CastStringToTypes::operation(const char* input, uint64_t len, - common::map_entry_t& result, common::ValueVector* vector, uint64_t rowToAdd, - const common::CSVReaderConfig* csvReaderConfig); +void CastStringToTypes::operation(const ku_string_t& input, map_entry_t& result, + ValueVector* resultVector, uint64_t rowToAdd, const CSVReaderConfig* CSVReaderConfig); template<> -void CastStringToTypes::operation(const char* input, uint64_t len, - common::struct_entry_t& result, common::ValueVector* vector, uint64_t rowToAdd, - const common::CSVReaderConfig* csvReaderConfig); +void CastStringToTypes::operation(const ku_string_t& input, struct_entry_t& result, + ValueVector* resultVector, uint64_t rowToAdd, const CSVReaderConfig* CSVReaderConfig); template<> -void CastStringToTypes::operation(const char* input, uint64_t len, - common::union_entry_t& result, common::ValueVector* vector, uint64_t rowToAdd, - const common::CSVReaderConfig* csvReaderConfig); +void CastStringToTypes::operation(const ku_string_t& input, union_entry_t& result, + ValueVector* resultVector, uint64_t rowToAdd, const CSVReaderConfig* CSVReaderConfig); } // namespace function } // namespace kuzu diff --git a/src/include/function/cast/vector_cast_functions.h b/src/include/function/cast/vector_cast_functions.h index e3d4e163cfb..de830d2ba85 100644 --- a/src/include/function/cast/vector_cast_functions.h +++ b/src/include/function/cast/vector_cast_functions.h @@ -90,10 +90,10 @@ struct CastFunction { template inline static std::unique_ptr bindCastStringToFunction( const std::string& funcName, common::LogicalTypeID targetTypeID) { + scalar_exec_func func = ScalarFunction::UnaryCastStringExecFunction; return std::make_unique(funcName, - std::vector{common::LogicalTypeID::STRING}, targetTypeID, - ScalarFunction::UnaryStringExecFunction); + std::vector{common::LogicalTypeID::STRING}, targetTypeID, func); } }; @@ -171,5 +171,9 @@ struct CastToUInt8Function { static function_set getFunctionSet(); }; +struct CastAnyFunction { + static function_set getFunctionSet(); +}; + } // namespace function } // namespace kuzu diff --git a/src/include/function/comparison/vector_comparison_functions.h b/src/include/function/comparison/vector_comparison_functions.h index 72f1283f37d..df91585407f 100644 --- a/src/include/function/comparison/vector_comparison_functions.h +++ b/src/include/function/comparison/vector_comparison_functions.h @@ -35,7 +35,7 @@ struct ComparisonFunction { template static void BinaryComparisonExecFunction( const std::vector>& params, - common::ValueVector& result) { + common::ValueVector& result, void* /*dataPtr*/ = nullptr) { assert(params.size() == 2); BinaryFunctionExecutor::executeComparison( *params[0], *params[1], result); diff --git a/src/include/function/function.h b/src/include/function/function.h index be9b69ce6c2..fb6e10e1d0c 100644 --- a/src/include/function/function.h +++ b/src/include/function/function.h @@ -1,6 +1,7 @@ #pragma once #include "binder/expression/expression.h" +#include "common/copier_config/copier_config.h" namespace kuzu { namespace function { @@ -13,6 +14,13 @@ struct FunctionBindData { virtual ~FunctionBindData() = default; }; +struct StringCastFunctionBindData : public FunctionBindData { + common::CSVReaderConfig csvConfig; + + StringCastFunctionBindData(common::LogicalType dataType) + : FunctionBindData{std::move(dataType)} {} +}; + struct Function; using scalar_bind_func = std::function( const binder::expression_vector&, Function* definition)>; diff --git a/src/include/function/list/vector_list_functions.h b/src/include/function/list/vector_list_functions.h index 6728d2131ef..7307ca6977e 100644 --- a/src/include/function/list/vector_list_functions.h +++ b/src/include/function/list/vector_list_functions.h @@ -226,7 +226,7 @@ struct ListCreationFunction { static std::unique_ptr bindFunc( const binder::expression_vector& arguments, Function* function); static void execFunc(const std::vector>& parameters, - common::ValueVector& result); + common::ValueVector& result, void* /*dataPtr*/ = nullptr); }; struct ListRangeFunction { diff --git a/src/include/function/null/vector_null_functions.h b/src/include/function/null/vector_null_functions.h index 320e6675457..64cc7e70e25 100644 --- a/src/include/function/null/vector_null_functions.h +++ b/src/include/function/null/vector_null_functions.h @@ -18,7 +18,7 @@ class VectorNullFunction { template static void UnaryNullExecFunction( const std::vector>& params, - common::ValueVector& result) { + common::ValueVector& result, void* /*dataPtr*/ = nullptr) { assert(params.size() == 1); NullOperationExecutor::execute(*params[0], result); } diff --git a/src/include/function/path/vector_path_functions.h b/src/include/function/path/vector_path_functions.h index 51d32b9cbb3..95bce20a78b 100644 --- a/src/include/function/path/vector_path_functions.h +++ b/src/include/function/path/vector_path_functions.h @@ -32,13 +32,13 @@ struct PropertiesFunction { const std::vector>& parameters, std::shared_ptr& result); static void execFunc(const std::vector>& parameters, - common::ValueVector& result); + common::ValueVector& result, void* /*dataPtr*/ = nullptr); }; struct IsTrailFunction { static function_set getFunctionSet(); static void execFunc(const std::vector>& parameters, - common::ValueVector& result); + common::ValueVector& result, void* /*dataPtr*/ = nullptr); static bool selectFunc(const std::vector>& parameters, common::SelectionVector& selectionVector); }; @@ -46,7 +46,7 @@ struct IsTrailFunction { struct IsACyclicFunction { static function_set getFunctionSet(); static void execFunc(const std::vector>& parameters, - common::ValueVector& result); + common::ValueVector& result, void* /*dataPtr*/ = nullptr); static bool selectFunc(const std::vector>& parameters, common::SelectionVector& selectionVector); }; diff --git a/src/include/function/scalar_function.h b/src/include/function/scalar_function.h index 7a080376554..9fdc9e0cc2e 100644 --- a/src/include/function/scalar_function.h +++ b/src/include/function/scalar_function.h @@ -15,7 +15,7 @@ using scalar_compile_func = std::function>&, std::shared_ptr&)>; using scalar_exec_func = std::function>&, common::ValueVector&)>; + const std::vector>&, common::ValueVector&, void*)>; using scalar_select_func = std::function>&, common::SelectionVector&)>; using function_set = std::vector>; @@ -27,6 +27,11 @@ struct ScalarFunction : public BaseScalarFunction { : ScalarFunction{std::move(name), std::move(parameterTypeIDs), returnTypeID, std::move(execFunc), nullptr, nullptr, nullptr, isVarLength} {} + ScalarFunction(std::string name, std::vector parameterTypeIDs, + common::LogicalTypeID returnTypeID, bool isVarLength = false) + : ScalarFunction{std::move(name), std::move(parameterTypeIDs), returnTypeID, nullptr, + nullptr, nullptr, nullptr, isVarLength} {} + ScalarFunction(std::string name, std::vector parameterTypeIDs, common::LogicalTypeID returnTypeID, scalar_exec_func execFunc, scalar_select_func selectFunc, bool isVarLength = false) @@ -51,20 +56,38 @@ struct ScalarFunction : public BaseScalarFunction { template static void TernaryExecFunction(const std::vector>& params, - common::ValueVector& result) { + common::ValueVector& result, void* /*dataPtr*/ = nullptr) { assert(params.size() == 3); TernaryFunctionExecutor::execute( *params[0], *params[1], *params[2], result); } + template + static void TernaryStringExecFunction( + const std::vector>& params, + common::ValueVector& result, void* /*dataPtr*/ = nullptr) { + assert(params.size() == 3); + TernaryFunctionExecutor::executeString( + *params[0], *params[1], *params[2], result); + } + template static void BinaryExecFunction(const std::vector>& params, - common::ValueVector& result) { + common::ValueVector& result, void* /*dataPtr*/ = nullptr) { assert(params.size() == 2); BinaryFunctionExecutor::execute( *params[0], *params[1], result); } + template + static void BinaryStringExecFunction( + const std::vector>& params, + common::ValueVector& result, void* /*dataPtr*/ = nullptr) { + assert(params.size() == 2); + BinaryFunctionExecutor::executeString( + *params[0], *params[1], result); + } + template static bool BinarySelectFunction( const std::vector>& params, @@ -76,7 +99,7 @@ struct ScalarFunction : public BaseScalarFunction { template static void UnaryExecFunction(const std::vector>& params, - common::ValueVector& result) { + common::ValueVector& result, void* /*dataPtr*/) { assert(params.size() == 1); UnaryFunctionExecutor::execute(*params[0], result); } @@ -84,22 +107,31 @@ struct ScalarFunction : public BaseScalarFunction { template static void UnaryStringExecFunction( const std::vector>& params, - common::ValueVector& result) { + common::ValueVector& result, void* /*dataPtr*/ = nullptr) { assert(params.size() == 1); UnaryFunctionExecutor::executeString(*params[0], result); } + template + static void UnaryCastStringExecFunction( + const std::vector>& params, + common::ValueVector& result, void* dataPtr) { + assert(params.size() == 1); + UnaryFunctionExecutor::executeCastString( + *params[0], result, dataPtr); + } + template static void UnaryCastExecFunction( const std::vector>& params, - common::ValueVector& result) { + common::ValueVector& result, void* /*dataPtr*/ = nullptr) { assert(params.size() == 1); UnaryFunctionExecutor::executeCast(*params[0], result); } template static void ConstExecFunction(const std::vector>& params, - common::ValueVector& result) { + common::ValueVector& result, void* /*dataPtr*/ = nullptr) { assert(params.empty()); (void)params; ConstFunctionExecutor::execute(result); @@ -108,7 +140,7 @@ struct ScalarFunction : public BaseScalarFunction { template static void TernaryExecListStructFunction( const std::vector>& params, - common::ValueVector& result) { + common::ValueVector& result, void* /*dataPtr*/ = nullptr) { assert(params.size() == 3); TernaryFunctionExecutor::executeListStruct( *params[0], *params[1], *params[2], result); @@ -117,7 +149,7 @@ struct ScalarFunction : public BaseScalarFunction { template static void BinaryExecListStructFunction( const std::vector>& params, - common::ValueVector& result) { + common::ValueVector& result, void* /*dataPtr*/ = nullptr) { assert(params.size() == 2); BinaryFunctionExecutor::executeListStruct( *params[0], *params[1], result); @@ -126,7 +158,7 @@ struct ScalarFunction : public BaseScalarFunction { template static void UnaryExecListStructFunction( const std::vector>& params, - common::ValueVector& result) { + common::ValueVector& result, void* /*dataPtr*/ = nullptr) { assert(params.size() == 1); UnaryFunctionExecutor::executeListStruct( *params[0], result); diff --git a/src/include/function/schema/vector_label_functions.h b/src/include/function/schema/vector_label_functions.h index ae2ae81d391..878e64a64a8 100644 --- a/src/include/function/schema/vector_label_functions.h +++ b/src/include/function/schema/vector_label_functions.h @@ -8,7 +8,7 @@ namespace function { struct LabelFunction { static void execFunction(const std::vector>& params, - common::ValueVector& result) { + common::ValueVector& result, void* /*dataPtr*/ = nullptr) { assert(params.size() == 2); BinaryFunctionExecutor::executeListExtract(*params[0], *params[1], result); diff --git a/src/include/function/string/vector_string_functions.h b/src/include/function/string/vector_string_functions.h index 8825743475c..896faf5bcfc 100644 --- a/src/include/function/string/vector_string_functions.h +++ b/src/include/function/string/vector_string_functions.h @@ -12,40 +12,13 @@ namespace kuzu { namespace function { struct VectorStringFunction { - - template - static void TernaryStringExecFunction( - const std::vector>& params, - common::ValueVector& result) { - assert(params.size() == 3); - TernaryFunctionExecutor::executeString( - *params[0], *params[1], *params[2], result); - } - - template - static void BinaryStringExecFunction( - const std::vector>& params, - common::ValueVector& result) { - assert(params.size() == 2); - BinaryFunctionExecutor::executeString( - *params[0], *params[1], result); - } - - template - static void UnaryStringExecFunction( - const std::vector>& params, - common::ValueVector& result) { - assert(params.size() == 1); - UnaryFunctionExecutor::executeString(*params[0], result); - } - template static inline function_set getUnaryStrFunction(std::string funcName) { function_set functionSet; functionSet.emplace_back(std::make_unique(funcName, std::vector{common::LogicalTypeID::STRING}, common::LogicalTypeID::STRING, - UnaryStringExecFunction, + ScalarFunction::UnaryStringExecFunction, false /* isVarLength */)); return functionSet; } diff --git a/src/include/function/struct/vector_struct_functions.h b/src/include/function/struct/vector_struct_functions.h index fb8fdc46d65..52951a1c6e3 100644 --- a/src/include/function/struct/vector_struct_functions.h +++ b/src/include/function/struct/vector_struct_functions.h @@ -12,7 +12,7 @@ struct StructPackFunctions { static std::unique_ptr bindFunc( const binder::expression_vector& arguments, Function* function); static void execFunc(const std::vector>& parameters, - common::ValueVector& result); + common::ValueVector& result, void* /*dataPtr*/ = nullptr); static void compileFunc(FunctionBindData* bindData, const std::vector>& parameters, std::shared_ptr& result); diff --git a/src/include/function/udf_function.h b/src/include/function/udf_function.h index 22b49a45c55..0ab9b75a8e0 100644 --- a/src/include/function/udf_function.h +++ b/src/include/function/udf_function.h @@ -95,7 +95,7 @@ struct UDF { validateType(parameterTypes[0]); function::scalar_exec_func execFunc = [=](const std::vector>& params, - common::ValueVector& result) -> void { + common::ValueVector& result, void* /*dataPtr*/ = nullptr) -> void { assert(params.size() == 1); UnaryFunctionExecutor::executeUDF( *params[0], result, (void*)udfFunc); @@ -122,7 +122,7 @@ struct UDF { validateType(parameterTypes[1]); function::scalar_exec_func execFunc = [=](const std::vector>& params, - common::ValueVector& result) -> void { + common::ValueVector& result, void* /*dataPtr*/ = nullptr) -> void { assert(params.size() == 2); BinaryFunctionExecutor::executeUDF(*params[0], *params[1], result, (void*)udfFunc); @@ -150,7 +150,7 @@ struct UDF { validateType(parameterTypes[2]); function::scalar_exec_func execFunc = [=](const std::vector>& params, - common::ValueVector& result) -> void { + common::ValueVector& result, void* /*dataPtr*/ = nullptr) -> void { assert(params.size() == 3); TernaryFunctionExecutor::executeUDF(*params[0], *params[1], *params[2], result, (void*)udfFunc); diff --git a/src/include/function/unary_function_executor.h b/src/include/function/unary_function_executor.h index 5e73a0d9060..8ebb64bf51c 100644 --- a/src/include/function/unary_function_executor.h +++ b/src/include/function/unary_function_executor.h @@ -13,7 +13,7 @@ namespace function { struct UnaryFunctionWrapper { template static inline void operation(OPERAND_TYPE& input, RESULT_TYPE& result, void* /*inputVector*/, - void* /*resultVector*/, void* /*dataPtr*/) { + void* /*resultVector*/, uint64_t /*operand_pos*/, void* /*dataPtr*/) { FUNC::operation(input, result); } }; @@ -21,15 +21,24 @@ struct UnaryFunctionWrapper { struct UnaryStringFunctionWrapper { template static void operation(OPERAND_TYPE& input, RESULT_TYPE& result, void* /*inputVector*/, - void* resultVector, void* /*dataPtr*/) { + void* resultVector, uint64_t /*operand_pos*/, void* /*dataPtr*/) { FUNC::operation(input, result, *(common::ValueVector*)resultVector); } }; +struct UnaryCastStringFunctionWrapper { + template + static void operation(OPERAND_TYPE& input, RESULT_TYPE& result, void* /*inputVector*/, + void* resultVector, uint64_t operand_pos, void* dataPtr) { + FUNC::operation(input, result, (common::ValueVector*)resultVector, operand_pos, + reinterpret_cast(dataPtr)); + } +}; + struct UnaryListFunctionWrapper { template static inline void operation(OPERAND_TYPE& input, RESULT_TYPE& result, void* leftValueVector, - void* resultValueVector, void* /*dataPtr*/) { + void* resultValueVector, uint64_t /*operand_pos*/, void* /*dataPtr*/) { FUNC::operation(input, result, *(common::ValueVector*)leftValueVector, *(common::ValueVector*)resultValueVector); } @@ -38,7 +47,7 @@ struct UnaryListFunctionWrapper { struct UnaryCastFunctionWrapper { template static void operation(OPERAND_TYPE& input, RESULT_TYPE& result, void* inputVector, - void* resultVector, void* /*dataPtr*/) { + void* resultVector, uint64_t /*operand_pos*/, void* /*dataPtr*/) { FUNC::operation( input, result, *(common::ValueVector*)inputVector, *(common::ValueVector*)resultVector); } @@ -47,7 +56,7 @@ struct UnaryCastFunctionWrapper { struct UnaryUDFFunctionWrapper { template static inline void operation(OPERAND_TYPE& input, RESULT_TYPE& result, void* /*inputVector*/, - void* /*resultVector*/, void* dataPtr) { + void* /*resultVector*/, uint64_t /*operand_pos*/, void* dataPtr) { FUNC::operation(input, result, dataPtr); } }; @@ -58,7 +67,7 @@ struct UnaryFunctionExecutor { RESULT_TYPE& resultValue, common::ValueVector& resultValueVector, void* dataPtr) { OP_WRAPPER::template operation( ((OPERAND_TYPE*)operand.getData())[operandPos], resultValue, (void*)&operand, - (void*)&resultValueVector, dataPtr); + (void*)&resultValueVector, operandPos, dataPtr); } template @@ -129,6 +138,12 @@ struct UnaryFunctionExecutor { operand, result, nullptr /* dataPtr */); } + template + static void executeCastString(common::ValueVector& operand, common::ValueVector& result, void* dataPtr) { + executeSwitch( + operand, result, dataPtr); + } + template static void executeCast(common::ValueVector& operand, common::ValueVector& result) { executeSwitch( diff --git a/src/include/function/union/vector_union_functions.h b/src/include/function/union/vector_union_functions.h index d08dddd21e7..c9447bd0a72 100644 --- a/src/include/function/union/vector_union_functions.h +++ b/src/include/function/union/vector_union_functions.h @@ -10,7 +10,7 @@ struct UnionValueFunction { static std::unique_ptr bindFunc( const binder::expression_vector& arguments, Function* function); static void execFunc(const std::vector>& parameters, - common::ValueVector& result); + common::ValueVector& result, void* /*dataPtr*/ = nullptr); static void compileFunc(FunctionBindData* bindData, const std::vector>& parameters, std::shared_ptr& result); diff --git a/src/parser/transform/transform_expression.cpp b/src/parser/transform/transform_expression.cpp index 9c1ad4cac50..f45829c6bcc 100644 --- a/src/parser/transform/transform_expression.cpp +++ b/src/parser/transform/transform_expression.cpp @@ -579,13 +579,14 @@ std::string Transformer::transformPropertyKeyName(CypherParser::OC_PropertyKeyNa std::unique_ptr Transformer::transformIntegerLiteral( CypherParser::OC_IntegerLiteralContext& ctx) { auto text = ctx.DecimalInteger()->getText(); + ku_string_t literal{text.c_str(), text.length()}; int64_t result; - if (function::CastStringToTypes::tryCast(text.c_str(), text.length(), result)) { + if (function::CastStringToTypes::tryCast(literal, result)) { return std::make_unique( std::make_unique(result), ctx.getText()); } int128_t result128; - function::CastStringToTypes::operation(text.c_str(), text.length(), result128); + function::CastStringToTypes::operation(literal, result128); return std::make_unique( std::make_unique(result128), ctx.getText()); } @@ -593,8 +594,9 @@ std::unique_ptr Transformer::transformIntegerLiteral( std::unique_ptr Transformer::transformDoubleLiteral( CypherParser::OC_DoubleLiteralContext& ctx) { auto text = ctx.RegularDecimalReal()->getText(); + ku_string_t literal{text.c_str(), text.length()}; double_t result; - function::CastStringToTypes::operation(text.c_str(), text.length(), result); + function::CastStringToTypes::operation(literal, result); return std::make_unique( std::make_unique(result), ctx.getText()); } diff --git a/src/processor/operator/persistent/copy_to_csv.cpp b/src/processor/operator/persistent/copy_to_csv.cpp index 50d2a129d42..b93e74a048e 100644 --- a/src/processor/operator/persistent/copy_to_csv.cpp +++ b/src/processor/operator/persistent/copy_to_csv.cpp @@ -137,7 +137,7 @@ void CopyToCSVLocalState::writeString(const uint8_t* strData, uint64_t strLen, b void CopyToCSVLocalState::writeRows() { for (auto i = 0u; i < vectorsToCast.size(); i++) { std::vector> vectorToCast = {vectorsToCast[i]}; - castFuncs[i](vectorToCast, *castVectors[i]); + castFuncs[i](vectorToCast, *castVectors[i], nullptr); } uint64_t numRowsToWrite = 1; diff --git a/test/main/udf_test.cpp b/test/main/udf_test.cpp index 3decf3c6f70..83cd5f74813 100644 --- a/test/main/udf_test.cpp +++ b/test/main/udf_test.cpp @@ -192,8 +192,8 @@ TEST_F(ApiTest, TernaryUDFMoreParamType) { "Catalog exception: Expected exactly three parameter types for ternary udf. Got: 4."); } -static void addFour( - const std::vector>& parameters, ValueVector& result) { +static void addFour(const std::vector>& parameters, + ValueVector& result, void* /*dataPtr*/ = nullptr) { assert(parameters.size() == 1); auto parameter = parameters[0]; result.resetAuxiliaryBuffer(); @@ -223,8 +223,8 @@ struct AddDate { } }; -static void addDate( - const std::vector>& parameters, ValueVector& result) { +static void addDate(const std::vector>& parameters, + ValueVector& result, void* /*dataPtr*/ = nullptr) { assert(parameters.size() == 2); function::BinaryFunctionExecutor::execute( *parameters[0], *parameters[1], result); @@ -253,8 +253,8 @@ struct ConditionalConcat { } }; -static void conditionalConcat( - const std::vector>& parameters, ValueVector& result) { +static void conditionalConcat(const std::vector>& parameters, + ValueVector& result, void* /*dataPtr*/ = nullptr) { assert(parameters.size() == 3); function::TernaryFunctionExecutor::executeString(*parameters[0], *parameters[1], *parameters[2], result); diff --git a/test/test_files/tinysnb/cast/cast_error.test b/test/test_files/tinysnb/cast/cast_error.test index 21b15136309..03b809bcc09 100644 --- a/test/test_files/tinysnb/cast/cast_error.test +++ b/test/test_files/tinysnb/cast/cast_error.test @@ -9,89 +9,140 @@ -STATEMENT MATCH (:person)-[e:studyAt]->(:organisation) return to_int64(e.code); ---- error Overflow exception: Value 9223372036854775808 is not within INT64 range +-STATEMENT MATCH (:person)-[e:studyAt]->(:organisation) return cast(e.code, "int64"); +---- error +Overflow exception: Value 9223372036854775808 is not within INT64 range -LOG CastUint64ToInt32OutOfRange -STATEMENT MATCH (:person)-[e:studyAt]->(:organisation) return to_int32(e.code); ---- error Overflow exception: Value 9223372036854775808 is not within INT32 range +-STATEMENT MATCH (:person)-[e:studyAt]->(:organisation) return cast(e.code, "int32"); +---- error +Overflow exception: Value 9223372036854775808 is not within INT32 range --LOG CastInt64ToInt32OutOfRange +-LOG CastStringToInt32OutOfRange -STATEMENT return to_int32("2147483648"); ---- error Conversion exception: Cast failed. 2147483648 is not in INT32 range. +-STATEMENT return cast("2147483648", "int32"); +---- error +Conversion exception: Cast failed. 2147483648 is not in INT32 range. -LOG CastUint32ToInt32OutOfRange -STATEMENT return to_int32(to_uint32(4294967295)); ---- error Overflow exception: Value 4294967295 is not within INT32 range +-STATEMENT return cast(cast(4294967295, "uint32"), "int32"); +---- error +Overflow exception: Value 4294967295 is not within INT32 range -LOG CastUint64ToInt16OutOfRange -STATEMENT MATCH (:person)-[e:studyAt]->(:organisation) return to_int16(e.code); ---- error Overflow exception: Value 9223372036854775808 is not within INT16 range +-STATEMENT MATCH (:person)-[e:studyAt]->(:organisation) return cast(e.code, "int16"); +---- error +Overflow exception: Value 9223372036854775808 is not within INT16 range -LOG CastInt64ToInt16OutOfRange -STATEMENT RETURN to_int16("32768"); ---- error Conversion exception: Cast failed. 32768 is not in INT16 range. +-STATEMENT RETURN cast("32768", "int16"); +---- error +Conversion exception: Cast failed. 32768 is not in INT16 range. -LOG CastUint32ToInt16OutOfRange -STATEMENT MATCH (:person)-[e:studyAt]->(:organisation) return to_int16(e.temprature); ---- error Overflow exception: Value 32800 is not within INT16 range +-STATEMENT MATCH (:person)-[e:studyAt]->(:organisation) return cast(e.temprature, "int16"); +---- error +Overflow exception: Value 32800 is not within INT16 range -LOG CastInt32ToInt16OutOfRange -STATEMENT RETURN to_int16(to_int32("-32770")); ---- error Overflow exception: Value -32770 is not within INT16 range +-STATEMENT RETURN cast(cast("-32770", "int32"), "int16"); +---- error +Overflow exception: Value -32770 is not within INT16 range -LOG CastUint16ToInt16OutOfRange -STATEMENT MATCH (:person)-[e:studyAt]->(:organisation) return to_int16(e.ulength); ---- error Overflow exception: Value 33768 is not within INT16 range +-STATEMENT MATCH (:person)-[e:studyAt]->(:organisation) return cast(e.ulength, "int16"); +---- error +Overflow exception: Value 33768 is not within INT16 range -LOG CastUint64ToInt8OutOfRange -STATEMENT MATCH (:person)-[e:studyAt]->(:organisation) return to_int8(e.code); ---- error Overflow exception: Value 9223372036854775808 is not within INT8 range +-STATEMENT MATCH (:person)-[e:studyAt]->(:organisation) return cast(e.code, "int8"); +---- error +Overflow exception: Value 9223372036854775808 is not within INT8 range -LOG CastInt64ToInt8OutOfRange -STATEMENT return to_int8(-1000); ---- error Overflow exception: Value -1000 is not within INT8 range +-STATEMENT return cast(-1000, "int8"); +---- error +Overflow exception: Value -1000 is not within INT8 range -LOG CastUint32ToInt8OutOfRange -STATEMENT MATCH (:person)-[e:studyAt]->(:organisation) return to_int8(e.temprature); ---- error Overflow exception: Value 32800 is not within INT8 range +-STATEMENT MATCH (:person)-[e:studyAt]->(:organisation) return cast(e.temprature, "int8"); +---- error +Overflow exception: Value 32800 is not within INT8 range -LOG CastInt32ToInt8OutOfRange -STATEMENT return to_int8(to_int32(1000)); ---- error Overflow exception: Value 1000 is not within INT8 range +-STATEMENT return cast(cast(1000, "int32"), "int8"); +---- error +Overflow exception: Value 1000 is not within INT8 range -LOG CastUint16ToInt8OutOfRange -STATEMENT MATCH (:person)-[e:studyAt]->(:organisation) return to_int8(e.ulength); ---- error Overflow exception: Value 33768 is not within INT8 range +-STATEMENT MATCH (:person)-[e:studyAt]->(:organisation) return cast(e.ulength, "int8"); +---- error +Overflow exception: Value 33768 is not within INT8 range -LOG CastInt16ToInt8OutOfRange -STATEMENT return to_int8(to_int16(520)); ---- error Overflow exception: Value 520 is not within INT8 range +-STATEMENT return cast(cast(520, "int16"), "int8"); +---- error +Overflow exception: Value 520 is not within INT8 range -LOG CastUint8ToInt8OutOfRange -STATEMENT MATCH (:person)-[e:studyAt]->(:organisation) return to_int8(e.ulevel); ---- error Overflow exception: Value 250 is not within INT8 range +-STATEMENT MATCH (:person)-[e:studyAt]->(:organisation) return cast(e.ulevel, "int8"); +---- error +Overflow exception: Value 250 is not within INT8 range -LOG CastInt64ToUint64OutOfRange -STATEMENT return to_uint64(-500); ---- error Overflow exception: Value -500 is not within UINT64 range +-STATEMENT return cast(-500, "uint64"); +---- error +Overflow exception: Value -500 is not within UINT64 range -LOG CastInt32ToUint64OutOfRange --STATEMENT return to_uint64(to_int32(-1024)); +-STATEMENT return cast(cast(-1024, "int32"), "uint64"); ---- error Overflow exception: Value -1024 is not within UINT64 range @@ -99,69 +150,99 @@ Overflow exception: Value -1024 is not within UINT64 range -STATEMENT return to_uint64(to_int16(-1)); ---- error Overflow exception: Value -1 is not within UINT64 range +-STATEMENT return cast(cast(-1, "int16"), "uint64"); +---- error +Overflow exception: Value -1 is not within UINT64 range -LOG CastInt8ToUint64OutOfRange -STATEMENT return to_uint64(to_int8(-2)); ---- error Overflow exception: Value -2 is not within UINT64 range +-STATEMENT return cast(cast(-2, "int8"), "uint64"); +---- error +Overflow exception: Value -2 is not within UINT64 range -LOG CastUint64ToUint32OutOfRange -STATEMENT return to_uint32(to_uint64(922337203685477580)); ---- error Overflow exception: Value 922337203685477580 is not within UINT32 range +-STATEMENT return cast(cast(922337203685477580, "uint64"), "uint32"); +---- error +Overflow exception: Value 922337203685477580 is not within UINT32 range -LOG CastInt64ToUint32OutOfRange -STATEMENT return to_uint32(9223372036854775807); ---- error Overflow exception: Value 9223372036854775807 is not within UINT32 range +-STATEMENT return cast(9223372036854775807, "uint32"); +---- error +Overflow exception: Value 9223372036854775807 is not within UINT32 range -LOG CastInt32ToUint32OutOfRange -STATEMENT return to_uint32(to_int32("-10244")); ---- error Overflow exception: Value -10244 is not within UINT32 range +-STATEMENT return cast(cast("-10244", "int32"), "uint32"); +---- error +Overflow exception: Value -10244 is not within UINT32 range -LOG CastInt16ToUint32OutOfRange -STATEMENT return to_uint32(to_int16(-100)); ---- error Overflow exception: Value -100 is not within UINT32 range +-STATEMENT return cast(cast(-100, "int16"), "uint32"); +---- error +Overflow exception: Value -100 is not within UINT32 range -LOG CastInt8ToUint32OutOfRange -STATEMENT return to_uint32(to_int8(-110)); ---- error Overflow exception: Value -110 is not within UINT32 range +-STATEMENT return cast(cast(-110, "int8"), "uint32"); +---- error +Overflow exception: Value -110 is not within UINT32 range -LOG CastUint64ToUint16OutOfRange -STATEMENT return to_uint16(to_uint64(922337203685477580)); ---- error Overflow exception: Value 922337203685477580 is not within UINT16 range +-STATEMENT return cast(cast(922337203685477580, "uint64"), "uint16"); +---- error +Overflow exception: Value 922337203685477580 is not within UINT16 range -LOG CastInt64ToUint16OutOfRange -STATEMENT return to_uint16("922337203685"); ---- error Conversion exception: Cast failed. 922337203685 is not in UINT16 range. +-STATEMENT return cast("922337203685", "uint16"); +---- error +Conversion exception: Cast failed. 922337203685 is not in UINT16 range. -LOG CastUint32ToUint16OutOfRange -STATEMENT return to_uint16(to_uint32(65536)); ---- error Overflow exception: Value 65536 is not within UINT16 range +-STATEMENT return cast(cast(65536, "uint32"), "uint16"); +---- error +Overflow exception: Value 65536 is not within UINT16 range -LOG CastInt32ToUint16OutOfRange --STATEMENT return to_uint16(to_int32("-10244")); +-STATEMENT return cast(cast("-10244", "int32"), "uint16"); ---- error Overflow exception: Value -10244 is not within UINT16 range -LOG CastInt16ToUint16OutOfRange --STATEMENT return to_uint16(to_int16(-100)); +-STATEMENT return cast(cast(-100, "int16"), "uint16"); ---- error Overflow exception: Value -100 is not within UINT16 range -LOG CastInt8ToUint16OutOfRange --STATEMENT return to_uint16(to_int8(-110)); +-STATEMENT return cast(cast(-110, "int8"), "uint16"); ---- error Overflow exception: Value -110 is not within UINT16 range -LOG CastUint64ToUint8OutOfRange --STATEMENT return to_uint8(to_uint64(922337203685477580)); +-STATEMENT return cast(cast(922337203685477580, "uint64"), "uint8"); ---- error Overflow exception: Value 922337203685477580 is not within UINT8 range @@ -169,41 +250,68 @@ Overflow exception: Value 922337203685477580 is not within UINT8 range -STATEMENT return to_uint8(257); ---- error Overflow exception: Value 257 is not within UINT8 range +-STATEMENT return cast(257, "uint8"); +---- error +Overflow exception: Value 257 is not within UINT8 range -LOG CastUint32ToUint8OutOfRange -STATEMENT return to_uint8(to_uint32(300)); ---- error Overflow exception: Value 300 is not within UINT8 range +-STATEMENT return cast(cast(300, "uint32"), "uint8"); +---- error +Overflow exception: Value 300 is not within UINT8 range -LOG CastInt32ToUint8OutOfRange -STATEMENT return to_uint8(to_int32("-10244")); ---- error Overflow exception: Value -10244 is not within UINT8 range +-STATEMENT return cast(cast("-10244", "int32"), "uint8"); +---- error +Overflow exception: Value -10244 is not within UINT8 range -LOG CastUint16ToUint8OutOfRange -STATEMENT return to_uint8(to_uint16(312)); ---- error Overflow exception: Value 312 is not within UINT8 range +-STATEMENT return cast(cast(312, "uint16"), "uint8"); +---- error +Overflow exception: Value 312 is not within UINT8 range + -LOG CastInt16ToUint8OutOfRange -STATEMENT return to_uint8(to_int16(-100)); ---- error Overflow exception: Value -100 is not within UINT8 range +-STATEMENT return cast(cast(-100, "int16"), "uint8"); +---- error +Overflow exception: Value -100 is not within UINT8 range -LOG CastInt8ToUint8OutOfRange -STATEMENT return to_uint8(to_int8(-3)); ---- error Overflow exception: Value -3 is not within UINT8 range +-STATEMENT return cast(cast(-3, "int8"), "uint8"); +---- error +Overflow exception: Value -3 is not within UINT8 range -LOG CastDoubleToInt64OutOfRange -STATEMENT return to_int64(9223372038854775807.452313); ---- error Overflow exception: Value 9223372038854774784.000000 is not within INT64 range +-STATEMENT return cast(9223372038854775807.452313, "int64"); +---- error +Overflow exception: Value 9223372038854774784.000000 is not within INT64 range -LOG CastFloatToUint8OutOfRange -STATEMENT return to_uint8(-728.923); ---- error Overflow exception: Value -728.923000 is not within UINT8 range +-STATEMENT return cast(-728.923, "uint8"); +---- error +Overflow exception: Value -728.923000 is not within UINT8 range + +-LOG CastStringOutoOfRange -STATEMENT RETURN TO_INT32("2147483648"); ---- error Conversion exception: Cast failed. 2147483648 is not in INT32 range. @@ -276,29 +384,116 @@ Conversion exception: Value fasdf is not a valid boolean -STATEMENT RETURN TO_BOOL("fal"); ---- error Conversion exception: Value fal is not a valid boolean +-STATEMENT RETURN cast("2147483648", "int32"); +---- error +Conversion exception: Cast failed. 2147483648 is not in INT32 range. +-STATEMENT RETURN cast("-2147483649", "int32"); +---- error +Conversion exception: Cast failed. -2147483649 is not in INT32 range. +-STATEMENT RETURN cast("32768", "int16"); +---- error +Conversion exception: Cast failed. 32768 is not in INT16 range. +-STATEMENT RETURN cast("-32769", "int16"); +---- error +Conversion exception: Cast failed. -32769 is not in INT16 range. +-STATEMENT RETURN cast("128", "int8"); +---- error +Conversion exception: Cast failed. 128 is not in INT8 range. +-STATEMENT RETURN cast("-129", "int8"); +---- error +Conversion exception: Cast failed. -129 is not in INT8 range. +-STATEMENT RETURN cast("-1", "uint64"); +---- error +Conversion exception: Cast failed. -1 is not in UINT64 range. +-STATEMENT RETURN cast("4294967296", "uint32"); +---- error +Conversion exception: Cast failed. 4294967296 is not in UINT32 range. +-STATEMENT RETURN cast("65536", "uint16"); +---- error +Conversion exception: Cast failed. 65536 is not in UINT16 range. +-STATEMENT RETURN cast("256", "uint8"); +---- error +Conversion exception: Cast failed. 256 is not in UINT8 range. +-STATEMENT RETURN cast("-1", "uint8"); +---- error +Conversion exception: Cast failed. -1 is not in UINT8 range. +-STATEMENT RETURN cast(170141183460469231731687303715884105728, "int128"); +---- error +Conversion exception: Cast failed. 170141183460469231731687303715884105728 is not within INT128 range. +-STATEMENT RETURN cast("-170141183460469231731687303715884105728", "int128"); +---- error +Conversion exception: Cast failed. -170141183460469231731687303715884105728 is not within INT128 range. +-STATEMENT RETURN TO_UINT8(cast(-1, "int128")); +---- error +Overflow exception: Cast failed. Cannot cast -1 to unsigned type. +-STATEMENT RETURN TO_UINT16(cast(-10, "int128")); +---- error +Overflow exception: Cast failed. Cannot cast -10 to unsigned type. +-STATEMENT RETURN TO_UINT64(cast(-15, "int128")); +---- error +Overflow exception: Cast failed. Cannot cast -15 to unsigned type. +-STATEMENT RETURN cast(170141183460469231731687303715884105727, "int128") + cast(10, "int128"); +---- error +Overflow exception: INT128 is out of range: cannot add. +-STATEMENT RETURN cast(-170141183460469231731687303715884105727, "int128") + cast(-10, "int128"); +---- error +Overflow exception: INT128 is out of range: cannot add. +-STATEMENT RETURN cast(170141183460469231731687303715884105727, "int128") - cast(-10, "int128"); +---- error +Overflow exception: INT128 is out of range: cannot subtract. +-STATEMENT RETURN cast(-170141183460469231731687303715884105727, "int128") - cast(10, "int128"); +---- error +Overflow exception: INT128 is out of range: cannot subtract. +-STATEMENT RETURN cast(-170141183460469231731687303715884105727, "int128") * cast(10, "int128"); +---- error +Overflow exception: INT128 is out of range: cannot multiply. +-STATEMENT RETURN cast(170141183460469231731687303715884105727, "int128") * cast(10, "int128"); +---- error +Overflow exception: INT128 is out of range: cannot multiply. +-STATEMENT RETURN cast("fasdf", "boolean"); +---- error +Conversion exception: Value fasdf is not a valid boolean +-STATEMENT RETURN cast("fal", "boolean"); +---- error +Conversion exception: Value fal is not a valid boolean -LOG SerialOutOfRange -STATEMENT RETURN TO_SERIAL(TO_UINT64(9223372036854775807) * TO_UINT64(2)); ---- error Overflow exception: Value 18446744073709551614 is not within INT64 range +-STATEMENT RETURN cast(cast(9223372036854775807, "uint64") * cast(2, "uint64"), "serial"); +---- error +Overflow exception: Value 18446744073709551614 is not within INT64 range -STATEMENT RETURN TO_SERIAL(TO_UINT64(18446744073709551615)); ---- error Overflow exception: Value 18446744073709551615 is not within INT64 range +-STATEMENT RETURN cast(cast(18446744073709551615, "uint64"), "serial"); +---- error +Overflow exception: Value 18446744073709551615 is not within INT64 range -LOG NonAsciiStringToBlob -STATEMENT RETURN BLOB('😀') ---- error Conversion exception: Invalid byte encountered in STRING -> BLOB conversion. All non-ascii characters must be escaped with hex codes (e.g. \xAA) +-STATEMENT RETURN cast('😀', "blob") +---- error +Conversion exception: Invalid byte encountered in STRING -> BLOB conversion. All non-ascii characters must be escaped with hex codes (e.g. \xAA) -LOG StringToBlobInvalidHexCode -STATEMENT RETURN BLOB('\\xgg') ---- error Conversion exception: Invalid hex escape code encountered in string -> blob conversion: \xgg +-STATEMENT RETURN cast('\\xgg', "blob") +---- error +Conversion exception: Invalid hex escape code encountered in string -> blob conversion: \xgg -LOG StringToBlobUnterminatedHexCode -STATEMENT RETURN BLOB('\\xa') ---- error Conversion exception: Invalid hex escape code encountered in string -> blob conversion: unterminated escape code at end of string +-STATEMENT RETURN cast('\\xa', "blob") +---- error +Conversion exception: Invalid hex escape code encountered in string -> blob conversion: unterminated escape code at end of string -LOG INT128CastToError -STATEMENT RETURN TO_SERIAL(TO_INT128(18446744073709551615)); @@ -328,3 +523,62 @@ Overflow exception: Value 18446744073709551615 is not within UINT16 range -STATEMENT RETURN TO_UINT8(TO_INT128(256)); ---- error Overflow exception: Value 256 is not within UINT8 range +-STATEMENT RETURN cast(cast(18446744073709551615, "int128"), "serial"); +---- error +Overflow exception: Value 18446744073709551615 is not within INT64 range +-STATEMENT RETURN cast(cast(18446744073709551615, "int128"), "int64"); +---- error +Overflow exception: Value 18446744073709551615 is not within INT64 range +-STATEMENT RETURN cast(cast(18446744073709551615, "int128"), "int32"); +---- error +Overflow exception: Value 18446744073709551615 is not within INT32 range +-STATEMENT RETURN cast(cast(18446744073709551615, "int128"), "int16"); +---- error +Overflow exception: Value 18446744073709551615 is not within INT16 range +-STATEMENT RETURN cast(cast(18446744073709551615, "int128"), "int8"); +---- error +Overflow exception: Value 18446744073709551615 is not within INT8 range +-STATEMENT RETURN cast(cast(184467440737095516151, "int128"), "uint64"); +---- error +Overflow exception: Value 184467440737095516151 is not within UINT64 range +-STATEMENT RETURN cast(cast(18446744073709551615, "int128"), "uint32"); +---- error +Overflow exception: Value 18446744073709551615 is not within UINT32 range +-STATEMENT RETURN cast(cast(18446744073709551615, "int128"), "uint16"); +---- error +Overflow exception: Value 18446744073709551615 is not within UINT16 range +-STATEMENT RETURN cast(cast(256, "int128"), "uint8"); +---- error +Overflow exception: Value 256 is not within UINT8 range + +-LOG CastFunctionError +-STATEMENT RETURN cast('T', "bool") +---- error +Cannot parse dataTypeID: BOOL +-STATEMENT RETURN cast("fd", "UNION(uint64, int128, BOOLEAN)"); +---- error +Conversion exception: Could not convert to union type UNION(uint64:UINT64, int128:INT128, BOOLEAN:BOOL): fd. +-STATEMENT RETURN cast("{a: 432412343242343241432432444444444444443244}", "STRUCT(a INT128)"); +---- error +Conversion exception: Cast failed. 432412343242343241432432444444444444443244 is not within INT128 range. +-STATEMENT RETURN cast("{a}", "STRUCT(a INT128)"); +---- error +Conversion exception: Cast failed. {a} is not in STRUCT(a:INT128) range. +-STATEMENT RETURN cast("{-12=34}", "MAP(UINT8, UINT16)"); +---- error +Conversion exception: Cast failed. -12 is not in UINT8 range. +-STATEMENT RETURN cast("{} fsdf", "MAP(UINT8, UINT16)"); +---- error +Conversion exception: Cast failed. {} fsdf is not in MAP(UINT8: UINT16) range. +-STATEMENT RETURN cast("[[432343243243254534554654654654234,2,3]]", "INT64[][]"); +---- error +Conversion exception: Cast failed. 432343243243254534554654654654234 is not in INT64 range. +-STATEMENT RETURN cast("[bool]", "INT64[][]"); +---- error +Conversion exception: Cast failed. bool is not in INT64[] range. +-STATEMENT RETURN cast("[[231|4324]", "INT64[][]"); +---- error +Conversion exception: Cast failed. [[231|4324] is not in INT64[][] range. +-STATEMENT RETURN cast("[sdf, fsd, fad]", "STRING[]", "3rd arg"); +---- error +Cannot match a built-in function for given function CAST diff --git a/test/test_files/tinysnb/cast/cast_string_to_nested_types.test b/test/test_files/tinysnb/cast/cast_string_to_nested_types.test index 141c30edf3e..19b905f44cd 100644 --- a/test/test_files/tinysnb/cast/cast_string_to_nested_types.test +++ b/test/test_files/tinysnb/cast/cast_string_to_nested_types.test @@ -168,3 +168,74 @@ Copy exception: Invalid UTF8-encoded string. -STATEMENT LOAD WITH HEADERS (a UNION(v1 INT64, v2 INT32)) FROM "${KUZU_ROOT_DIRECTORY}/dataset/load-from-test/union/union_error.csv" RETURN *; ---- error Conversion exception: Could not convert to union type UNION(v1:INT64, v2:INT32): fdsaf. + +-LOG CastToVarList +-STATEMENT RETURN cast(" [ [ 1 ,3, 423 , 124,43242 ] , [ 432 ]]", "INT64[][]"); +---- 1 +[[1,3,423,124,43242],[432]] +-STATEMENT RETURN cast("[[], [], [] ]", "INT64[][]"); +---- 1 +[[],[],[]] +-STATEMENT RETURN cast("[null, null, [1, 3] ]", "INT64[][]"); +---- 1 +[,,[1,3]] +-STATEMENT RETURN cast("[[null, null], [5, null], [1, 3] ]", "INT64[][]"); +---- 1 +[[,],[5,],[1,3]] +-STATEMENT RETURN cast("[[1,2,3]]", "INT64[][]"); +---- 1 +[[1,2,3]] +-STATEMENT RETURN cast("[this, is, a, list, of, string]", "STRING[]"); +---- 1 +[this, is, a, list, of, string] +-STATEMENT RETURN cast("[x\', ,\',6]", "STRING[]"); +---- 1 +[x', ,',6] +-STATEMENT RETURN cast("[1,2,3]", "UINT8[]"), cast("[1,2,3]", "UINT16[]"), cast("[1,2,3]", "UINT32[]"), cast("[1,2,3]", "UINT64[]"), cast("[1,2,3]", "INT8[]"), cast("[1,2,3]", "INT16[]"), cast("[1,2,3]", "INT32[]"), cast("[1,2,3]", "INT64[]"), cast("[1,2,3]", "INT128[]"), cast("[1,2,3]", "FLOAT[]"), cast("[1,2,3]", "DOUBLE[]"); +---- 1 +[1,2,3]|[1,2,3]|[1,2,3]|[1,2,3]|[1,2,3]|[1,2,3]|[1,2,3]|[1,2,3]|[1,2,3]|[1.000000,2.000000,3.000000]|[1.000000,2.000000,3.000000] +# timestamp/date/... list + +-LOG CastToMap +-STATEMENT RETURN cast(" { c= {a = 3423 }, b = { g = 3421 } } ", "MAP(STRING, MAP(STRING, INT16))"), cast("{}", "MAP(STRING, MAP(STRING, INT16))"), cast("{d = {}}", "MAP(STRING, MAP(STRING, INT16))"); +---- 1 +{c={a=3423}, b={g=3421}}|{}|{d={}} +-STATEMENT LOAD WITH HEADERS (map STRING) FROM "${KUZU_ROOT_DIRECTORY}/dataset/load-from-test/map/nested_map2.csv" RETURN cast(map, "MAP(MAP(INT64, INT64), MAP(STRING, STRING))"); +---- 7 +{{18046=18046, 2=321, 3=423421}={dJ3cf6Y=dJ3cf6Y, dJ3cf6Y=dJ3cf6Y, dJ3cf6Y=dJ3cf6Y}} +{{30099=30099, 1=0}={3mTEf=3mTEf, 3mTEf=3mTEf, 3mTEf=3mTEf}} +{{31395=31395}={}} +{{}={YQcmYouhyFqD3y=YQcmYouhyFqD3y, YQcmYouhyFqD3y=YQcmYouhyFqD3y, YQcmYouhyFqD3y=YQcmYouhyFqD3y}} +{{}={}} +{=} +{} +-STATEMENT RETURN cast("{[432,24,12]={c: okay}, [90,11,43,54]={c: bad}, [0]={c: good}}", "MAP(INT32[], STRUCT(c STRING))"), cast("{[1000,143245,432,43241,-43214324,-432423,-4324324,-41412,-131242143,0,-4324324,0]={}}", "MAP(INT32[], STRUCT(c STRING))"); +---- 1 +{[432,24,12]={c: okay}, [90,11,43,54]={c: bad}, [0]={c: good}}|{[1000,143245,432,43241,-43214324,-432423,-4324324,-41412,-131242143,0,-4324324,0]={c: }} +-STATEMENT RETURN cast("{12=34}", "MAP(UINT8, UINT16)"), cast("{12=}", "MAP(UINT32, UINT64)"), cast("{=43}", "MAP(INT8, INT16)"), cast("{=}", "MAP(INT32, INT64)"), cast("{12=12}", "MAP(float, double)"); +---- 1 +{12=34}|{12=}|{=43}|{=}|{12.000000=12.000000} + +-LOG CastToStruct +-STATEMENT RETURN cast("{ a : { b : {c:[ 3432423 ,-43423 ,31231 ,NULL ]} } } ", "STRUCT(a STRUCT(b STRUCT(c INT64[])))"), cast("{ a : { b : {c:[]} } } ", "STRUCT(a STRUCT(b STRUCT(c INT64[])))"), cast("{ a : { b : {c:} } } ", "STRUCT(a STRUCT(b STRUCT(c INT64[])))"), cast("{ a : { b : {} } } ", "STRUCT(a STRUCT(b STRUCT(c INT64[])))"), cast("{ a : {} } ", "STRUCT(a STRUCT(b STRUCT(c INT64[])))"), cast("{} ", "STRUCT(a STRUCT(b STRUCT(c INT64[])))"); +---- 1 +{a: {b: {c: [3432423,-43423,31231,]}}}|{a: {b: {c: []}}}|{a: {b: {c: }}}|{a: {b: {c: []}}}|{a: {b: {c: []}}}|{a: {b: {c: []}}} +-STATEMENT RETURN cast("{a: 432412343242343241}", "STRUCT(a INT128)"), cast("{a: -44332412343242343241}", "STRUCT(a INT128)"); +---- 1 +{a: 432412343242343241}|{a: -44332412343242343241} + +-LOG CastToUnion +-STATEMENT RETURN cast("324324", "UNION(uint64, int128, BOOLEAN)"), cast("-324324", "UNION(uint64, int128, BOOLEAN)"), cast("false", "UNION(uint64, int128, BOOLEAN)"); +---- 1 +324324|-324324|False +-STATEMENT LOAD WITH HEADERS (u STRING, u2 STRING, u3 STRING, u4 STRING, u5 STRING) FROM "${KUZU_ROOT_DIRECTORY}/dataset/load-from-test/union/union_correct1.csv" RETURN cast(u, "UNION(v1 INT64, v2 BOOLEAN)"), cast(u2, "UNION(v1 UINT32, v2 INT32, v3 DATE)"), cast(u3, "UNION(v1 UINT8, v2 UINT16, v3 TIMESTAMP, v4 FLOAT)"), cast(u4, "UNION(v1 UINT64, v2 INT8, v3 INT16, v4 DOUBLE)"), cast(u5, "UNION(v1 STRING)"); +---- 9 +False|34|255|18446744073709551615|fsdfa +True|432|0|-1.432415|543fasf +34234|4294967295|65535|-128|432 +-42342345|-1|-1.000000|-129|fasf +True|2022-06-06|4324.123047|-32768|fds +True|2019-03-19|-12.343200|32768| +1|-2147483648|1970-01-01 10:00:00.004666|-32769.000000|fsdxcv +0|0|2014-05-12 12:11:59|4324254534123134124032.000000|fsaf +False|-4325|14|18446744073709551616.000000| dfsa diff --git a/test/test_files/tinysnb/function/cast.test b/test/test_files/tinysnb/function/cast.test index 2fe57a96eb4..3b2a3b1a65d 100644 --- a/test/test_files/tinysnb/function/cast.test +++ b/test/test_files/tinysnb/function/cast.test @@ -9,47 +9,74 @@ -STATEMENT MATCH (p:person)-[e:studyAt]->(o:organisation) WHERE p.ID=0 RETURN to_int16(e.level), to_int32(e.level), to_int64(e.level), to_int128(e.level), to_float(e.level), to_double(e.level) ---- 1 5|5|5|5|5.000000|5.000000 +-STATEMENT MATCH (p:person)-[e:studyAt]->(o:organisation) WHERE p.ID=0 RETURN CAST(e.level, "INT16"), CAST(e.level, "INT32"), CAST(e.level, "INT64"), CAST(e.level, "INT128"), CAST(e.level, "FLOAT"), CAST(e.level, "DOUBLE") +---- 1 +5|5|5|5|5.000000|5.000000 -LOG CastFromINT16 -STATEMENT MATCH (p:person)-[e:studyAt]->(o:organisation) WHERE p.ID=0 RETURN to_int8(e.length), to_int32(e.length), to_int64(e.length), to_int128(e.length), to_float(e.length), to_double(e.length) ---- 1 5|5|5|5|5.000000|5.000000 +-STATEMENT MATCH (p:person)-[e:studyAt]->(o:organisation) WHERE p.ID=0 RETURN cast(e.length, "int8"), cast(e.length, "int32"), cast(e.length, "int64"), cast(e.length, "int128"), cast(e.length, "float"), cast(e.length, "double") +---- 1 +5|5|5|5|5.000000|5.000000 -LOG CastFromINT32 -STATEMENT MATCH (m:movies) WHERE m.name='Roma' RETURN to_int16(m.length), to_int64(m.length), to_int128(m.length), to_float(m.length), to_double(m.length) ---- 1 298|298|298|298.000000|298.000000 +-STATEMENT MATCH (m:movies) WHERE m.name='Roma' RETURN cast(m.length, "int16"), cast(m.length, "int64"), cast(m.length, "int128"), cast(m.length, "float"), cast(m.length, "double") +---- 1 +298|298|298|298.000000|298.000000 -LOG CastFromINT64 -STATEMENT MATCH (p:person) WHERE p.ID=0 RETURN to_int8(p.gender), to_int16(p.gender), to_int32(p.gender), to_int128(p.gender), to_float(p.gender), to_double(p.gender) ---- 1 1|1|1|1|1.000000|1.000000 +-STATEMENT MATCH (p:person) WHERE p.ID=0 RETURN cast(p.gender, "int8"), cast(p.gender, "int16"), cast(p.gender, "int32"), cast(p.gender, "int64"), cast(p.gender, "int128"), cast(p.gender, "float"), cast(p.gender, "double") +---- 1 +1|1|1|1|1|1.000000|1.000000 -LOG CastFromUINT8 -STATEMENT MATCH (p:person)-[e:studyAt]->(o:organisation) WHERE p.ID=0 RETURN to_int16(e.ulevel), to_int32(e.ulevel), to_int64(e.ulevel), to_int128(e.ulevel), to_float(e.ulevel), to_double(e.ulevel) ---- 1 250|250|250|250|250.000000|250.000000 +-STATEMENT MATCH (p:person)-[e:studyAt]->(o:organisation) WHERE p.ID=0 RETURN cast(e.ulevel, "int16"), cast(e.ulevel, "int32"), cast(e.ulevel, "int64"), cast(e.ulevel, "int128"), cast(e.ulevel, "float"), cast(e.ulevel, "double") +---- 1 +250|250|250|250|250.000000|250.000000 -LOG CastFromUINT16 -STATEMENT MATCH (p:person)-[e:studyAt]->(o:organisation) WHERE p.ID=2 RETURN to_int8(e.ulength), to_int32(e.ulength), to_int64(e.ulength), to_int128(e.ulength), to_float(e.ulength), to_double(e.ulength) ---- 1 90|90|90|90|90.000000|90.000000 +-STATEMENT MATCH (p:person)-[e:studyAt]->(o:organisation) WHERE p.ID=2 RETURN cast(e.ulength, "uint8"), cast(e.ulength, "uint16"), cast(e.ulength, "uint32"), cast(e.ulength, "uint64"), cast(e.ulength, "float"), cast(e.ulength, "double") +---- 1 +90|90|90|90|90.000000|90.000000 -LOG CastFromUINT32 -STATEMENT MATCH (p:person)-[e:studyAt]->(o:organisation) WHERE p.ID=2 RETURN to_int8(e.temprature), to_int16(e.temprature), to_int32(e.temprature), to_int128(e.temprature), to_float(e.temprature), to_double(e.temprature) ---- 1 1|1|1|1|1.000000|1.000000 +-STATEMENT MATCH (p:person)-[e:studyAt]->(o:organisation) WHERE p.ID=2 RETURN cast(e.temprature, "int8"), cast(e.temprature, "int16"), cast(e.temprature, "int32"), cast(e.temprature, "int128"), cast(e.temprature, "float"), cast(e.temprature, "double") +---- 1 +1|1|1|1|1.000000|1.000000 -LOG CastFromFLOAT -STATEMENT MATCH (p:person) WHERE p.ID=0 RETURN to_int16(p.height), to_int32(p.height), to_int64(p.height), to_int128(p.height), to_double(p.height) ---- 1 2|2|2|1|1.731000 +-STATEMENT MATCH (p:person) WHERE p.ID=0 RETURN cast(p.height, "uint8"), cast(p.height, "int16"), cast(p.height, "int32"), cast(p.height, "int64"), cast(p.height, "int128"), cast(p.height, "double"), cast(p.height, "float") +---- 1 +2|2|2|2|1|1.731000|1.731000 -LOG CastFromDOUBLE -STATEMENT MATCH (p:person) WHERE p.ID=0 RETURN to_int16(p.eyeSight), to_int32(p.eyeSight), to_int64(p.eyeSight), to_int128(p.eyeSight), to_float(p.eyeSight) ---- 1 5|5|5|5|5.000000 +-STATEMENT MATCH (p:person) WHERE p.ID=0 RETURN cast(p.eyeSight, "uint8"), cast(p.eyeSight, "uint16"), cast(p.eyeSight, "uint32"), cast(p.eyeSight, "int32"), cast(p.eyeSight, "int64"), cast(p.eyeSight, "int128"), cast(p.eyeSight, "float"), cast(p.eyeSight, "double") +---- 1 +5|5|5|5|5|5|5.000000|5.000000 -CASE CastDataTypeToString @@ -71,6 +98,16 @@ True False False +-STATEMENT MATCH (p:person) RETURN cast(p.isStudent, "string") +---- 9 +True +True +False +False +False +True +False +False -LOG CastInt64ToString -STATEMENT MATCH (p:person) RETURN string(p.age) @@ -84,6 +121,17 @@ False 40 83 +-STATEMENT MATCH (p:person) RETURN cast(p.age, "string") +---- 9 +35 +30 +45 +20 +20 +25 +40 +83 + -LOG CastInt32ToString -STATEMENT MATCH (m:movies) RETURN string(m.length) @@ -91,6 +139,11 @@ False 126 2544 298 +-STATEMENT MATCH (m:movies) RETURN CAST(m.length, "STRING") +---- 3 +126 +2544 +298 -LOG CastInt16ToString -STATEMENT MATCH (p:person)-[s:studyAt]->(o:organisation) RETURN string(s.length) @@ -98,6 +151,11 @@ False 5 55 22 +-STATEMENT MATCH (p:person)-[s:studyAt]->(o:organisation) RETURN CAST(s.length, "STRING") +---- 3 +5 +55 +22 -LOG CastInt8ToString -STATEMENT MATCH (p:person)-[s:studyAt]->(o:organisation) RETURN string(s.level) @@ -105,6 +163,11 @@ False 5 120 2 +-STATEMENT MATCH (p:person)-[s:studyAt]->(o:organisation) RETURN cast(s.level, "string") +---- 3 +5 +120 +2 -LOG CastDoubleToString -STATEMENT MATCH (p:person) RETURN string(p.eyeSight) @@ -118,6 +181,17 @@ False 4.900000 4.900000 +-STATEMENT MATCH (p:person) RETURN cast(p.eyeSight, "string") +---- 9 +5.000000 +5.100000 +5.000000 +4.800000 +4.700000 +4.500000 +4.900000 +4.900000 + -LOG CastFloatToString -STATEMENT MATCH (p:person) RETURN string(p.height) @@ -131,6 +205,17 @@ False 1.600000 1.323000 +-STATEMENT MATCH (p:person) RETURN cast(p.height, "string") +---- 9 +1.731000 +0.990000 +1.000000 +1.300000 +1.463000 +1.510000 +1.600000 +1.323000 + -LOG CastDateToString -STATEMENT MATCH (p:person) RETURN string(p.birthdate) @@ -144,6 +229,17 @@ False 1980-10-26 1990-11-27 +-STATEMENT MATCH (p:person) RETURN cast(p.birthdate, "string") +---- 9 +1900-01-01 +1900-01-01 +1940-06-22 +1950-07-23 +1980-10-26 +1980-10-26 +1980-10-26 +1990-11-27 + -LOG CastTimestampToString -STATEMENT MATCH (p:person) RETURN string(p.registerTime) @@ -157,6 +253,17 @@ False 1976-12-23 04:41:42 2023-02-21 13:25:30 +-STATEMENT MATCH (p:person) RETURN cast(p.registerTime, "string") +---- 9 +2011-08-20 11:25:30 +2008-11-03 15:25:30.000526 +1911-08-20 02:32:21 +2031-11-30 12:25:30 +1976-12-23 11:21:42 +1972-07-31 13:22:30.678559 +1976-12-23 04:41:42 +2023-02-21 13:25:30 + -LOG CastIntervalToString -STATEMENT MATCH (p:person) RETURN string(p.lastJobDuration) @@ -170,6 +277,17 @@ False 10 years 5 months 13:00:00.000024 3 years 2 days 13:02:00 +-STATEMENT MATCH (p:person) RETURN cast(p.lastJobDuration, "string") +---- 9 +3 years 2 days 13:02:00 +10 years 5 months 13:00:00.000024 +48:24:11 +10 years 5 months 13:00:00.000024 +48:24:11 +00:18:00.024 +10 years 5 months 13:00:00.000024 +3 years 2 days 13:02:00 + -LOG CastStringToString -STATEMENT MATCH (p:person) RETURN string(p.fName) @@ -183,6 +301,17 @@ Farooq Greg Hubert Blaine Wolfeschlegelsteinhausenbergerdorff +-STATEMENT MATCH (p:person) RETURN cast(p.fName, "string") +---- 9 +Alice +Bob +Carol +Dan +Elizabeth +Farooq +Greg +Hubert Blaine Wolfeschlegelsteinhausenbergerdorff + -LOG CastListOfIntsToString -STATEMENT MATCH (p:person) RETURN string(p.workedHours) @@ -196,6 +325,17 @@ Hubert Blaine Wolfeschlegelsteinhausenbergerdorff [1] [10,11,12,3,4,5,6,7] +-STATEMENT MATCH (p:person) RETURN cast(p.workedHours, "string") +---- 9 +[10,5] +[12,8] +[4,5] +[1,9] +[2] +[3,4,5,6,7] +[1] +[10,11,12,3,4,5,6,7] + -LOG CastListOfListOfIntsToString -STATEMENT MATCH (p:person) RETURN string(p.courseScoresPerTerm) @@ -209,6 +349,17 @@ Hubert Blaine Wolfeschlegelsteinhausenbergerdorff [[10]] [[7],[10],[6,7]] +-STATEMENT MATCH (p:person) RETURN cast(p.courseScoresPerTerm, "string") +---- 9 +[[10,8],[6,7,8]] +[[8,9],[9,10]] +[[8,10]] +[[7,4],[8,8],[9]] +[[6],[7],[8]] +[[8]] +[[10]] +[[7],[10],[6,7]] + -LOG CastFixedListToString -STATEMENT MATCH (p:person) where p.ID > 1 RETURN string(p.grades) @@ -221,12 +372,28 @@ Hubert Blaine Wolfeschlegelsteinhausenbergerdorff [43,83,67,43] [77,64,100,54] +-STATEMENT MATCH (p:person) where p.ID > 1 RETURN cast(p.grades, "string") +---- 8 +[98,42,93,88] +[91,75,21,95] +[76,88,99,89] +[96,59,65,88] +[80,78,34,83] +[43,83,67,43] +[77,64,100,54] + + -LOG CastMapToString -STATEMENT MATCH (m:movies) RETURN string(m.audience) ---- 3 {audience1=33} {audience1=52, audience53=42} {} +-STATEMENT MATCH (m:movies) RETURN cast(m.audience, "string") +---- 3 +{audience1=33} +{audience1=52, audience53=42} +{} -LOG CastInternalIDToString -STATEMENT MATCH (p:person) RETURN string(id(p)) @@ -240,6 +407,17 @@ Hubert Blaine Wolfeschlegelsteinhausenbergerdorff 0:6 0:7 0:8 +-STATEMENT MATCH (p:person) RETURN cast(id(p), "string") +---- 9 +0:0 +0:1 +0:2 +0:3 +0:4 +0:5 +0:6 +0:7 +0:8 -LOG CastStructToString -STATEMENT MATCH (o:organisation) RETURN string(o.state) @@ -248,6 +426,12 @@ Hubert Blaine Wolfeschlegelsteinhausenbergerdorff {revenue: 152, location: ["vanco,uver north area"], stock: {price: [15,78,671], volume: 432}} {revenue: 558, location: ['very long city name', 'new york'], stock: {price: [22], volume: 99}} +-STATEMENT MATCH (o:organisation) RETURN cast(o.state, "string") +---- 4 +{revenue: 138, location: ['toronto', 'montr,eal'], stock: {price: [96,56], volume: 1000}} +{revenue: 152, location: ["vanco,uver north area"], stock: {price: [15,78,671], volume: 432}} +{revenue: 558, location: ['very long city name', 'new york'], stock: {price: [22], volume: 99}} + -LOG CastUnionToString -STATEMENT MATCH (o:organisation) RETURN string(o.info) @@ -256,6 +440,12 @@ Hubert Blaine Wolfeschlegelsteinhausenbergerdorff abcd 2023-12-15 +-STATEMENT MATCH (o:organisation) RETURN cast(o.info, "string") +---- 4 +3.120000 +abcd +2023-12-15 + -CASE DataTypeCasting -LOG CastInt8ToDouble @@ -264,6 +454,11 @@ abcd 5.000000 120.000000 2.000000 +-STATEMENT MATCH (:person)-[e:studyAt]->(:organisation) RETURN cast(e.level, "double") +---- 3 +5.000000 +120.000000 +2.000000 -LOG CastInt8ToFloat -STATEMENT MATCH (:person)-[e:studyAt]->(:organisation) RETURN to_float(e.level) @@ -271,6 +466,11 @@ abcd 5.000000 120.000000 2.000000 +-STATEMENT MATCH (:person)-[e:studyAt]->(:organisation) RETURN cast(e.level, "float") +---- 3 +5.000000 +120.000000 +2.000000 -LOG CastInt8ToInt64 -STATEMENT MATCH (:person)-[e:studyAt]->(:organisation) RETURN to_int64(e.level) @@ -278,6 +478,11 @@ abcd 5 120 2 +-STATEMENT MATCH (:person)-[e:studyAt]->(:organisation) RETURN cast(e.level, "int64") +---- 3 +5 +120 +2 -LOG CastInt8ToUInt8 -STATEMENT MATCH (:person)-[e:studyAt]->(:organisation) RETURN to_uint8(e.level) @@ -285,6 +490,11 @@ abcd 5 120 2 +-STATEMENT MATCH (:person)-[e:studyAt]->(:organisation) RETURN cast(e.level, "uint8") +---- 3 +5 +120 +2 -LOG CastInt8ToUInt32 -STATEMENT MATCH (:person)-[e:studyAt]->(:organisation) RETURN to_uint32(e.level) @@ -292,6 +502,11 @@ abcd 5 120 2 +-STATEMENT MATCH (:person)-[e:studyAt]->(:organisation) RETURN cast(e.level, "uint32") +---- 3 +5 +120 +2 -LOG CastInt16ToDouble -STATEMENT MATCH (:person)-[e:studyAt]->(:organisation) RETURN to_double(e.length) @@ -299,6 +514,11 @@ abcd 5.000000 55.000000 22.000000 +-STATEMENT MATCH (:person)-[e:studyAt]->(:organisation) RETURN cast(e.length, "double") +---- 3 +5.000000 +55.000000 +22.000000 -LOG CastInt16ToFloat -STATEMENT MATCH (:person)-[e:studyAt]->(:organisation) RETURN to_float(e.length) @@ -306,6 +526,11 @@ abcd 5.000000 55.000000 22.000000 +-STATEMENT MATCH (:person)-[e:studyAt]->(:organisation) RETURN cast(e.length, "float") +---- 3 +5.000000 +55.000000 +22.000000 -LOG CastInt16ToInt64 -STATEMENT MATCH (:person)-[e:studyAt]->(:organisation) RETURN to_int64(e.length) @@ -313,6 +538,11 @@ abcd 5 55 22 +-STATEMENT MATCH (:person)-[e:studyAt]->(:organisation) RETURN cast(e.length, "int64") +---- 3 +5 +55 +22 -LOG CastInt16ToInt32 -STATEMENT MATCH (:person)-[e:studyAt]->(:organisation) RETURN to_int32(e.length) @@ -320,6 +550,11 @@ abcd 5 55 22 +-STATEMENT MATCH (:person)-[e:studyAt]->(:organisation) RETURN cast(e.length, "int32") +---- 3 +5 +55 +22 -LOG CastInt16ToInt8 -STATEMENT MATCH (:person)-[e:studyAt]->(:organisation) RETURN to_int8(e.length) @@ -327,6 +562,48 @@ abcd 5 55 22 +-STATEMENT MATCH (:person)-[e:studyAt]->(:organisation) RETURN cast(e.length, "int8") +---- 3 +5 +55 +22 + +-LOG CastInt16ToUINT64 +-STATEMENT MATCH (:person)-[e:studyAt]->(:organisation) RETURN cast(e.length, "uint64") +---- 3 +5 +55 +22 + +-LOG CastInt16ToUINT32 +-STATEMENT MATCH (:person)-[e:studyAt]->(:organisation) RETURN cast(e.length, "uint32") +---- 3 +5 +55 +22 + + +-LOG CastInt16ToUINT16 +-STATEMENT MATCH (:person)-[e:studyAt]->(:organisation) RETURN cast(e.length, "uint16") +---- 3 +5 +55 +22 + + +-LOG CastInt16ToUINT8 +-STATEMENT MATCH (:person)-[e:studyAt]->(:organisation) RETURN cast(e.length, "uint8") +---- 3 +5 +55 +22 + +-LOG CastInt16ToINT128 +-STATEMENT MATCH (:person)-[e:studyAt]->(:organisation) RETURN cast(e.length, "int128") +---- 3 +5 +55 +22 -LOG CastInt32ToDouble -STATEMENT MATCH (m:movies) RETURN to_double(m.length) @@ -334,6 +611,11 @@ abcd 126.000000 2544.000000 298.000000 +-STATEMENT MATCH (m:movies) RETURN cast(m.length, "double") +---- 3 +126.000000 +2544.000000 +298.000000 -LOG CastInt32ToFloat -STATEMENT MATCH (m:movies) RETURN to_float(m.length) @@ -341,6 +623,11 @@ abcd 126.000000 2544.000000 298.000000 +-STATEMENT MATCH (m:movies) RETURN cast(m.length, "float") +---- 3 +126.000000 +2544.000000 +298.000000 -LOG CastInt32ToInt64 -STATEMENT MATCH (m:movies) RETURN to_int64(m.length) @@ -348,17 +635,31 @@ abcd 126 2544 298 +-STATEMENT MATCH (m:movies) RETURN cast(m.length, "int64") +---- 3 +126 +2544 +298 -LOG CastUIntToInt -STATEMENT RETURN TO_INT64(TO_UINT64(9223372036854775807)); ---- 1 9223372036854775807 +-STATEMENT RETURN cast(cast(9223372036854775807, "uint64"), "int64"); +---- 1 +9223372036854775807 -STATEMENT RETURN TO_INT32(TO_UINT64("43242")); ---- 1 43242 +-STATEMENT RETURN cast(cast("43242", "uint64"), "int32"); +---- 1 +43242 -STATEMENT RETURN TO_INT32(TO_UINT32("43242")); ---- 1 43242 +-STATEMENT RETURN cast(cast("43242", "uint32"), "int32"); +---- 1 +43242 -LOG CastInt64ToInt8 -STATEMENT MATCH (p:person) RETURN to_int8(p.age) @@ -371,27 +672,49 @@ abcd 25 40 83 +-STATEMENT MATCH (p:person) RETURN cast(p.age, "int8") +---- 8 +35 +30 +45 +20 +20 +25 +40 +83 -LOG CastFloatDoubleToInt8 -STATEMENT Return to_int8(1.1), to_int8(to_float(3.2)) ---- 1 1|3 +-STATEMENT Return cast(1.1, "int8"), cast(cast(3.2, "float"), "int8") +---- 1 +1|3 -LOG CastNumericalToInt8 -STATEMENT Return to_int8(to_int64(1)), to_int8(to_int32(2)), to_int8(to_int16(3)), to_int8(to_int8(4)), to_int8(to_uint8(5)), to_int8(to_uint16(6)), to_int8(to_uint32(7)), to_int8(to_uint64(8)), to_int8(to_int128(9)) ---- 1 1|2|3|4|5|6|7|8|9 +-STATEMENT Return cast(cast(1, "int64"), "int8"), cast(cast(2, "int32"), "int8"), cast(cast(3, "int16"), "int8"), cast(cast(4, "int8"), "int8"), cast(cast(5, "uint8"), "int8"), cast(cast(6, "uint16"), "int8"), cast(cast(7, "uint32"), "int8"), cast(cast(8, "uint64"), "int8"), cast(cast(9, "int128"), "int8"), cast(cast(10, "float"), "int8"), cast(cast(11, "double"), "int8") +---- 1 +1|2|3|4|5|6|7|8|9|10|11 -LOG CastNumericalToUInt8 -STATEMENT Return to_uint8(to_int64(1)), to_uint8(to_int32(2)), to_uint8(to_int16(3)), to_uint8(to_int8(4)), to_uint8(to_uint16(6)), to_uint8(to_uint32(7)), to_uint8(to_uint64(8)), to_uint8(to_int128(9)) ---- 1 1|2|3|4|6|7|8|9 +-STATEMENT Return cast(cast(1, "int64"), "uint8"), cast(cast(2, "int32"), "uint8"), cast(cast(3, "int16"), "uint8"), cast(cast(4, "int8"), "uint8"), cast(cast(5, "uint8"), "uint8"), cast(cast(6, "uint16"), "uint8"), cast(cast(7, "uint32"), "uint8"), cast(cast(8, "uint64"), "uint8"), cast(cast(9, "int128"), "uint8"), cast(cast(10, "float"), "uint8"), cast(cast(11, "double"), "uint8") +---- 1 +1|2|3|4|5|6|7|8|9|10|11 -LOG CastNumericalToUInt16 -STATEMENT Return to_uint16(to_int64(1)), to_uint16(to_int32(2)), to_uint16(to_int16(3)), to_uint16(to_int8(4)), to_uint16(to_uint8(5)), to_uint16(to_uint32(7)), to_uint16(to_uint64(8)), to_uint16(to_int128(9)) ---- 1 1|2|3|4|5|7|8|9 +-STATEMENT Return cast(cast(1, "int64"), "uint16"), cast(cast(2, "int32"), "uint16"), cast(cast(3, "int16"), "uint16"), cast(cast(4, "int8"), "uint16"), cast(cast(5, "uint8"), "uint16"), cast(cast(6, "uint16"), "uint16"), cast(cast(7, "uint32"), "uint16"), cast(cast(8, "uint64"), "uint16"), cast(cast(9, "int128"), "uint16"), cast(cast(10, "float"), "uint16"), cast(cast(11, "double"), "uint16") +---- 1 +1|2|3|4|5|6|7|8|9|10|11 -LOG CastUnsignedIntToFLoatDouble -STATEMENT Return to_float(to_uint64(1)), to_double(to_uint64(2)), to_float(to_uint32(3)), to_double(to_uint32(4)), to_float(to_uint16(5)), to_double(to_uint16(6)), to_float(to_uint8(7)), to_double(to_uint8(8)) @@ -402,16 +725,25 @@ abcd -STATEMENT Return to_uint32(to_int64(1)), to_uint32(to_int32(2)), to_uint32(to_int16(3)), to_uint32(to_int8(4)), to_uint32(to_uint8(5)), to_uint32(to_uint16(6)), to_uint32(to_uint64(8)), to_uint32(to_int128(9)) ---- 1 1|2|3|4|5|6|8|9 +-STATEMENT Return cast(cast(1, "int64"), "uint32"), cast(cast(2, "int32"), "uint32"), cast(cast(3, "int16"), "uint32"), cast(cast(4, "int8"), "uint32"), cast(cast(5, "uint16"), "uint32"), cast(cast(6, "uint8"), "uint32"), cast(cast(7, "uint32"), "uint32"), cast(cast(8, "uint64"), "uint32"), cast(cast(9, "int128"), "uint32"), cast(cast(10, "float"), "uint32"), cast(cast(11, "double"), "uint32") +---- 1 +1|2|3|4|5|6|7|8|9|10|11 -LOG CastNumericalToUInt64 --STATEMENT Return to_uint64(to_int64(1)), to_uint64(to_int32(2)), to_uint64(to_int16(3)), to_uint64(to_int8(4)), to_uint64(to_uint8(5)), to_uint64(to_uint16(6)), to_uint64(to_uint32(7)), to_uint64(to_int128(9)) +-STATEMENT Return to_uint64(to_int64(1)), to_uint64(to_int32(2)), to_uint64(to_int16(3)), to_uint64(to_int8(4)), to_uint64(to_uint8(5)), to_uint64(to_uint32(6)), to_uint64(to_uint32(7)), to_uint64(to_int128(9)) ---- 1 1|2|3|4|5|6|7|9 +-STATEMENT Return cast(cast(1, "int64"), "uint64"), cast(cast(2, "int32"), "uint64"), cast(cast(3, "int64"), "uint64"), cast(cast(4, "int64"), "uint64"), cast(cast(5, "uint8"), "uint64"), cast(cast(6, "uint16"), "uint64"), cast(cast(7, "uint64"), "uint64"), cast(cast(8, "uint64"), "uint64"), cast(cast(9, "int128"), "uint64"), cast(cast(10, "float"), "uint64"), cast(cast(11, "double"), "uint64") +---- 1 +1|2|3|4|5|6|7|8|9|10|11 -LOG CastNumericalToInt128 -STATEMENT Return to_int128(to_int64(1)), to_int128(to_int32(2)), to_int128(to_int16(3)), to_int128(to_int8(4)), to_int128(to_uint8(5)), to_int128(to_uint16(6)), to_int128(to_uint32(7)), to_int128(to_uint64(8)) ---- 1 1|2|3|4|5|6|7|8 +-STATEMENT Return cast(cast(1, "int64"), "int128"), cast(cast(2, "int32"), "int128"), cast(cast(3, "int64"), "int128"), cast(cast(4, "int64"), "int128"), cast(cast(5, "uint8"), "int128"), cast(cast(6, "uint16"), "int128"), cast(cast(7, "uint64"), "int128"), cast(cast(8, "uint64"), "int128"), cast(cast(9, "int128"), "int128"), cast(cast(10, "float"), "int128"), cast(cast(11, "double"), "int128") +---- 1 +1|2|3|4|5|6|7|8|9|10|11 -LOG CastInt64ToDouble -STATEMENT MATCH (p:person) RETURN to_double(p.age) @@ -424,6 +756,16 @@ abcd 25.000000 40.000000 83.000000 +-STATEMENT MATCH (p:person) RETURN cast(p.age, "double") +---- 8 +35.000000 +30.000000 +45.000000 +20.000000 +20.000000 +25.000000 +40.000000 +83.000000 -LOG CastInt64ToFloat -STATEMENT MATCH (p:person) RETURN to_float(p.gender) @@ -436,16 +778,45 @@ abcd 2.000000 2.000000 2.000000 +-STATEMENT MATCH (p:person) RETURN cast(p.gender, "float") +---- 8 +1.000000 +2.000000 +1.000000 +2.000000 +1.000000 +2.000000 +2.000000 +2.000000 + +-LOG CastInt64ToSerial +-STATEMENT MATCH (p:person) RETURN cast(p.gender, "Serial") +---- 8 +1 +2 +1 +2 +1 +2 +2 +2 -LOG CastDoubleToUInt -STATEMENT RETURN to_uint8(to_double(1)), to_uint16(to_double(2)), to_uint32(to_double(3)), to_uint64(to_double(4)), to_int128(to_double(5)) ---- 1 1|2|3|4|5 +-STATEMENT RETURN cast(cast(1, "double"), "uint8"), cast(cast(2, "double"), "uint16"), cast(cast(3, "double"), "uint32"), cast(cast(4, "double"), "uint64"), cast(cast(5, "double"), "int128") +---- 1 +1|2|3|4|5 -LOG CastFloatToUInt -STATEMENT RETURN to_uint8(to_float(1)), to_uint16(to_float(2)), to_uint32(to_float(3)), to_uint64(to_float(4)), to_int128(to_float(5)) ---- 1 1|2|3|4|5 +-LOG CastFloatToUInt +-STATEMENT RETURN cast(cast(1, "float"), "uint8"), cast(cast(2, "float"), "uint16"), cast(cast(3, "float"), "uint32"), cast(cast(4, "float"), "uint64"), cast(cast(5, "float"), "int128") +---- 1 +1|2|3|4|5 -LOG CastFloatToDouble -STATEMENT MATCH (p:person) RETURN to_double(p.height) @@ -458,6 +829,16 @@ abcd 1.510000 1.600000 1.323000 +-STATEMENT MATCH (p:person) RETURN cast(p.height, "double") +---- 8 +1.731000 +0.990000 +1.000000 +1.300000 +1.463000 +1.510000 +1.600000 +1.323000 -LOG CastStringToNum -STATEMENT RETURN TO_INT64("12"); @@ -556,6 +937,99 @@ False -STATEMENT RETURN TO_DATE("2022-10-21"); ---- 1 2022-10-21 +-STATEMENT RETURN cast("12", "int64"); +---- 1 +12 +-STATEMENT RETURN cast("9223372036854775807", "int64"); +---- 1 +9223372036854775807 +-STATEMENT RETURN cast("9223372036854775807", "serial"); +---- 1 +9223372036854775807 +-STATEMENT RETURN cast("-9223372036854775808", "serial"); +---- 1 +-9223372036854775808 +-STATEMENT RETURN cast("2147483647", "int32"); +---- 1 +2147483647 +-STATEMENT RETURN cast("-2147483648", "int32"); +---- 1 +-2147483648 +-STATEMENT RETURN cast("32767", "int16"); +---- 1 +32767 +-STATEMENT RETURN cast("-32768", "int16"); +---- 1 +-32768 +-STATEMENT RETURN cast("0", "int8"); +---- 1 +0 +-STATEMENT RETURN cast("-128", "int8"); +---- 1 +-128 +-STATEMENT RETURN cast("0", "uint64"); +---- 1 +0 +-STATEMENT RETURN cast("4320492", "uint64"); +---- 1 +4320492 +-STATEMENT RETURN cast("4294967295", "uint32"); +---- 1 +4294967295 +-STATEMENT RETURN cast("65535", "uint16"); +---- 1 +65535 +-STATEMENT RETURN cast("255", "uint8"); +---- 1 +255 +-STATEMENT RETURN cast("1844674407370955161811111111", "int128"); +---- 1 +1844674407370955161811111111 +-STATEMENT RETURN cast(" 3.294", "float"); +---- 1 +3.294000 +-STATEMENT RETURN cast("3.294", "float"); +---- 1 +3.294000 +-STATEMENT RETURN cast("0.99", "float"); +---- 1 +0.990000 +-STATEMENT RETURN cast("42341.43299123", "float"); +---- 1 +42341.433594 +-STATEMENT RETURN cast("3.294 ", "double"); +---- 1 +3.294000 +-STATEMENT RETURN cast(" 3.294 ", "double"); +---- 1 +3.294000 +-STATEMENT RETURN cast("TRUE", "boolean"); +---- 1 +True +-STATEMENT RETURN cast("1", "boolean"); +---- 1 +True +-STATEMENT RETURN cast("tRUE", "boolean"); +---- 1 +True +-STATEMENT RETURN cast(" t ", "boolean"); +---- 1 +True +-STATEMENT RETURN cast("T ", "boolean"); +---- 1 +True +-STATEMENT RETURN cast("false", "boolean"); +---- 1 +False +-STATEMENT RETURN cast(" F", "boolean"); +---- 1 +False +-STATEMENT RETURN cast("0", "boolean"); +---- 1 +False +-STATEMENT RETURN cast("0", "boolean"); +---- 1 +False -LOG CastDoubleToFloat -STATEMENT MATCH (p:person) RETURN to_float(p.eyeSight) @@ -568,23 +1042,45 @@ False 4.500000 4.900000 4.900000 +-STATEMENT MATCH (p:person) RETURN cast(p.eyeSight, "float") +---- 8 +5.000000 +5.100000 +5.000000 +4.800000 +4.700000 +4.500000 +4.900000 +4.900000 -LOG CastNumericalToINT128Test -STATEMENT RETURN to_int8(to_int128(1)), to_int16(to_int128(2)), to_int32(to_int128(3)), to_int64(to_int128(4)), to_uint8(to_int128(5)), to_uint16(to_int128(6)), to_uint32(to_int128(7)), to_uint64(to_int128(8)) ---- 1 1|2|3|4|5|6|7|8 +-STATEMENT RETURN cast(cast(1, "int128"), "int8"), cast(cast(2, "int128"), "int16"), cast(cast(3, "int128"), "int32"), cast(cast(4, "int128"), "int64"), cast(cast(5, "int128"), "int128"), cast(cast(6, "int128"), "uint8"), cast(cast(7, "int128"), "uint16"), cast(cast(8, "int128"), "uint32"), cast(cast(9, "int128"), "uint64"), cast(cast(10, "int128"), "double"), cast(cast(11, "int128"), "float"), cast(cast(12, "int128"), "string") +---- 1 +1|2|3|4|5|6|7|8|9|10.000000|11.000000|12 -LOG CastInt128ToOtherTypes -STATEMENT RETURN TO_FLOAT(170141183460469231731687303715884105727), TO_INT64(-4324324); ---- 1 170141183460469231731687303715884105728.000000|-4324324 +-STATEMENT RETURN cast(170141183460469231731687303715884105727, "float"), cast(-4324324, "int64"); +---- 1 +170141183460469231731687303715884105728.000000|-4324324 -LOG CastNegInt128ToFloatDouble -STATEMENT Return to_float(to_int128(-15)), to_double(to_int128(-1)), to_float(to_int128(15)), to_double(to_int128(1)) ---- 1 -15.000000|-1.000000|15.000000|1.000000 +-STATEMENT Return cast(cast(-15, "int128"), "float"), cast(cast(-1, "int128"), "double"), cast(cast(15, "int128"), "float"), cast(cast(1, "int128"), "double") +---- 1 +-15.000000|-1.000000|15.000000|1.000000 -LOG CastFloatDoubleToInt128 -STATEMENT Return to_int128(to_float(-15)), to_int128(to_double(-1)), to_int128(to_float(15)), to_int128(to_double(1)) ---- 1 -15|-1|15|1 +-STATEMENT Return cast(cast(-15, "float"), "int128"), cast(cast(-1, "double"), "int128"), cast(cast(15, "float"), "int128"), cast(cast(1, "double"), "int128") +---- 1 +-15|-1|15|1 diff --git a/test/test_files/tinysnb/function/list.test b/test/test_files/tinysnb/function/list.test index 9ee81775223..ad92aa7b61f 100644 --- a/test/test_files/tinysnb/function/list.test +++ b/test/test_files/tinysnb/function/list.test @@ -428,11 +428,17 @@ ad -STATEMENT RETURN LIST_CONCAT([1,2,NULL], [to_int64(NULL)]) ---- 1 [1,2,,] +-STATEMENT RETURN LIST_CONCAT([1,2,NULL], [cast(NULL, "int64")]) +---- 1 +[1,2,,] -LOG ListConcatNullAndINT64 -STATEMENT RETURN LIST_CONCAT([to_int64(NULL)], [NULL, 1, 3]) ---- 1 [,,1,3] +-STATEMENT RETURN LIST_CONCAT([cast(NULL, "int64")], [NULL, 1, 3]) +---- 1 +[,,1,3] -LOG ListAppendListOfINT64 -STATEMENT MATCH (a:person) RETURN list_append(a.workedHours, a.age) @@ -1096,26 +1102,41 @@ True -STATEMENT Return list_sort([to_int8(2), to_int8(3), to_int8(1), NULL, NULL]); ---- 1 [,,1,2,3] +-STATEMENT Return list_sort([cast(2, "int8"), cast(3, "int8"), cast(1, "int8"), NULL, NULL]); +---- 1 +[,,1,2,3] -LOG ListSortInt8Desc -STATEMENT Return list_sort([to_int8(2), to_int8(3), to_int8(1), to_int8(5), NULL], 'DESC'); ---- 1 [,5,3,2,1] +-STATEMENT Return list_sort([cast(2, "int8"), cast(3, "int8"), cast(1, "int8"), cast(5, "int8"), NULL], 'DESC'); +---- 1 +[,5,3,2,1] -LOG ListSortInt16Asc -STATEMENT Return list_sort([to_int16(2), to_int16(3), to_int16(1), NULL, NULL]); ---- 1 [,,1,2,3] +-STATEMENT Return list_sort([cast(2, "int16"), cast(3, "int16"), cast(1, "int16"), NULL, NULL]); +---- 1 +[,,1,2,3] -LOG ListSortInt16Desc -STATEMENT Return list_sort([to_int16(2), to_int16(3), to_int16(1), to_int16(5), NULL], 'DESC'); ---- 1 [,5,3,2,1] +-STATEMENT Return list_sort([cast(2, "int16"), cast(3, "int16"), cast(1, "int16"), to_int16(5), NULL], 'DESC'); +---- 1 +[,5,3,2,1] -LOG ListSortInt16DescWithNullsLast -STATEMENT Return list_sort([to_int16(2), to_int16(3), to_int16(1), NULL], 'DESC', 'NULLS LAST'); ---- 1 [3,2,1,] +-STATEMENT Return list_sort([cast(2, "int16"), cast(3, "int16"), cast(1, "int16"), NULL], 'DESC', 'NULLS LAST'); +---- 1 +[3,2,1,] -LOG ListSortInt32Asc -STATEMENT Return list_sort([to_int32(2), to_int32(3), to_int32(1), NULL, NULL]);