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

GH-38879: [C++][Gandiva] Fix Gandiva to_date function's validation fo… #73

Merged
merged 2 commits into from
May 15, 2024
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: 1 addition & 1 deletion cpp/src/gandiva/to_date_holder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ Status ToDateHolder::Make(const FunctionNode& node,
if (node.children().size() == 3) {
auto literal_suppress_errors =
dynamic_cast<LiteralNode*>(node.children().at(2).get());
if (literal_pattern == nullptr) {
if (literal_suppress_errors == nullptr) {
return Status::Invalid(
"The (optional) third parameter to 'to_date' function needs to an integer "
"literal to indicate whether to suppress the error");
Expand Down
26 changes: 21 additions & 5 deletions cpp/src/gandiva/to_date_holder_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,18 @@ namespace gandiva {

class TestToDateHolder : public ::testing::Test {
public:
FunctionNode BuildToDate(std::string pattern) {
FunctionNode BuildToDate(std::string pattern,
std::shared_ptr<Node> suppress_error_node = nullptr) {
auto field = std::make_shared<FieldNode>(arrow::field("in", arrow::utf8()));
auto pattern_node =
std::make_shared<LiteralNode>(arrow::utf8(), LiteralHolder(pattern), false);
auto suppress_error_node =
std::make_shared<LiteralNode>(arrow::int32(), LiteralHolder(0), false);
return FunctionNode("to_date_utf8_utf8_int32",
{field, pattern_node, suppress_error_node}, arrow::int64());
if (suppress_error_node == nullptr) {
suppress_error_node =
std::make_shared<LiteralNode>(arrow::int32(), LiteralHolder(0), false);
}
return {"to_date_utf8_utf8_int32",
{field, pattern_node, std::move(suppress_error_node)},
arrow::int64()};
}

protected:
Expand Down Expand Up @@ -178,4 +182,16 @@ TEST_F(TestToDateHolder, TestSimpleDateYear) {
EXPECT_EQ(millis_since_epoch, 915148800000);
}

TEST_F(TestToDateHolder, TestMakeFromFunctionNode) {
std::shared_ptr<ToDateHolder> to_date_holder;
auto to_date_func = BuildToDate("YYYY");
ASSERT_OK(ToDateHolder::Make(to_date_func, &to_date_holder));
}

TEST_F(TestToDateHolder, TestMakeFromInvalidSurpressParamFunctionNode) {
std::shared_ptr<ToDateHolder> to_date_holder;
auto non_literal_param = std::make_shared<FieldNode>(arrow::field("in", arrow::utf8()));
auto to_date_func = BuildToDate("YYYY", std::move(non_literal_param));
ASSERT_RAISES(Invalid, ToDateHolder::Make(to_date_func, &to_date_holder));
}
} // namespace gandiva
4 changes: 2 additions & 2 deletions dev/tasks/java-jars/github.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ jobs:
fail-fast: false
matrix:
platform:
- { runs_on: ["macos-latest"], arch: "x86_64"}
- { runs_on: ["macos-12"], arch: "x86_64"}
env:
MACOSX_DEPLOYMENT_TARGET: "10.13"
steps:
Expand Down Expand Up @@ -162,7 +162,7 @@ jobs:

package-jars:
name: Build jar files
runs-on: macos-latest
runs-on: macos-12
needs:
- build-cpp-ubuntu
- build-cpp-macos
Expand Down
Loading