Skip to content

feat: add date functions QUARTER and DAY_OF_YEAR#814

Open
YinZiBenRun wants to merge 2 commits into
apache:masterfrom
YinZiBenRun:feature/add-date-functions-quarter-dayofyear
Open

feat: add date functions QUARTER and DAY_OF_YEAR#814
YinZiBenRun wants to merge 2 commits into
apache:masterfrom
YinZiBenRun:feature/add-date-functions-quarter-dayofyear

Conversation

@YinZiBenRun

Copy link
Copy Markdown
Contributor

Add two new date UDFs:

  • quarter(date): returns the quarter of the year (1-4)
  • day_of_year(date): returns the day of the year (1-366)

Both follow the existing WeekOfYear pattern using Joda-Time. Registered in BuildInSqlFunctionTable.
Tests cover quarter boundaries, leap years, year boundaries, and null inputs.

Closes #791

What changes were proposed in this pull request?

Add two new date UDFs:

  • quarter(date): returns the quarter of the year (1-4), e.g. quarter('2020-06-05') = 2
  • day_of_year(date): returns the day of the year (1-366), e.g. day_of_year('2020-12-31') = 366

Both follow the existing WeekOfYear pattern using Joda-Time DateTime and DateTimeFormatter.
Registered in BuildInSqlFunctionTable.java.

How was this PR tested?

  • [√] Tests have Added for the changes
  • Production environment verified

@YinZiBenRun

Copy link
Copy Markdown
Contributor Author

#791

}

@Test
public void testQuarter() {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These tests verify the Java methods directly, but they do not exercise SQL registration, overload resolution, type inference, or runtime invocation.
Could we add an end-to-end SQL test for them there?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

已添加端到端 SQL 测试,通过完整查询管线验证函数的注册、重载解析、类型推断和运行时调用。测试在 geaflow-dsl-runtime 模块:

  • DateQuarterDayOfYearTest.java - 通过 QueryTester 驱动测试
  • query/date_quarter_dayofyear_001.sql - 调用 quarter() 和 day_of_year()
  • data/ + expect/ - 输入数据与期望输出

测试覆盖了季度边界(Q1-Q4)、闰年(2020-12-31=366,2020-02-29=60)、非闰年(2019-12-31=365)以及年初/年末边界。

已在本地验证通过(Tests run: 1, Failures: 0, Errors: 0)。

1+5 added 2 commits July 26, 2026 12:27
Add two new date UDFs:
- quarter(date): returns the quarter of the year (1-4)
- day_of_year(date): returns the day of the year (1-366)

Both follow the existing WeekOfYear pattern using Joda-Time.
Registered in BuildInSqlFunctionTable.
Tests cover quarter boundaries, leap years, year boundaries, and null inputs.

Closes apache#791
The existing UDFDateTest verifies the Java eval() methods directly but
does not exercise SQL registration, overload resolution, type inference,
or runtime invocation. Add an E2E SQL test via QueryTester that runs the
functions through the full query pipeline.

Covers quarter boundaries (Q1-Q4), leap-year day_of_year values
(2020-12-31=366, 2020-02-29=60), non-leap year (2019-12-31=365), and
year start/end boundaries.

Verified locally: Tests run: 1, Failures: 0, Errors: 0.
@YinZiBenRun
YinZiBenRun force-pushed the feature/add-date-functions-quarter-dayofyear branch from c0d6e72 to 49d3651 Compare July 26, 2026 04:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add the date functions QUARTER / DAY_OF_YEAR

2 participants