anthonylouisbsb commented on a change in pull request #10137: URL: https://github.com/apache/arrow/pull/10137#discussion_r756497715
########## File path: cpp/src/gandiva/interval_holder_test.cc ########## @@ -0,0 +1,423 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +#include "gandiva/interval_holder.h" + +#include <gtest/gtest.h> + +#include <memory> +#include <vector> + +#include "gandiva/execution_context.h" + +namespace gandiva { + +class TestIntervalHolder : public ::testing::Test { + protected: + ExecutionContext execution_context_; +}; + +TEST_F(TestIntervalHolder, TestMatchAllPeriods) { + std::shared_ptr<IntervalDaysHolder> interval_days_holder; + std::shared_ptr<IntervalYearsHolder> interval_years_holder; + + auto status = IntervalDaysHolder::Make(0, &interval_days_holder); + EXPECT_EQ(status.ok(), true) << status.message(); + + status = IntervalYearsHolder::Make(0, &interval_years_holder); + EXPECT_EQ(status.ok(), true) << status.message(); + + auto& cast_interval_day = *interval_days_holder; + auto& cast_interval_year = *interval_years_holder; + + // Pass only numbers to cast + bool out_valid; + std::string data("73834992"); + int64_t response = cast_interval_day(&execution_context_, data, true, &out_valid); + EXPECT_GT(response, 0); + EXPECT_TRUE(out_valid); + EXPECT_FALSE(execution_context_.has_error()); + + int32_t response_interval_yrs = + cast_interval_year(&execution_context_, data, true, &out_valid); + EXPECT_GT(response_interval_yrs, 0); + EXPECT_TRUE(out_valid); + EXPECT_FALSE(execution_context_.has_error()); + + // Pass only years and days to cast + data = "P12Y15D"; + response = cast_interval_day(&execution_context_, data, true, &out_valid); + EXPECT_GT(response, 0); + EXPECT_TRUE(out_valid); + EXPECT_FALSE(execution_context_.has_error()); + + response_interval_yrs = cast_interval_year(&execution_context_, data, true, &out_valid); + EXPECT_GT(response_interval_yrs, 0); + EXPECT_TRUE(out_valid); + EXPECT_FALSE(execution_context_.has_error()); + + // Pass years and days and months to cast + data = "P12Y2M15D"; + response = cast_interval_day(&execution_context_, data, true, &out_valid); + EXPECT_GT(response, 0); + EXPECT_TRUE(out_valid); + EXPECT_FALSE(execution_context_.has_error()); + + response_interval_yrs = cast_interval_year(&execution_context_, data, true, &out_valid); + EXPECT_GT(response_interval_yrs, 0); + EXPECT_TRUE(out_valid); + EXPECT_FALSE(execution_context_.has_error()); + + // Pass days and months to cast + data = "P5M13D"; + response = cast_interval_day(&execution_context_, data, true, &out_valid); + EXPECT_GT(response, 0); + EXPECT_TRUE(out_valid); + EXPECT_FALSE(execution_context_.has_error()); + + response_interval_yrs = cast_interval_year(&execution_context_, data, true, &out_valid); + EXPECT_GT(response_interval_yrs, 0); + EXPECT_TRUE(out_valid); + EXPECT_FALSE(execution_context_.has_error()); + + // Pass all possible fields cast + data = "P2Y5M13DT10H42M21S"; + response = cast_interval_day(&execution_context_, data, true, &out_valid); + EXPECT_GT(response, 0); + EXPECT_TRUE(out_valid); + EXPECT_FALSE(execution_context_.has_error()); + + response_interval_yrs = cast_interval_year(&execution_context_, data, true, &out_valid); + EXPECT_GT(response_interval_yrs, 0); + EXPECT_TRUE(out_valid); + EXPECT_FALSE(execution_context_.has_error()); + + // Pass only time fields cast + data = "PT10H42M21S"; + response = cast_interval_day(&execution_context_, data, true, &out_valid); + EXPECT_GT(response, 0); + EXPECT_TRUE(out_valid); + EXPECT_FALSE(execution_context_.has_error()); + + response_interval_yrs = cast_interval_year(&execution_context_, data, true, &out_valid); + EXPECT_GE(response_interval_yrs, 0); + EXPECT_TRUE(out_valid); + EXPECT_FALSE(execution_context_.has_error()); + + // Pass only time fields to cast without hours + data = "PT42M21S"; + response = cast_interval_day(&execution_context_, data, true, &out_valid); + EXPECT_GT(response, 0); + EXPECT_TRUE(out_valid); + EXPECT_FALSE(execution_context_.has_error()); + + response_interval_yrs = cast_interval_year(&execution_context_, data, true, &out_valid); + EXPECT_GE(response_interval_yrs, 0); + EXPECT_TRUE(out_valid); + EXPECT_FALSE(execution_context_.has_error()); + + // Pass only weeks to cast + data = "P25W"; + response = cast_interval_day(&execution_context_, data, true, &out_valid); + EXPECT_GT(response, 0); + EXPECT_TRUE(out_valid); + EXPECT_FALSE(execution_context_.has_error()); + + response_interval_yrs = cast_interval_year(&execution_context_, data, true, &out_valid); + EXPECT_GE(response_interval_yrs, 0); Review comment: I based on some engines behaviors(like Dremio as example) where the period in week format is not compatible to return the month interval. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
