Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue-1720 #1776

Merged
merged 1 commit into from
Jul 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/function/built_in_vector_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()});
Expand Down
24 changes: 20 additions & 4 deletions src/function/vector_cast_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,14 @@

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:
Expand Down Expand Up @@ -215,6 +217,20 @@
return result;
}

vector_function_definitions CastToSerialVectorFunction::getDefinitions() {
vector_function_definitions result;
result.push_back(bindVectorFunction<int16_t, int64_t, CastToSerial>(
CAST_TO_SERIAL_FUNC_NAME, LogicalTypeID::INT16, LogicalTypeID::SERIAL));
result.push_back(bindVectorFunction<int32_t, int64_t, CastToSerial>(
CAST_TO_SERIAL_FUNC_NAME, LogicalTypeID::INT32, LogicalTypeID::SERIAL));
// down cast
result.push_back(bindVectorFunction<float_t, int64_t, CastToSerial>(
CAST_TO_SERIAL_FUNC_NAME, LogicalTypeID::FLOAT, LogicalTypeID::SERIAL));
result.push_back(bindVectorFunction<double_t, int64_t, CastToSerial>(
CAST_TO_SERIAL_FUNC_NAME, LogicalTypeID::DOUBLE, LogicalTypeID::SERIAL));
return result;
}

Check warning on line 232 in src/function/vector_cast_functions.cpp

View check run for this annotation

Codecov / codecov/patch

src/function/vector_cast_functions.cpp#L232

Added line #L232 was not covered by tests

vector_function_definitions CastToInt64VectorFunction::getDefinitions() {
vector_function_definitions result;
result.push_back(bindVectorFunction<int16_t, int64_t, CastToInt64>(
Expand Down
1 change: 1 addition & 0 deletions src/include/common/expression_type.h
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
7 changes: 7 additions & 0 deletions src/include/function/cast/cast_functions.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,13 @@
numericDownCast<float_t, int64_t>(input, result, "INT64");
}

struct CastToSerial {
template<typename T>
static inline void operation(T& input, int64_t& result) {
CastToInt64::operation(input, result);

Check warning on line 134 in src/include/function/cast/cast_functions.h

View check run for this annotation

Codecov / codecov/patch

src/include/function/cast/cast_functions.h#L134

Added line #L134 was not covered by tests
}
};

struct CastToInt32 {
template<typename T>
static inline void operation(T& input, int32_t& result) {
Expand Down
4 changes: 4 additions & 0 deletions src/include/function/cast/vector_cast_functions.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
};
Expand Down
5 changes: 5 additions & 0 deletions test/test_files/tinysnb/filter/serial.test
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Loading