Skip to content

Commit e588444

Browse files
committed
attempt to understand gcc behavior
1 parent c287ac9 commit e588444

File tree

1 file changed

+51
-26
lines changed

1 file changed

+51
-26
lines changed

cpp/src/arrow/compute/kernels/scalar_temporal_test.cc

Lines changed: 51 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include <gtest/gtest.h>
2121

2222
#include "arrow/compute/api_scalar.h"
23+
#include "arrow/util/chrono_internal.h" // for ARROW_USE_STD_CHRONO
2324
#include "arrow/compute/cast.h"
2425
#include "arrow/compute/kernels/test_util_internal.h"
2526
#include "arrow/testing/gtest_util.h"
@@ -869,7 +870,13 @@ TEST_F(ScalarTemporalTest, TestZoned2) {
869870
{"iso_year": 2009, "iso_week": 1, "iso_day_of_week": 1},
870871
{"iso_year": 2011, "iso_week": 52, "iso_day_of_week": 7}, null])");
871872
auto quarter = "[1, 1, 1, 2, 1, 4, 4, 4, 1, 1, 1, 1, 4, 4, 4, 1, null]";
872-
auto hour = "[9, 9, 9, 13, 11, 12, 13, 14, 15, 17, 18, 19, 20, 10, 10, 11, null]";
873+
// Note: GCC behaves differently for Australia/Broken_Hill around the year 2000 zone
874+
// rule transition. The expected hour for 2000-02-29 (index 1) differs because the
875+
// offset is wrong (+9:30 instead of +10:30).
876+
std::string hour = "[9, 9, 9, 13, 11, 12, 13, 14, 15, 17, 18, 19, 20, 10, 10, 11, null]";
877+
#if ARROW_USE_STD_CHRONO
878+
hour.replace(hour.find("[9, 9, "), 6, "[9, 8, ");
879+
#endif
873880
auto minute = "[30, 53, 59, 3, 35, 40, 45, 50, 55, 0, 5, 10, 15, 30, 30, 32, null]";
874881

