diff --git a/dataset/reader/union_correct.csv b/dataset/reader/union_correct.csv new file mode 100644 index 0000000000..df9c6a3239 --- /dev/null +++ b/dataset/reader/union_correct.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" diff --git a/src/binder/bind/bind_graph_pattern.cpp b/src/binder/bind/bind_graph_pattern.cpp index 7a4e20eb55..6f89edbcd1 100644 --- a/src/binder/bind/bind_graph_pattern.cpp +++ b/src/binder/bind/bind_graph_pattern.cpp @@ -398,12 +398,14 @@ std::pair Binder::bindVariableLengthRelBound( const kuzu::parser::RelPattern& relPattern) { auto recursiveInfo = relPattern.getRecursiveInfo(); uint32_t lowerBound; - function::CastStringToTypes::operation( - recursiveInfo->lowerBound.c_str(), recursiveInfo->lowerBound.length(), lowerBound); + function::CastString::operation( + 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); + function::CastString::operation( + 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 88aed511b9..64e310a4db 100644 --- a/src/binder/bind_expression/bind_function_expression.cpp +++ b/src/binder/bind_expression/bind_function_expression.cpp @@ -59,17 +59,23 @@ std::shared_ptr ExpressionBinder::bindScalarFunctionExpression( auto function = reinterpret_cast( builtInFunctions->matchScalarFunction(functionName, childrenTypes)); 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; - if (function->bindFunc) { - bindData = function->bindFunc(childrenAfterCast, function); + if (functionName == CAST_FUNC_NAME) { + bindData = function->bindFunc(children, function); + childrenAfterCast.push_back( + implicitCastIfNecessary(children[0], function->parameterTypeIDs[0])); } else { - bindData = - std::make_unique(LogicalType(function->returnTypeID)); + 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)); + } + if (function->bindFunc) { + bindData = function->bindFunc(childrenAfterCast, function); + } else { + bindData = + std::make_unique(LogicalType(function->returnTypeID)); + } } auto uniqueExpressionName = ScalarFunctionExpression::getUniqueName(function->name, childrenAfterCast); @@ -253,8 +259,8 @@ 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), - std::move(children), execFunc, nullptr, uniqueExpressionName); + return std::make_shared(LABEL_FUNC_NAME, FUNCTION, + std::move(bindData), std::move(children), execFunc, nullptr, uniqueExpressionName); } std::unique_ptr ExpressionBinder::createInternalLengthExpression( diff --git a/src/binder/expression/function_expression.cpp b/src/binder/expression/function_expression.cpp index f3f4dd21f5..3ae6f6dfc7 100644 --- a/src/binder/expression/function_expression.cpp +++ b/src/binder/expression/function_expression.cpp @@ -6,7 +6,7 @@ namespace kuzu { namespace binder { std::string ScalarFunctionExpression::getUniqueName( - const std::string& functionName, kuzu::binder::expression_vector& children) { + const std::string& functionName, const kuzu::binder::expression_vector& children) { auto result = functionName + "("; for (auto& child : children) { result += child->getUniqueName() + ", "; @@ -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 c8a189d5fe..05aa619eb5 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::CastString::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 1f81183426..f1db589b9c 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 46b37062e2..549dc438ab 100644 --- a/src/expression_evaluator/function_evaluator.cpp +++ b/src/expression_evaluator/function_evaluator.cpp @@ -21,8 +21,15 @@ void FunctionExpressionEvaluator::evaluate() { for (auto& child : children) { child->evaluate(); } + auto expr = reinterpret_cast(expression.get()); + if (expr->getFunctionName() == CAST_FUNC_NAME && + parameters[0]->dataType.getLogicalTypeID() == LogicalTypeID::STRING) { + execFunc(parameters, *resultVector, + reinterpret_cast(expr->getBindData())); + return; + } if (execFunc != nullptr) { - execFunc(parameters, *resultVector); + execFunc(parameters, *resultVector, nullptr); } } @@ -34,7 +41,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 0ab534eb4e..fd8be389f4 100644 --- a/src/function/built_in_functions.cpp +++ b/src/function/built_in_functions.cpp @@ -68,6 +68,9 @@ Function* BuiltInFunctions::matchScalarFunction( uint32_t minCost = UINT32_MAX; for (auto& function : functionSet) { auto func = reinterpret_cast(function.get()); + if (name == CAST_FUNC_NAME) { + return func; + } auto cost = getFunctionCost(inputTypes, func, isOverload); if (cost == UINT32_MAX) { continue; @@ -597,6 +600,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 3d37f5ef4a..a30abc049e 100644 --- a/src/function/cast_string_to_functions.cpp +++ b/src/function/cast_string_to_functions.cpp @@ -13,27 +13,119 @@ using namespace kuzu::common; namespace kuzu { namespace function { +// ---------------------- cast String Helper ------------------------------ // +struct CastStringHelper { + 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 CastStringHelper::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 CastStringHelper::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 CastStringHelper::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 CastStringHelper::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 CastStringHelper::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 CastStringHelper::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 CastStringHelper::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 CastStringHelper::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 CastStringHelper::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 CastStringHelper::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 CastStringHelper::cast(const char* input, uint64_t len, bool& result, + ValueVector* /*vector*/, uint64_t /*rowToAdd*/, const CSVReaderConfig* /*csvReaderConfig*/) { + castStringToBool(input, len, result); +} + +template<> +inline void CastStringHelper::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 CastStringHelper::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 CastStringHelper::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 CastString::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*/, - ValueVector* vector, uint64_t rowToAdd, const CSVReaderConfig* /*CSVReaderConfig*/) { +void CastStringHelper::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); auto blobBuffer = std::make_unique(len); @@ -137,7 +229,7 @@ struct SplitStringListOperation { ValueVector* resultVector; void handleValue(const char* start, const char* end, const CSVReaderConfig* csvReaderConfig) { - CastStringToTypes::copyStringToVector(resultVector, offset, + CastString::copyStringToVector(resultVector, offset, std::string_view{start, (uint32_t)(end - start)}, csvReaderConfig); offset++; } @@ -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 CastStringHelper::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 CastString::operation(const ku_string_t& input, list_entry_t& result, + ValueVector* resultVector, uint64_t rowToAdd, const CSVReaderConfig* csvReaderConfig) { + CastStringHelper::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); + CastStringHelper::cast(start, str.length(), value); resultVector->setValue(offset, value); offset++; } @@ -296,15 +395,15 @@ struct SplitStringMapOperation { inline bool handleKey( const char* start, const char* end, const CSVReaderConfig* csvReaderConfig) { trimRightWhitespace(start, end); - CastStringToTypes::copyStringToVector(StructVector::getFieldVector(resultVector, 0).get(), - offset, std::string_view{start, (uint32_t)(end - start)}, csvReaderConfig); + CastString::copyStringToVector(StructVector::getFieldVector(resultVector, 0).get(), offset, + std::string_view{start, (uint32_t)(end - start)}, csvReaderConfig); return true; } inline void handleValue( const char* start, const char* end, const CSVReaderConfig* csvReaderConfig) { trimRightWhitespace(start, end); - CastStringToTypes::copyStringToVector(StructVector::getFieldVector(resultVector, 1).get(), + CastString::copyStringToVector(StructVector::getFieldVector(resultVector, 1).get(), offset++, std::string_view{start, (uint32_t)(end - start)}, csvReaderConfig); } }; @@ -379,7 +478,7 @@ static bool splitCStringMap( } template<> -void CastStringToTypes::operation(const char* input, uint64_t len, common::map_entry_t& /*result*/, +void CastStringHelper::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 CastString::operation(const ku_string_t& input, map_entry_t& result, ValueVector* resultVector, + uint64_t rowToAdd, const CSVReaderConfig* CSVReaderConfig) { + CastStringHelper::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) { @@ -475,7 +581,7 @@ static bool tryCastStringToStruct(const char* input, uint64_t len, ValueVector* trimRightWhitespace(valStart, valEnd); skipWhitespace(++input, end); - CastStringToTypes::copyStringToVector(StructVector::getFieldVector(vector, fieldIdx).get(), + CastString::copyStringToVector(StructVector::getFieldVector(vector, fieldIdx).get(), rowToAdd, std::string_view{valStart, (uint32_t)(valEnd - valStart)}, csvReaderConfig); if (closeBracket) { @@ -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 CastStringHelper::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 CastString::operation(const ku_string_t& input, struct_entry_t& result, + ValueVector* resultVector, uint64_t rowToAdd, const CSVReaderConfig* csvReaderConfig) { + CastStringHelper::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,8 +707,8 @@ static bool tryCastUnionField( } template<> -void CastStringToTypes::operation(const char* input, uint64_t len, union_entry_t& /*result*/, - ValueVector* vector, uint64_t rowToAdd, const CSVReaderConfig* /*CSVReaderConfig**/) { +void CastStringHelper::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,8 +734,15 @@ void CastStringToTypes::operation(const char* input, uint64_t len, union_entry_t ->setNull(rowToAdd, false /* isNull */); } -void CastStringToTypes::copyStringToVector(ValueVector* vector, uint64_t rowToAdd, - std::string_view strVal, const CSVReaderConfig* csvReaderConfig) { +template<> +void CastString::operation(const ku_string_t& input, union_entry_t& result, + ValueVector* resultVector, uint64_t rowToAdd, const CSVReaderConfig* CSVReaderConfig) { + CastStringHelper::cast(reinterpret_cast(input.getData()), input.len, result, + resultVector, rowToAdd, CSVReaderConfig); +} + +void CastString::copyStringToVector(ValueVector* vector, uint64_t rowToAdd, std::string_view strVal, + const CSVReaderConfig* csvReaderConfig) { auto& type = vector->dataType; if (strVal.empty() || isNull(strVal)) { @@ -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); + CastStringHelper::cast(strVal.data(), strVal.length(), val); vector->setValue(rowToAdd, val); } break; case LogicalTypeID::INT64: { int64_t val; - operation(strVal.data(), strVal.length(), val); + CastStringHelper::cast(strVal.data(), strVal.length(), val); vector->setValue(rowToAdd, val); } break; case LogicalTypeID::INT32: { int32_t val; - operation(strVal.data(), strVal.length(), val); + CastStringHelper::cast(strVal.data(), strVal.length(), val); vector->setValue(rowToAdd, val); } break; case LogicalTypeID::INT16: { int16_t val; - operation(strVal.data(), strVal.length(), val); + CastStringHelper::cast(strVal.data(), strVal.length(), val); vector->setValue(rowToAdd, val); } break; case LogicalTypeID::INT8: { int8_t val; - operation(strVal.data(), strVal.length(), val); + CastStringHelper::cast(strVal.data(), strVal.length(), val); vector->setValue(rowToAdd, val); } break; case LogicalTypeID::UINT64: { uint64_t val; - operation(strVal.data(), strVal.length(), val); + CastStringHelper::cast(strVal.data(), strVal.length(), val); vector->setValue(rowToAdd, val); } break; case LogicalTypeID::UINT32: { uint32_t val; - operation(strVal.data(), strVal.length(), val); + CastStringHelper::cast(strVal.data(), strVal.length(), val); vector->setValue(rowToAdd, val); } break; case LogicalTypeID::UINT16: { uint16_t val; - operation(strVal.data(), strVal.length(), val); + CastStringHelper::cast(strVal.data(), strVal.length(), val); vector->setValue(rowToAdd, val); } break; case LogicalTypeID::UINT8: { uint8_t val; - operation(strVal.data(), strVal.length(), val); + CastStringHelper::cast(strVal.data(), strVal.length(), val); vector->setValue(rowToAdd, val); } break; case LogicalTypeID::FLOAT: { float_t val; - operation(strVal.data(), strVal.length(), val); + CastStringHelper::cast(strVal.data(), strVal.length(), val); vector->setValue(rowToAdd, val); } break; case LogicalTypeID::DOUBLE: { double_t val; - operation(strVal.data(), strVal.length(), val); + CastStringHelper::cast(strVal.data(), strVal.length(), val); vector->setValue(rowToAdd, val); } break; case LogicalTypeID::BOOL: { bool val; - operation(strVal.data(), strVal.length(), val); + CastStringHelper::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); + CastStringHelper::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); + CastStringHelper::cast(strVal.data(), strVal.length(), val); vector->setValue(rowToAdd, val); } break; case LogicalTypeID::TIMESTAMP: { timestamp_t val; - operation(strVal.data(), strVal.length(), val); + CastStringHelper::cast(strVal.data(), strVal.length(), val); vector->setValue(rowToAdd, val); } break; case LogicalTypeID::INTERVAL: { interval_t val; - operation(strVal.data(), strVal.length(), val); + CastStringHelper::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); + CastStringHelper::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); + CastStringHelper::cast( + strVal.data(), strVal.length(), val, vector, rowToAdd, csvReaderConfig); } break; case LogicalTypeID::FIXED_LIST: { // TODO: add fix list function wrapper @@ -727,14 +855,16 @@ 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); + CastStringHelper::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); + CastStringHelper::cast( + strVal.data(), strVal.length(), val, vector, rowToAdd, csvReaderConfig); } break; default: { // LCOV_EXCL_START - throw NotImplementedException("CastStringToTypes::operation"); + throw NotImplementedException("CastString::operation"); } // LCOV_EXCL_STOP } } diff --git a/src/function/vector_blob_functions.cpp b/src/function/vector_blob_functions.cpp index 1de9d1110d..3f0509ef0d 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 55ee4f827e..f71bbbc303 100644 --- a/src/function/vector_cast_functions.cpp +++ b/src/function/vector_cast_functions.cpp @@ -1,5 +1,8 @@ #include "function/cast/vector_cast_functions.h" +#include "binder/binder.h" +#include "binder/expression/literal_expression.h" +#include "common/exception/binder.h" #include "function/cast/functions/cast_functions.h" using namespace kuzu::common; @@ -127,20 +130,20 @@ 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; + func = + sourceTypeID == LogicalTypeID::STRING ? + &ScalarFunction::UnaryCastStringExecFunction : + &ScalarFunction::UnaryExecFunction; return; } case LogicalTypeID::INTERVAL: { assert(sourceTypeID == LogicalTypeID::STRING); - func = &ScalarFunction::UnaryStringExecFunction; + func = &ScalarFunction::UnaryCastStringExecFunction; return; } default: @@ -197,8 +200,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()) { @@ -299,6 +302,138 @@ void CastToStringFunction::getUnaryCastToStringExecFunction( } } +void CastFunction::getNumericalCastFunc( + common::LogicalTypeID srcTypeID, common::LogicalTypeID dstTypeID, scalar_exec_func& func) { + switch (dstTypeID) { + case common::LogicalTypeID::FLOAT: { + bindImplicitNumericalCastFunc(srcTypeID, func); + } break; + case common::LogicalTypeID::DOUBLE: { + bindImplicitNumericalCastFunc(srcTypeID, func); + } break; + case common::LogicalTypeID::SERIAL: { + bindImplicitNumericalCastFunc(srcTypeID, func); + } break; + case common::LogicalTypeID::INT128: { + bindImplicitNumericalCastFunc(srcTypeID, func); + } break; + case common::LogicalTypeID::INT64: { + bindImplicitNumericalCastFunc(srcTypeID, func); + } break; + case common::LogicalTypeID::INT32: { + bindImplicitNumericalCastFunc(srcTypeID, func); + } break; + case common::LogicalTypeID::INT16: { + bindImplicitNumericalCastFunc(srcTypeID, func); + } break; + case common::LogicalTypeID::INT8: { + bindImplicitNumericalCastFunc(srcTypeID, func); + } break; + case common::LogicalTypeID::UINT64: { + bindImplicitNumericalCastFunc(srcTypeID, func); + } break; + case common::LogicalTypeID::UINT32: { + bindImplicitNumericalCastFunc(srcTypeID, func); + } break; + case common::LogicalTypeID::UINT16: { + bindImplicitNumericalCastFunc(srcTypeID, func); + } break; + case common::LogicalTypeID::UINT8: { + bindImplicitNumericalCastFunc(srcTypeID, func); + } break; + default: + throw common::NotImplementedException( + "Unimplemented casting Function from " + + common::LogicalTypeUtils::dataTypeToString(srcTypeID) + " to numeric."); + } +} + +void CastFunction::getCastStringExecFunc(common::LogicalTypeID dstTypeID, scalar_exec_func& func) { + switch (dstTypeID) { + case common::LogicalTypeID::FLOAT: { + func = + ScalarFunction::UnaryCastStringExecFunction; + } break; + case common::LogicalTypeID::DOUBLE: { + func = + ScalarFunction::UnaryCastStringExecFunction; + } break; + case common::LogicalTypeID::INT128: { + func = + ScalarFunction::UnaryCastStringExecFunction; + } break; + case common::LogicalTypeID::SERIAL: + case common::LogicalTypeID::INT64: { + func = + ScalarFunction::UnaryCastStringExecFunction; + } break; + case common::LogicalTypeID::INT32: { + func = + ScalarFunction::UnaryCastStringExecFunction; + } break; + case common::LogicalTypeID::INT16: { + func = + ScalarFunction::UnaryCastStringExecFunction; + } break; + case common::LogicalTypeID::INT8: { + func = ScalarFunction::UnaryCastStringExecFunction; + } break; + case common::LogicalTypeID::UINT64: { + func = + ScalarFunction::UnaryCastStringExecFunction; + } break; + case common::LogicalTypeID::UINT32: { + func = + ScalarFunction::UnaryCastStringExecFunction; + } break; + case common::LogicalTypeID::UINT16: { + func = + ScalarFunction::UnaryCastStringExecFunction; + } break; + case common::LogicalTypeID::UINT8: { + func = + ScalarFunction::UnaryCastStringExecFunction; + } break; + case common::LogicalTypeID::BOOL: { + func = ScalarFunction::UnaryCastStringExecFunction; + } break; + case common::LogicalTypeID::DATE: { + func = ScalarFunction::UnaryCastStringExecFunction; + } break; + case common::LogicalTypeID::INTERVAL: { + func = ScalarFunction::UnaryCastStringExecFunction; + } break; + case common::LogicalTypeID::TIMESTAMP: { + func = ScalarFunction::UnaryCastStringExecFunction; + } break; + case common::LogicalTypeID::BLOB: { + func = ScalarFunction::UnaryCastStringExecFunction; + } break; + case common::LogicalTypeID::VAR_LIST: { + func = ScalarFunction::UnaryCastStringExecFunction; + } break; + case common::LogicalTypeID::MAP: { + func = ScalarFunction::UnaryCastStringExecFunction; + } break; + case common::LogicalTypeID::STRUCT: { + func = ScalarFunction::UnaryCastStringExecFunction; + } break; + case common::LogicalTypeID::UNION: { + func = ScalarFunction::UnaryCastStringExecFunction; + } break; + default: + throw common::NotImplementedException( + "Unimplemented casting Function from string to " + + common::LogicalTypeUtils::dataTypeToString(dstTypeID) + "."); + } +} + function_set CastToStringFunction::getFunctionSet() { function_set result; // ANY -> STRING @@ -460,5 +595,48 @@ function_set CastToUInt8Function::getFunctionSet() { return result; } +void CastAnyFunction::getUnaryCastExecFunction( + LogicalTypeID srcTypeID, LogicalTypeID dstTypeID, scalar_exec_func& func) { + if (dstTypeID == LogicalTypeID::STRING) { + CastToStringFunction::getUnaryCastToStringExecFunction(srcTypeID, func); + } else if (srcTypeID == LogicalTypeID::STRING) { + CastFunction::getCastStringExecFunc(dstTypeID, func); + } else { + CastFunction::getNumericalCastFunc(srcTypeID, dstTypeID, func); + } +} + +std::unique_ptr CastAnyFunction::bindFunc( + const binder::expression_vector& arguments, Function* function) { + // check the size of the arguments + if (arguments.size() != 2) { + throw BinderException("Invalid number of arguments for given function CAST."); + } + + auto inputTypeID = arguments[0]->dataType.getLogicalTypeID(); + if (inputTypeID == LogicalTypeID::ANY) { + inputTypeID = LogicalTypeID::STRING; + } + auto str = ((binder::LiteralExpression&)*arguments[1]).getValue()->getValue(); + auto outputType = binder::Binder::bindDataType(str); + auto func = reinterpret_cast(function); + func->name = "CAST_TO_" + str; + func->parameterTypeIDs[0] = inputTypeID; + getUnaryCastExecFunction(inputTypeID, outputType->getLogicalTypeID(), func->execFunc); + + if (inputTypeID == LogicalTypeID::STRING) { + return std::make_unique(*outputType); + } + return std::make_unique(*outputType); +} + +function_set CastAnyFunction::getFunctionSet() { + function_set result; + result.push_back(std::make_unique(CAST_FUNC_NAME, + std::vector{LogicalTypeID::ANY}, LogicalTypeID::ANY, nullptr, nullptr, + bindFunc, false)); + return result; +} + } // namespace function } // namespace kuzu diff --git a/src/function/vector_list_functions.cpp b/src/function/vector_list_functions.cpp index c276f1fc28..9821fcaeee 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 9b75a2ad49..bcbe959156 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 340173c93a..1dd010d284 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,8 @@ function_set LpadFunction::getFunctionSet() { std::vector{ LogicalTypeID::STRING, LogicalTypeID::INT64, LogicalTypeID::STRING}, LogicalTypeID::STRING, - TernaryStringExecFunction, + ScalarFunction::TernaryStringExecFunction, false /* isVarLength */)); return functionSet; } @@ -187,7 +189,8 @@ 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 +199,8 @@ 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 +211,8 @@ function_set RpadFunction::getFunctionSet() { std::vector{ LogicalTypeID::STRING, LogicalTypeID::INT64, LogicalTypeID::STRING}, LogicalTypeID::STRING, - TernaryStringExecFunction, + ScalarFunction::TernaryStringExecFunction, false /* isVarLength */)); return functionSet; } @@ -229,7 +234,8 @@ function_set SubStrFunction::getFunctionSet() { std::vector{ LogicalTypeID::STRING, LogicalTypeID::INT64, LogicalTypeID::INT64}, LogicalTypeID::STRING, - TernaryStringExecFunction, + ScalarFunction::TernaryStringExecFunction, false /* isVarLength */)); return functionSet; } @@ -264,8 +270,8 @@ function_set RegexpReplaceFunction::getFunctionSet() { std::vector{ LogicalTypeID::STRING, LogicalTypeID::STRING, LogicalTypeID::STRING}, LogicalTypeID::STRING, - TernaryStringExecFunction, + ScalarFunction::TernaryStringExecFunction, false /* isVarLength */)); return functionSet; } @@ -275,13 +281,15 @@ 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 +299,14 @@ function_set RegexpExtractAllFunction::getFunctionSet() { functionSet.emplace_back(make_unique(REGEXP_EXTRACT_FUNC_NAME, std::vector{LogicalTypeID::STRING, LogicalTypeID::STRING}, LogicalTypeID::VAR_LIST, - BinaryStringExecFunction, nullptr, - bindFunc, false /* isVarLength */)); + 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 32a425e3c9..fed3c74436 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 2abca59f8d..1e608aaab9 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/binder.h b/src/include/binder/binder.h index 90657589b5..d212240f88 100644 --- a/src/include/binder/binder.h +++ b/src/include/binder/binder.h @@ -82,6 +82,8 @@ class Binder { return expressionBinder.parameterMap; } + static std::unique_ptr bindDataType(const std::string& dataType); + private: std::shared_ptr bindWhereExpression( const parser::ParsedExpression& parsedExpression); @@ -93,8 +95,6 @@ class Binder { std::shared_ptr createVariable( const std::string& name, const common::LogicalType& dataType); - static std::unique_ptr bindDataType(const std::string& dataType); - /*** bind DDL ***/ std::unique_ptr bindCreateTableInfo(const parser::CreateTableInfo* info); std::unique_ptr bindCreateNodeTableInfo( diff --git a/src/include/binder/expression/function_expression.h b/src/include/binder/expression/function_expression.h index d4357b425c..ecbbf487ba 100644 --- a/src/include/binder/expression/function_expression.h +++ b/src/include/binder/expression/function_expression.h @@ -57,7 +57,8 @@ class ScalarFunctionExpression : public FunctionExpression { execFunc{std::move(execFunc)}, selectFunc{std::move(selectFunc)}, compileFunc{std::move( compileFunc)} {} - static std::string getUniqueName(const std::string& functionName, expression_vector& children); + static std::string getUniqueName( + const std::string& functionName, const expression_vector& children); std::string toStringInternal() const final; diff --git a/src/include/common/enums/expression_type.h b/src/include/common/enums/expression_type.h index 9e2a1cfd07..87abf22c25 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 273a04ae3a..73d27d3b06 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/function/boolean/vector_boolean_functions.h b/src/include/function/boolean/vector_boolean_functions.h index 43f1eba249..2b5e1ed58e 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/cast/functions/cast_string_to_functions.h b/src/include/function/cast/functions/cast_string_to_functions.h index b7c3bcbb78..92800e2ef7 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); +struct CastString { + 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 CastString::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 CastString::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 CastString::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 CastString::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 CastString::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 CastString::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 CastString::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 CastString::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 CastString::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 CastString::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 CastString::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 CastString::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 CastString::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 CastString::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 CastString::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 CastString::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 CastString::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 CastString::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 CastString::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 e3d4e163cf..415c5b525b 100644 --- a/src/include/function/cast/vector_cast_functions.h +++ b/src/include/function/cast/vector_cast_functions.h @@ -87,13 +87,18 @@ struct CastFunction { } } + static void getNumericalCastFunc( + common::LogicalTypeID srcTypeID, common::LogicalTypeID dstTypeID, scalar_exec_func& func); + + static void getCastStringExecFunc(common::LogicalTypeID dstTypeID, scalar_exec_func& func); + template inline static std::unique_ptr bindCastStringToFunction( const std::string& funcName, common::LogicalTypeID targetTypeID) { return std::make_unique(funcName, std::vector{common::LogicalTypeID::STRING}, targetTypeID, - ScalarFunction::UnaryStringExecFunction); + ScalarFunction::UnaryCastStringExecFunction); } }; @@ -171,5 +176,13 @@ struct CastToUInt8Function { static function_set getFunctionSet(); }; +struct CastAnyFunction { + static void getUnaryCastExecFunction( + common::LogicalTypeID srcTypeID, common::LogicalTypeID dstTypeID, scalar_exec_func& func); + static std::unique_ptr bindFunc( + const binder::expression_vector& arguments, Function* function); + 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 72f1283f37..df91585407 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 be9b69ce6c..fb6e10e1d0 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 6728d2131e..7307ca6977 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 320e667545..64cc7e70e2 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 51d32b9cbb..95bce20a78 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 7a08037655..daee6b960c 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>; @@ -51,20 +51,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 +94,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 +102,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 +135,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 +144,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 +153,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 ae2ae81d39..878e64a64a 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/schema/vector_node_rel_functions.h b/src/include/function/schema/vector_node_rel_functions.h index e16e3589d6..c2575f0988 100644 --- a/src/include/function/schema/vector_node_rel_functions.h +++ b/src/include/function/schema/vector_node_rel_functions.h @@ -9,7 +9,7 @@ namespace function { struct OffsetFunction { static function_set getFunctionSet(); static void execFunction(const std::vector>& params, - common::ValueVector& result) { + common::ValueVector& result, void* /*dataPtr*/ = nullptr) { assert(params.size() == 1); UnaryFunctionExecutor::execute(*params[0], result); } diff --git a/src/include/function/string/vector_string_functions.h b/src/include/function/string/vector_string_functions.h index 8825743475..bf34816085 100644 --- a/src/include/function/string/vector_string_functions.h +++ b/src/include/function/string/vector_string_functions.h @@ -12,40 +12,14 @@ 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 fb8fdc46d6..52951a1c6e 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 22b49a45c5..af361e028a 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 5e73a0d906..372f6fd512 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)->csvConfig); + } +}; + 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,13 @@ 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 d08dddd21e..c9447bd0a7 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 9c1ad4cac5..8185b622ef 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::CastString::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::CastString::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::CastString::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 50d2a129d4..b93e74a048 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/src/processor/operator/persistent/reader/csv/driver.cpp b/src/processor/operator/persistent/reader/csv/driver.cpp index 957a556dc2..7daa5e0943 100644 --- a/src/processor/operator/persistent/reader/csv/driver.cpp +++ b/src/processor/operator/persistent/reader/csv/driver.cpp @@ -36,7 +36,7 @@ void ParsingDriver::addValue( reader->filePath, reader->getLineNumber(), reader->expectedNumColumns)); } - function::CastStringToTypes::copyStringToVector( + function::CastString::copyStringToVector( chunk.getValueVector(columnIdx).get(), rowNum, value, &reader->csvReaderConfig); } diff --git a/test/main/udf_test.cpp b/test/main/udf_test.cpp index 3decf3c6f7..83cd5f7481 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 21b1513630..a51d72f25f 100644 --- a/test/test_files/tinysnb/cast/cast_error.test +++ b/test/test_files/tinysnb/cast/cast_error.test @@ -4,94 +4,144 @@ -- -CASE CastError - -LOG CastUint64ToInt64OutOfRange -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 +149,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 +249,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 +383,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 +522,68 @@ 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 +Binder exception: Invalid number of arguments for given function CAST. +-STATEMENT MATCH (:person)-[e:studyAt]->(:organisation) return cast(e, "INT64"); +---- error +Unimplemented casting Function from REL to numeric. +-STATEMENT RETURN cast("dfsdfasdgv", "INTERNAL_ID"); +---- error +Unimplemented casting Function from string to INTERNAL_ID. 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 141c30edf3..13e7cc79eb 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/reader/union_correct.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 2fe57a96eb..a94503bd2e 100644 --- a/test/test_files/tinysnb/function/cast.test +++ b/test/test_files/tinysnb/function/cast.test @@ -9,47 +9,73 @@ -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 +97,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 +120,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 +138,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 +150,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 +162,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 +180,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 +204,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 +228,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 +252,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 +276,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 +300,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 +324,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 +348,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 +371,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 +406,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 +425,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 +439,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 +453,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 +465,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 +477,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 +489,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 +501,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 +513,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 +525,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 +537,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 +549,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 +561,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 +610,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 +622,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 +634,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 +671,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 +724,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 +755,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 +777,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 +828,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 +936,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 +1041,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 9ee8177522..ad92aa7b61 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]);