Skip to content

added built-in timestamp transformation in the date function #6006

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
5 changes: 4 additions & 1 deletion src/common/function/FunctionManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,8 @@ std::unordered_map<std::string, std::vector<TypeSignature>> FunctionManager::typ
{"date",
{TypeSignature({}, Value::Type::DATE),
TypeSignature({Value::Type::STRING}, Value::Type::DATE),
TypeSignature({Value::Type::MAP}, Value::Type::DATE)}},
TypeSignature({Value::Type::MAP}, Value::Type::DATE),
TypeSignature({Value::Type::INT}, Value::Type::DATE)}},
{"datetime",
{TypeSignature({}, Value::Type::DATETIME),
TypeSignature({Value::Type::STRING}, Value::Type::DATETIME),
Expand Down Expand Up @@ -1820,6 +1821,8 @@ FunctionManager::FunctionManager() {
return Value::kNullBadData;
}
return result.value();
} else if (args[0].get().isInt()) {
return time::TimeConversion::unixSecondsToDate(args[0].get().getInt());
} else {
return Value::kNullBadType;
}
Expand Down
3 changes: 2 additions & 1 deletion src/common/function/test/FunctionManagerTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,7 @@ TEST_F(FunctionManagerTest, time) {
TEST_FUNCTION(
date, {Map({{"year", 2020}, {"month", 12}, {"day", 31}})}, Value(Date(2020, 12, 31)));
}
{ TEST_FUNCTION(date, {573206400}, Value(Date(1988, 3, 1))); }
// leap year February days
{
// 2020 is leap
Expand Down Expand Up @@ -1432,7 +1433,7 @@ TEST_F(FunctionManagerTest, returnType) {
}
// date
{
auto result = FunctionManager::getReturnType("date", {Value::Type::INT});
auto result = FunctionManager::getReturnType("date", {Value::Type::FLOAT});
ASSERT_FALSE(result.ok());
EXPECT_EQ(result.status().toString(), "Parameter's type error");
}
Expand Down