This is an automated email from the ASF dual-hosted git repository.
JingsongLi pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/paimon.git
The following commit(s) were added to refs/heads/master by this push:
new 8279248642 [python] Support the remaining date-extraction transforms
in query-auth rules (#10197)
8279248642 is described below
commit 8279248642d5dab00fb223694d46b1912511a341
Author: jackylee <[email protected]>
AuthorDate: Sat Oct 3 17:07:47 2026 +0800
[python] Support the remaining date-extraction transforms in query-auth
rules (#10197)
---
.../pypaimon/common/predicate_json_parser.py | 11 ++++++++++-
.../pypaimon/tests/predicate_json_parser_test.py | 23 +++++++++++++++++++++-
2 files changed, 32 insertions(+), 2 deletions(-)
diff --git a/paimon-python/pypaimon/common/predicate_json_parser.py
b/paimon-python/pypaimon/common/predicate_json_parser.py
index ba895449ce..c67c6442ca 100644
--- a/paimon-python/pypaimon/common/predicate_json_parser.py
+++ b/paimon-python/pypaimon/common/predicate_json_parser.py
@@ -45,7 +45,11 @@ _TRIM_OPS = {
# Calendar-field extractions on a DATE / TIMESTAMP field, mirroring Java's
# DateExtractTransform subclasses (name -> the Arrow kernel over a timestamp).
-# QUARTER matches (month - 1) / 3 + 1; the rest map one to one.
+# QUARTER matches (month - 1) / 3 + 1; the day-of-week variants match Java's
+# java.time numbering: WEEKDAY is Monday=0..Sunday=6, ISO_DAY_OF_WEEK is
+# Monday=1..Sunday=7, DAY_OF_WEEK is Sunday=1..Saturday=7. WEEK / YEAR_OF_WEEK
+# are the ISO week-of-week-based-year and the ISO week-based year. The rest map
+# one to one.
_DATE_EXTRACT = {
"YEAR": pc.year,
"MONTH": pc.month,
@@ -55,6 +59,11 @@ _DATE_EXTRACT = {
"SECOND": pc.second,
"QUARTER": pc.quarter,
"DAY_OF_YEAR": pc.day_of_year,
+ "WEEKDAY": lambda c: pc.day_of_week(c, count_from_zero=True, week_start=1),
+ "ISO_DAY_OF_WEEK": lambda c: pc.day_of_week(c, count_from_zero=False,
week_start=1),
+ "DAY_OF_WEEK": lambda c: pc.day_of_week(c, count_from_zero=False,
week_start=7),
+ "WEEK": pc.iso_week,
+ "YEAR_OF_WEEK": pc.iso_year,
}
diff --git a/paimon-python/pypaimon/tests/predicate_json_parser_test.py
b/paimon-python/pypaimon/tests/predicate_json_parser_test.py
index e6f6f0d4a5..8c96c1a04e 100644
--- a/paimon-python/pypaimon/tests/predicate_json_parser_test.py
+++ b/paimon-python/pypaimon/tests/predicate_json_parser_test.py
@@ -806,7 +806,8 @@ class TestConcatWsAllNull(unittest.TestCase):
class TestDateExtractTransforms(unittest.TestCase):
- """YEAR / MONTH / DAY / HOUR / MINUTE / SECOND / QUARTER / DAY_OF_YEAR,
+ """YEAR / MONTH / DAY / HOUR / MINUTE / SECOND / QUARTER / DAY_OF_YEAR /
+ WEEKDAY / ISO_DAY_OF_WEEK / DAY_OF_WEEK / WEEK / YEAR_OF_WEEK,
mirroring Java's DateExtractTransform subclasses."""
def _ts_batch(self):
@@ -832,6 +833,26 @@ class TestDateExtractTransforms(unittest.TestCase):
self.assertEqual(self._apply("QUARTER", batch), [1, 3, None])
self.assertEqual(self._apply("DAY_OF_YEAR", batch), [1, 183, None])
+ def test_week_family_parts(self):
+ # 2024-01-01 Monday, 2023-01-01 Sunday, 2021-01-01 Friday (ISO week 53
+ # of the 2020 week-based year), plus null. Numbering matches java.time.
+ batch = pa.RecordBatch.from_pydict({
+ "d": pa.array(
+ [datetime.date(2024, 1, 1), datetime.date(2023, 1, 1),
+ datetime.date(2021, 1, 1), None],
+ type=pa.date32()),
+ })
+ # WEEKDAY Monday=0..Sunday=6
+ self.assertEqual(self._apply("WEEKDAY", batch, "d", "DATE"), [0, 6, 4,
None])
+ # ISO_DAY_OF_WEEK Monday=1..Sunday=7
+ self.assertEqual(self._apply("ISO_DAY_OF_WEEK", batch, "d", "DATE"),
[1, 7, 5, None])
+ # DAY_OF_WEEK Sunday=1..Saturday=7
+ self.assertEqual(self._apply("DAY_OF_WEEK", batch, "d", "DATE"), [2,
1, 6, None])
+ # WEEK: ISO week of the week-based year
+ self.assertEqual(self._apply("WEEK", batch, "d", "DATE"), [1, 52, 53,
None])
+ # YEAR_OF_WEEK: ISO week-based year
+ self.assertEqual(self._apply("YEAR_OF_WEEK", batch, "d", "DATE"),
[2024, 2022, 2020, None])
+
def test_date_field_starts_at_midnight(self):
# epoch day 19723 == 2024-01-01; a DATE has no time, so HOUR is 0.
batch = pa.RecordBatch.from_pydict(