From 5fe6e9cf0d74cc8e7f5b5b5f17e75b29fe65f371 Mon Sep 17 00:00:00 2001 From: ziyi chen Date: Fri, 7 Jul 2023 14:59:07 -0400 Subject: [PATCH] Fix issue-1720 --- src/function/built_in_vector_functions.cpp | 2 ++ src/function/vector_cast_functions.cpp | 24 +++++++++++++++---- src/include/common/expression_type.h | 1 + src/include/function/cast/cast_functions.h | 7 ++++++ .../function/cast/vector_cast_functions.h | 4 ++++ test/test_files/tinysnb/filter/serial.test | 5 ++++ 6 files changed, 39 insertions(+), 4 deletions(-) diff --git a/src/function/built_in_vector_functions.cpp b/src/function/built_in_vector_functions.cpp index 0689931629..cd0b0e4e54 100644 --- a/src/function/built_in_vector_functions.cpp +++ b/src/function/built_in_vector_functions.cpp @@ -442,6 +442,8 @@ void BuiltInVectorFunctions::registerCastFunctions() { VectorFunctions.insert( {CAST_TO_DOUBLE_FUNC_NAME, CastToDoubleVectorFunction::getDefinitions()}); VectorFunctions.insert({CAST_TO_FLOAT_FUNC_NAME, CastToFloatVectorFunction::getDefinitions()}); + VectorFunctions.insert( + {CAST_TO_SERIAL_FUNC_NAME, CastToSerialVectorFunction::getDefinitions()}); VectorFunctions.insert({CAST_TO_INT64_FUNC_NAME, CastToInt64VectorFunction::getDefinitions()}); VectorFunctions.insert({CAST_TO_INT32_FUNC_NAME, CastToInt32VectorFunction::getDefinitions()}); VectorFunctions.insert({CAST_TO_INT16_FUNC_NAME, CastToInt16VectorFunction::getDefinitions()}); diff --git a/src/function/vector_cast_functions.cpp b/src/function/vector_cast_functions.cpp index f2c7a381a6..216638bbb0 100644 --- a/src/function/vector_cast_functions.cpp +++ b/src/function/vector_cast_functions.cpp @@ -39,12 +39,14 @@ bool VectorCastFunction::hasImplicitCast( std::string VectorCastFunction::bindImplicitCastFuncName(const common::LogicalType& dstType) { switch (dstType.getLogicalTypeID()) { - case common::LogicalTypeID::INT16: - return CAST_TO_INT16_FUNC_NAME; - case common::LogicalTypeID::INT32: - return CAST_TO_INT32_FUNC_NAME; + case common::LogicalTypeID::SERIAL: + return CAST_TO_SERIAL_FUNC_NAME; case common::LogicalTypeID::INT64: return CAST_TO_INT64_FUNC_NAME; + case common::LogicalTypeID::INT32: + return CAST_TO_INT32_FUNC_NAME; + case common::LogicalTypeID::INT16: + return CAST_TO_INT16_FUNC_NAME; case common::LogicalTypeID::FLOAT: return CAST_TO_FLOAT_FUNC_NAME; case common::LogicalTypeID::DOUBLE: @@ -215,6 +217,20 @@ vector_function_definitions CastToFloatVectorFunction::getDefinitions() { return result; } +vector_function_definitions CastToSerialVectorFunction::getDefinitions() { + vector_function_definitions result; + result.push_back(bindVectorFunction( + CAST_TO_SERIAL_FUNC_NAME, LogicalTypeID::INT16, LogicalTypeID::SERIAL)); + result.push_back(bindVectorFunction( + CAST_TO_SERIAL_FUNC_NAME, LogicalTypeID::INT32, LogicalTypeID::SERIAL)); + // down cast + result.push_back(bindVectorFunction( + CAST_TO_SERIAL_FUNC_NAME, LogicalTypeID::FLOAT, LogicalTypeID::SERIAL)); + result.push_back(bindVectorFunction( + CAST_TO_SERIAL_FUNC_NAME, LogicalTypeID::DOUBLE, LogicalTypeID::SERIAL)); + return result; +} + vector_function_definitions CastToInt64VectorFunction::getDefinitions() { vector_function_definitions result; result.push_back(bindVectorFunction( diff --git a/src/include/common/expression_type.h b/src/include/common/expression_type.h index 567cf2b925..9003e4182b 100644 --- a/src/include/common/expression_type.h +++ b/src/include/common/expression_type.h @@ -26,6 +26,7 @@ const std::string CAST_TO_INTERVAL_FUNC_NAME = "INTERVAL"; const std::string CAST_TO_STRING_FUNC_NAME = "STRING"; const std::string CAST_TO_DOUBLE_FUNC_NAME = "TO_DOUBLE"; const std::string CAST_TO_FLOAT_FUNC_NAME = "TO_FLOAT"; +const std::string CAST_TO_SERIAL_FUNC_NAME = "TO_SERIAL"; const std::string CAST_TO_INT64_FUNC_NAME = "TO_INT64"; const std::string CAST_TO_INT32_FUNC_NAME = "TO_INT32"; const std::string CAST_TO_INT16_FUNC_NAME = "TO_INT16"; diff --git a/src/include/function/cast/cast_functions.h b/src/include/function/cast/cast_functions.h index 544ea09081..f2aba55061 100644 --- a/src/include/function/cast/cast_functions.h +++ b/src/include/function/cast/cast_functions.h @@ -128,6 +128,13 @@ inline void CastToInt64::operation(float_t& input, int64_t& result) { numericDownCast(input, result, "INT64"); } +struct CastToSerial { + template + static inline void operation(T& input, int64_t& result) { + CastToInt64::operation(input, result); + } +}; + struct CastToInt32 { template static inline void operation(T& input, int32_t& result) { diff --git a/src/include/function/cast/vector_cast_functions.h b/src/include/function/cast/vector_cast_functions.h index bc2c4954f6..8ad814e4ee 100644 --- a/src/include/function/cast/vector_cast_functions.h +++ b/src/include/function/cast/vector_cast_functions.h @@ -100,6 +100,10 @@ struct CastToFloatVectorFunction : public VectorCastFunction { static vector_function_definitions getDefinitions(); }; +struct CastToSerialVectorFunction : public VectorCastFunction { + static vector_function_definitions getDefinitions(); +}; + struct CastToInt64VectorFunction : public VectorCastFunction { static vector_function_definitions getDefinitions(); }; diff --git a/test/test_files/tinysnb/filter/serial.test b/test/test_files/tinysnb/filter/serial.test index 3b530f67b2..d8fa9772ca 100644 --- a/test/test_files/tinysnb/filter/serial.test +++ b/test/test_files/tinysnb/filter/serial.test @@ -41,3 +41,8 @@ {_ID: 0:2, _LABEL: person, ID: 2, fName: Carol, gender: 1, isStudent: False, isWorker: True, age: 45, eyeSight: 5.000000, birthdate: 1940-06-22, registerTime: 1911-08-20 02:32:21, lastJobDuration: 48:24:11, workedHours: [4,5], usedNames: [Carmen,Fred], courseScoresPerTerm: [[8,10]], grades: [91,75,21,95], height: 1.000000} {_ID: 0:3, _LABEL: person, ID: 3, fName: Dan, gender: 2, isStudent: False, isWorker: True, age: 20, eyeSight: 4.800000, birthdate: 1950-07-23, registerTime: 2031-11-30 12:25:30, lastJobDuration: 10 years 5 months 13:00:00.000024, workedHours: [1,9], usedNames: [Wolfeschlegelstein,Daniel], courseScoresPerTerm: [[7,4],[8,8],[9]], grades: [76,88,99,89], height: 1.300000} {_ID: 0:4, _LABEL: person, ID: 4, fName: Elizabeth, gender: 1, isStudent: False, isWorker: True, age: 20, eyeSight: 4.700000, birthdate: 1980-10-26, registerTime: 1976-12-23 11:21:42, lastJobDuration: 48:24:11, workedHours: [2], usedNames: [Ein], courseScoresPerTerm: [[6],[7],[8]], grades: [96,59,65,88], height: 1.463000} + +-LOG SerialWithFilter +-STATEMENT MATCH (a:person {ID:1}) RETURN a +---- 1 +{_ID: 0:1, _LABEL: person, ID: 1, fName: Bob, gender: 2, isStudent: True, isWorker: False, age: 30, eyeSight: 5.100000, birthdate: 1900-01-01, registerTime: 2008-11-03 15:25:30.000526, lastJobDuration: 10 years 5 months 13:00:00.000024, workedHours: [12,8], usedNames: [Bobby], courseScoresPerTerm: [[8,9],[9,10]], grades: [98,42,93,88], height: 0.990000}