kou commented on code in PR #44057: URL: https://github.com/apache/arrow/pull/44057#discussion_r1814100136
########## cpp/src/arrow/vendored/datetime/date.h: ########## Review Comment: We don't want to change vendored code. If we need to change vendored code, could you upstream it? https://github.com/HowardHinnant/date ########## cpp/src/arrow/compute/api_scalar.h: ########## @@ -1332,6 +1337,57 @@ Result<Datum> ISOYear(const Datum& values, ExecContext* ctx = NULLPTR); ARROW_EXPORT Result<Datum> USYear(const Datum& values, ExecContext* ctx = NULLPTR); +/// \brief PGYear returns PostgreSQL year for each element of `values`. +/// First week of PostgreSQL epidemiological year has the majority (4 or more) of it's +/// days in January. Last week of PostgreSQL epidemiological year has the year's last +/// Wednesday in it. PostgreSQL epidemiological week starts on Sunday. Review Comment: It seems that this is the same description as `USYear()`. Is there any difference between `USYear()` and `PGYear()`? ########## cpp/src/arrow/compute/api_scalar.h: ########## @@ -1332,6 +1337,57 @@ Result<Datum> ISOYear(const Datum& values, ExecContext* ctx = NULLPTR); ARROW_EXPORT Result<Datum> USYear(const Datum& values, ExecContext* ctx = NULLPTR); +/// \brief PGYear returns PostgreSQL year for each element of `values`. +/// First week of PostgreSQL epidemiological year has the majority (4 or more) of it's +/// days in January. Last week of PostgreSQL epidemiological year has the year's last +/// Wednesday in it. PostgreSQL epidemiological week starts on Sunday. +/// +/// \param[in] values input to extract year from +/// \param[in] ctx the function execution context, optional +/// \return the resulting datum +/// +/// \since 18.0.0 +/// \note API not yet finalized +ARROW_EXPORT +Result<Datum> PGYear(const Datum& values, ExecContext* ctx = NULLPTR); + +/// \brief PGMonth returns PostgreSQL month for each element of `values`. +/// Month is encoded as January=1, December=12 +/// +/// \param[in] values input to extract month from +/// \param[in] ctx the function execution context, optional +/// \return the resulting datum +/// +/// \since 18.0.0 +/// \note API not yet finalized +ARROW_EXPORT +Result<Datum> PGMonth(const Datum& values, ExecContext* ctx = NULLPTR); + +/// \brief PGDay returns PostgreSQL day number for each element of `values`. Review Comment: What is the difference wit h`Day()`? ########## cpp/src/arrow/compute/kernels/scalar_temporal_test.cc: ########## @@ -712,6 +712,39 @@ TEST_F(ScalarTemporalTest, TestIsLeapYear) { boolean(), is_leap_year_pago_pago); } +TEST_F(ScalarTemporalTest, TestPostgreSQL) { + auto unit = timestamp(TimeUnit::NANO); + auto year = + "[2000, 2030, 1929, 2063, 2049, 2049, 2049, 2039, 2040, 2040, 2040, 2036, 2035, " + "2038, 2038, 2041, null]"; + auto month = "[1, 2, 1, 5, 12, 12, 12, 12, 1, 1, 1, 1, 12, 12, 12, 12, null]"; + auto day = "[1, 28, 1, 18, 31, 30, 29, 31, 1, 3, 4, 1, 31, 28, 29, 31, null]"; + auto week = "[52, 9, 1, 20, 52, 52, 52, 52, 52, 1, 1, 1, 1, 52, 52, 1]"; + auto year_month_day = ArrayFromJSON(year_month_day_type, + R"([{"year": 2000, "month": 1, "day": 1}, + {"year": 2030, "month": 2, "day": 28}, + {"year": 1929, "month": 1, "day": 1}, + {"year": 2063, "month": 5, "day": 18}, + {"year": 2049, "month": 12, "day": 31}, + {"year": 2049, "month": 12, "day": 30}, + {"year": 2049, "month": 12, "day": 29}, + {"year": 2039, "month": 12, "day": 31}, + {"year": 2040, "month": 1, "day": 1}, + {"year": 2040, "month": 1, "day": 3}, + {"year": 2040, "month": 1, "day": 4}, + {"year": 2036, "month": 1, "day": 1}, + {"year": 2035, "month": 12, "day": 31}, + {"year": 2038, "month": 12, "day": 28}, + {"year": 2038, "month": 12, "day": 29}, + {"year": 2041, "month": 12, "day": 31}, null])"); Review Comment: Is this used? ########## cpp/src/arrow/compute/api_scalar.h: ########## @@ -1332,6 +1337,57 @@ Result<Datum> ISOYear(const Datum& values, ExecContext* ctx = NULLPTR); ARROW_EXPORT Result<Datum> USYear(const Datum& values, ExecContext* ctx = NULLPTR); +/// \brief PGYear returns PostgreSQL year for each element of `values`. +/// First week of PostgreSQL epidemiological year has the majority (4 or more) of it's +/// days in January. Last week of PostgreSQL epidemiological year has the year's last +/// Wednesday in it. PostgreSQL epidemiological week starts on Sunday. +/// +/// \param[in] values input to extract year from +/// \param[in] ctx the function execution context, optional +/// \return the resulting datum +/// +/// \since 18.0.0 Review Comment: ```suggestion /// \since 19.0.0 ``` ########## cpp/src/arrow/compute/api_scalar.h: ########## @@ -1332,6 +1337,57 @@ Result<Datum> ISOYear(const Datum& values, ExecContext* ctx = NULLPTR); ARROW_EXPORT Result<Datum> USYear(const Datum& values, ExecContext* ctx = NULLPTR); +/// \brief PGYear returns PostgreSQL year for each element of `values`. +/// First week of PostgreSQL epidemiological year has the majority (4 or more) of it's +/// days in January. Last week of PostgreSQL epidemiological year has the year's last +/// Wednesday in it. PostgreSQL epidemiological week starts on Sunday. +/// +/// \param[in] values input to extract year from +/// \param[in] ctx the function execution context, optional +/// \return the resulting datum +/// +/// \since 18.0.0 +/// \note API not yet finalized +ARROW_EXPORT +Result<Datum> PGYear(const Datum& values, ExecContext* ctx = NULLPTR); + +/// \brief PGMonth returns PostgreSQL month for each element of `values`. +/// Month is encoded as January=1, December=12 Review Comment: Same as `Month()`? ########## cpp/src/arrow/compute/api_scalar.h: ########## @@ -1332,6 +1337,57 @@ Result<Datum> ISOYear(const Datum& values, ExecContext* ctx = NULLPTR); ARROW_EXPORT Result<Datum> USYear(const Datum& values, ExecContext* ctx = NULLPTR); +/// \brief PGYear returns PostgreSQL year for each element of `values`. +/// First week of PostgreSQL epidemiological year has the majority (4 or more) of it's +/// days in January. Last week of PostgreSQL epidemiological year has the year's last +/// Wednesday in it. PostgreSQL epidemiological week starts on Sunday. +/// +/// \param[in] values input to extract year from +/// \param[in] ctx the function execution context, optional +/// \return the resulting datum +/// +/// \since 18.0.0 +/// \note API not yet finalized +ARROW_EXPORT +Result<Datum> PGYear(const Datum& values, ExecContext* ctx = NULLPTR); + +/// \brief PGMonth returns PostgreSQL month for each element of `values`. +/// Month is encoded as January=1, December=12 +/// +/// \param[in] values input to extract month from +/// \param[in] ctx the function execution context, optional +/// \return the resulting datum +/// +/// \since 18.0.0 +/// \note API not yet finalized +ARROW_EXPORT +Result<Datum> PGMonth(const Datum& values, ExecContext* ctx = NULLPTR); + +/// \brief PGDay returns PostgreSQL day number for each element of `values`. +/// +/// \param[in] values input to extract day from +/// \param[in] ctx the function execution context, optional +/// \return the resulting datum +/// +/// \since 18.0.0 +/// \note API not yet finalized +ARROW_EXPORT +Result<Datum> PGDay(const Datum& values, ExecContext* ctx = NULLPTR); + +/// \brief PGWeek returns PostgreSQL week of year number for each element of `values`. +/// First PostgreSQL week has the majority (4 or more) of its days in January. +/// PostgreSQL week starts on Sunday. Year can have 52 or 53 weeks. +/// Week numbering starts with 1. Review Comment: Same as `USWeek()`? -- 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]