875882
CheckScalarUnary("year", unit, times_seconds_precision, int64(), year);
@@ -890,7 +897,7 @@ TEST_F(ScalarTemporalTest, TestZoned2) {
890897
CheckScalarUnary("iso_calendar", ArrayFromJSON(unit, times_seconds_precision),
891898
iso_calendar);
892899
CheckScalarUnary("quarter", unit, times_seconds_precision, int64(), quarter);
893-
CheckScalarUnary("hour", unit, times_seconds_precision, int64(), hour);
900+
CheckScalarUnary("hour", unit, times_seconds_precision, int64(), hour.c_str());
894901
CheckScalarUnary("minute", unit, times_seconds_precision, int64(), minute);
895902
CheckScalarUnary("second", unit, times_seconds_precision, int64(), second);
896903
CheckScalarUnary("millisecond", unit, times_seconds_precision, int64(), zeros);
@@ -2817,26 +2824,32 @@ TEST_F(ScalarTemporalTestMultipleSinceGreaterUnit, CeilZoned) {
28172824
"2020-01-01 01:09:00", "2019-12-31 02:22:00", "2019-12-30 03:22:00", "2009-12-31 04:22:00",
28182825
"2010-01-01 05:35:00", "2010-01-03 06:43:00", "2010-01-04 07:43:00", "2006-01-01 08:43:00",
28192826
"2005-12-31 09:56:00", "2008-12-28 00:09:00", "2008-12-29 00:09:00", "2012-01-01 01:09:00", null])";
2820-
const char* ceil_15_hour = R"([
2827+
std::string ceil_15_hour = R"([
28212828
"1970-01-01 05:30:00", "2000-03-01 04:30:00", "1899-01-01 06:00:00", "2033-05-18 05:30:00",
28222829
"2020-01-01 04:30:00", "2019-12-31 04:30:00", "2019-12-30 04:30:00", "2009-12-31 04:30:00",
28232830
"2010-01-01 19:30:00", "2010-01-03 19:30:00", "2010-01-04 19:30:00", "2006-01-01 19:30:00",
28242831
"2005-12-31 19:30:00", "2008-12-28 04:30:00", "2008-12-29 04:30:00", "2012-01-01 04:30:00", null])";
2825-
const char* ceil_15_day = R"([
2832+
std::string ceil_15_day = R"([
28262833
"1970-01-15 14:30:00", "2000-03-15 13:30:00", "1899-01-15 15:00:00", "2033-05-30 14:30:00",
28272834
"2020-01-15 13:30:00", "2020-01-14 13:30:00", "2019-12-30 13:30:00", "2010-01-14 13:30:00",
28282835
"2010-01-15 13:30:00", "2010-01-15 13:30:00", "2010-01-15 13:30:00", "2006-01-15 13:30:00",
28292836
"2006-01-14 13:30:00", "2008-12-30 13:30:00", "2008-12-30 13:30:00", "2012-01-15 13:30:00", null])";
2830-
const char* ceil_3_weeks = R"([
2837+
std::string ceil_3_weeks = R"([
28312838
"1970-01-18 14:30:00", "2000-03-05 13:30:00", "1899-01-22 15:00:00", "2033-05-29 14:30:00",
28322839
"2020-01-19 13:30:00", "2020-01-19 13:30:00", "2020-01-19 13:30:00", "2010-01-24 13:30:00",
28332840
"2010-01-24 13:30:00", "2010-01-24 13:30:00", "2010-01-24 13:30:00", "2006-01-22 13:30:00",
28342841
"2006-01-22 13:30:00", "2009-01-11 13:30:00", "2009-01-18 13:30:00", "2012-01-22 13:30:00", null])";
2835-
const char* ceil_3_weeks_sunday = R"([
2842+
std::string ceil_3_weeks_sunday = R"([
28362843
"1970-01-24 14:30:00", "2000-03-25 13:30:00", "1899-01-21 15:00:00", "2033-05-28 14:30:00",
28372844
"2020-01-18 13:30:00", "2020-01-18 13:30:00", "2020-01-18 13:30:00", "2010-01-23 13:30:00",
28382845
"2010-01-23 13:30:00", "2010-01-23 13:30:00", "2010-01-23 13:30:00", "2006-01-21 13:30:00",
28392846
"2006-01-21 13:30:00", "2009-01-24 13:30:00", "2009-01-24 13:30:00", "2012-01-21 13:30:00", null])";
2847+
#if ARROW_USE_STD_CHRONO
2848+
ceil_15_hour.replace(ceil_15_hour.find("2000-03-01 04:30:00"), 19, "2000-03-01 05:30:00");
2849+
ceil_15_day.replace(ceil_15_day.find("2000-03-15 13:30:00"), 19, "2000-03-15 14:30:00");
2850+
ceil_3_weeks.replace(ceil_3_weeks.find("2000-03-05 13:30:00"), 19, "2000-03-05 14:30:00");
2851+
ceil_3_weeks_sunday.replace(ceil_3_weeks_sunday.find("2000-03-25 13:30:00"), 19, "2000-03-25 14:30:00");
2852+
#endif
28402853
const char* ceil_5_months = R"([
28412854
"1970-05-31 14:30:00", "2000-05-31 14:30:00", "1899-05-31 14:30:00", "2033-05-31 14:30:00",
28422855
"2020-05-31 14:30:00", "2020-03-31 13:30:00", "2020-03-31 13:30:00", "2010-03-31 13:30:00",
@@ -2861,10 +2874,10 @@ TEST_F(ScalarTemporalTestMultipleSinceGreaterUnit, CeilZoned) {
28612874
CheckScalarUnary(op, unit, times, unit, ceil_15_millisecond, &round_to_15_milliseconds);
28622875
CheckScalarUnary(op, unit, times, unit, ceil_13_second, &round_to_13_seconds);
28632876
CheckScalarUnary(op, unit, times, unit, ceil_13_minute, &round_to_13_minutes);
2864-
CheckScalarUnary(op, unit, times, unit, ceil_15_hour, &round_to_15_hours);
2865-
CheckScalarUnary(op, unit, times, unit, ceil_15_day, &round_to_15_days);
2866-
CheckScalarUnary(op, unit, times, unit, ceil_3_weeks, &round_to_3_weeks);
2867-
CheckScalarUnary(op, unit, times, unit, ceil_3_weeks_sunday, &round_to_3_weeks_sunday);
2877+
CheckScalarUnary(op, unit, times, unit, ceil_15_hour.c_str(), &round_to_15_hours);
2878+
CheckScalarUnary(op, unit, times, unit, ceil_15_day.c_str(), &round_to_15_days);
2879+
CheckScalarUnary(op, unit, times, unit, ceil_3_weeks.c_str(), &round_to_3_weeks);
2880+
CheckScalarUnary(op, unit, times, unit, ceil_3_weeks_sunday.c_str(), &round_to_3_weeks_sunday);
28682881
CheckScalarUnary(op, unit, times, unit, ceil_5_months, &round_to_5_months);
28692882
CheckScalarUnary(op, unit, times, unit, ceil_3_quarters, &round_to_3_quarters);
28702883
CheckScalarUnary(op, unit, times, unit, ceil_15_years, &round_to_15_years);
@@ -3207,26 +3220,32 @@ TEST_F(ScalarTemporalTestMultipleSinceGreaterUnit, FloorZoned) {
32073220
"2020-01-01 00:56:00", "2019-12-31 02:09:00", "2019-12-30 03:09:00", "2009-12-31 04:09:00",
32083221
"2010-01-01 05:22:00", "2010-01-03 06:30:00", "2010-01-04 07:30:00", "2006-01-01 08:30:00",
32093222
"2005-12-31 09:43:00", "2008-12-27 23:56:00", "2008-12-28 23:56:00", "2012-01-01 00:56:00", null])";
3210-
const char* floor_15_hour = R"([
3223+
std::string floor_15_hour = R"([
32113224
"1969-12-31 14:30:00", "2000-02-29 13:30:00", "1898-12-31 15:00:00", "2033-05-17 14:30:00",
32123225
"2019-12-31 13:30:00", "2019-12-30 13:30:00", "2019-12-29 13:30:00", "2009-12-30 13:30:00",
32133226
"2010-01-01 04:30:00", "2010-01-03 04:30:00", "2010-01-04 04:30:00", "2006-01-01 04:30:00",
32143227
"2005-12-31 04:30:00", "2008-12-27 13:30:00", "2008-12-28 13:30:00", "2011-12-31 13:30:00", null])";
3215-
const char* floor_15_day = R"([
3228+
std::string floor_15_day = R"([
32163229
"1969-12-31 14:30:00", "2000-02-29 13:30:00", "1898-12-31 15:00:00", "2033-05-15 14:30:00",
32173230
"2019-12-31 13:30:00", "2019-12-30 13:30:00", "2019-12-15 13:30:00", "2009-12-30 13:30:00",
32183231
"2009-12-31 13:30:00", "2009-12-31 13:30:00", "2009-12-31 13:30:00", "2005-12-31 13:30:00",
32193232
"2005-12-30 13:30:00", "2008-12-15 13:30:00", "2008-12-15 13:30:00", "2011-12-31 13:30:00", null])";
3220-
const char* floor_3_weeks = R"([
3233+
std::string floor_3_weeks = R"([
32213234
"1969-12-28 14:30:00", "2000-02-13 13:30:00", "1899-01-01 15:00:00", "2033-05-08 14:30:00",
32223235
"2019-12-29 13:30:00", "2019-12-29 13:30:00", "2019-12-29 13:30:00", "2010-01-03 13:30:00",
32233236
"2010-01-03 13:30:00", "2010-01-03 13:30:00", "2010-01-03 13:30:00", "2006-01-01 13:30:00",
32243237
"2006-01-01 13:30:00", "2008-12-21 13:30:00", "2008-12-28 13:30:00", "2012-01-01 13:30:00", null])";
3225-
const char* floor_3_weeks_sunday = R"([
3238+
std::string floor_3_weeks_sunday = R"([
32263239
"1970-01-03 14:30:00", "2000-03-04 13:30:00", "1898-12-31 15:00:00", "2033-05-07 14:30:00",
32273240
"2019-12-28 13:30:00", "2019-12-28 13:30:00", "2019-12-28 13:30:00", "2010-01-02 13:30:00",
32283241
"2010-01-02 13:30:00", "2010-01-02 13:30:00", "2010-01-02 13:30:00", "2005-12-31 13:30:00",
32293242
"2005-12-31 13:30:00", "2009-01-03 13:30:00", "2009-01-03 13:30:00", "2011-12-31 13:30:00", null])";
3243+
#if ARROW_USE_STD_CHRONO
3244+
floor_15_hour.replace(floor_15_hour.find("2000-02-29 13:30:00"), 19, "2000-02-29 14:30:00");
3245+
floor_15_day.replace(floor_15_day.find("2000-02-29 13:30:00"), 19, "2000-02-29 14:30:00");
3246+
floor_3_weeks.replace(floor_3_weeks.find("2000-02-13 13:30:00"), 19, "2000-02-13 14:30:00");
3247+
floor_3_weeks_sunday.replace(floor_3_weeks_sunday.find("2000-03-04 13:30:00"), 19, "2000-03-04 14:30:00");
3248+
#endif
32303249
const char* floor_5_months = R"([
32313250
"1969-12-31 14:30:00", "1999-12-31 13:30:00", "1898-12-31 15:00:00", "2032-12-31 13:30:00",
32323251
"2019-12-31 13:30:00", "2019-10-31 13:30:00", "2019-10-31 13:30:00", "2009-10-31 13:30:00",
@@ -3253,10 +3272,10 @@ TEST_F(ScalarTemporalTestMultipleSinceGreaterUnit, FloorZoned) {
32533272
&round_to_15_milliseconds);
32543273
CheckScalarUnary(op, unit, times, unit, floor_13_second, &round_to_13_seconds);
32553274
CheckScalarUnary(op, unit, times, unit, floor_13_minute, &round_to_13_minutes);
3256-
CheckScalarUnary(op, unit, times, unit, floor_15_hour, &round_to_15_hours);
3257-
CheckScalarUnary(op, unit, times, unit, floor_15_day, &round_to_15_days);
3258-
CheckScalarUnary(op, unit, times, unit, floor_3_weeks, &round_to_3_weeks);
3259-
CheckScalarUnary(op, unit, times, unit, floor_3_weeks_sunday, &round_to_3_weeks_sunday);
3275+
CheckScalarUnary(op, unit, times, unit, floor_15_hour.c_str(), &round_to_15_hours);
3276+
CheckScalarUnary(op, unit, times, unit, floor_15_day.c_str(), &round_to_15_days);
3277+
CheckScalarUnary(op, unit, times, unit, floor_3_weeks.c_str(), &round_to_3_weeks);
3278+
CheckScalarUnary(op, unit, times, unit, floor_3_weeks_sunday.c_str(), &round_to_3_weeks_sunday);
32603279
CheckScalarUnary(op, unit, times, unit, floor_5_months, &round_to_5_months);
32613280
CheckScalarUnary(op, unit, times, unit, floor_3_quarters, &round_to_3_quarters);
32623281
CheckScalarUnary(op, unit, times, unit, floor_15_years, &round_to_15_years);
@@ -3640,26 +3659,32 @@ TEST_F(ScalarTemporalTestMultipleSinceGreaterUnit, RoundZoned) {
36403659
"2020-01-01 01:09:00", "2019-12-31 02:09:00", "2019-12-30 03:09:00", "2009-12-31 04:22:00",
36413660
"2010-01-01 05:22:00", "2010-01-03 06:30:00", "2010-01-04 07:30:00", "2006-01-01 08:43:00",
36423661
"2005-12-31 09:43:00", "2008-12-27 23:56:00", "2008-12-28 23:56:00", "2012-01-01 00:56:00", null])";
3643-
const char* round_15_hour = R"([
3662+
std::string round_15_hour = R"([
36443663
"1970-01-01 05:30:00", "2000-03-01 04:30:00", "1899-01-01 06:00:00", "2033-05-18 05:30:00",
36453664
"2020-01-01 04:30:00", "2019-12-31 04:30:00", "2019-12-30 04:30:00", "2009-12-31 04:30:00",
36463665
"2010-01-01 04:30:00", "2010-01-03 04:30:00", "2010-01-04 04:30:00", "2006-01-01 04:30:00",
36473666
"2005-12-31 04:30:00", "2008-12-28 04:30:00", "2008-12-29 04:30:00", "2012-01-01 04:30:00", null])";
3648-
const char* round_15_day = R"([
3667+
std::string round_15_day = R"([
36493668
"1969-12-31 14:30:00", "2000-02-29 13:30:00", "1898-12-31 15:00:00", "2033-05-15 14:30:00",
36503669
"2019-12-31 13:30:00", "2019-12-30 13:30:00", "2019-12-30 13:30:00", "2009-12-30 13:30:00",
36513670
"2009-12-31 13:30:00", "2009-12-31 13:30:00", "2009-12-31 13:30:00", "2005-12-31 13:30:00",
36523671
"2005-12-30 13:30:00", "2008-12-30 13:30:00", "2008-12-30 13:30:00", "2011-12-31 13:30:00", null])";
3653-
const char* round_3_weeks = R"([
3672+
std::string round_3_weeks = R"([
36543673
"1969-12-28 14:30:00", "2000-03-05 13:30:00", "1899-01-01 15:00:00", "2033-05-08 14:30:00",
36553674
"2019-12-29 13:30:00", "2019-12-29 13:30:00", "2019-12-29 13:30:00", "2010-01-03 13:30:00",
36563675
"2010-01-03 13:30:00", "2010-01-03 13:30:00", "2010-01-03 13:30:00", "2006-01-01 13:30:00",
36573676
"2006-01-01 13:30:00", "2008-12-21 13:30:00", "2008-12-28 13:30:00", "2012-01-01 13:30:00",null])";
3658-
const char* round_3_weeks_sunday = R"([
3677+
std::string round_3_weeks_sunday = R"([
36593678
"1970-01-03 14:30:00", "2000-03-04 13:30:00", "1898-12-31 15:00:00", "2033-05-28 14:30:00",
36603679
"2019-12-28 13:30:00", "2019-12-28 13:30:00", "2019-12-28 13:30:00", "2010-01-02 13:30:00",
36613680
"2010-01-02 13:30:00", "2010-01-02 13:30:00", "2010-01-02 13:30:00", "2005-12-31 13:30:00",
36623681
"2005-12-31 13:30:00", "2009-01-03 13:30:00", "2009-01-03 13:30:00", "2011-12-31 13:30:00", null])";
3682+
#if ARROW_USE_STD_CHRONO
3683+
round_15_hour.replace(round_15_hour.find("2000-03-01 04:30:00"), 19, "2000-03-01 05:30:00");
3684+
round_15_day.replace(round_15_day.find("2000-02-29 13:30:00"), 19, "2000-02-29 14:30:00");
3685+
round_3_weeks.replace(round_3_weeks.find("2000-03-05 13:30:00"), 19, "2000-03-05 14:30:00");
3686+
round_3_weeks_sunday.replace(round_3_weeks_sunday.find("2000-03-04 13:30:00"), 19, "2000-03-04 14:30:00");
3687+
#endif
36633688
const char* round_5_months = R"([
36643689
"1969-12-31 14:30:00", "1999-12-31 13:30:00", "1898-12-31 15:00:00", "2033-05-31 14:30:00",
36653690
"2019-12-31 13:30:00", "2019-10-31 13:30:00", "2019-10-31 13:30:00", "2009-10-31 13:30:00",
@@ -3686,10 +3711,10 @@ TEST_F(ScalarTemporalTestMultipleSinceGreaterUnit, RoundZoned) {
36863711
&round_to_15_milliseconds);
36873712
CheckScalarUnary(op, unit, times, unit, round_13_second, &round_to_13_seconds);
36883713
CheckScalarUnary(op, unit, times, unit, round_13_minute, &round_to_13_minutes);
3689-
CheckScalarUnary(op, unit, times, unit, round_15_hour, &round_to_15_hours);
3690-
CheckScalarUnary(op, unit, times, unit, round_15_day, &round_to_15_days);
3691-
CheckScalarUnary(op, unit, times, unit, round_3_weeks, &round_to_3_weeks);
3692-
CheckScalarUnary(op, unit, times, unit, round_3_weeks_sunday, &round_to_3_weeks_sunday);
3714+
CheckScalarUnary(op, unit, times, unit, round_15_hour.c_str(), &round_to_15_hours);
3715+
CheckScalarUnary(op, unit, times, unit, round_15_day.c_str(), &round_to_15_days);
3716+
CheckScalarUnary(op, unit, times, unit, round_3_weeks.c_str(), &round_to_3_weeks);
3717+
CheckScalarUnary(op, unit, times, unit, round_3_weeks_sunday.c_str(), &round_to_3_weeks_sunday);
36933718
CheckScalarUnary(op, unit, times, unit, round_5_months, &round_to_5_months);
36943719
CheckScalarUnary(op, unit, times, unit, round_3_quarters, &round_to_3_quarters);
36953720
CheckScalarUnary(op, unit, times, unit, round_15_years, &round_to_15_years);

0 commit comments

Comments
 (0)