chovy-3012 opened a new pull request, #12703:
URL: https://github.com/apache/seatunnel/pull/12703
### Purpose of this pull request
Add a `UNIX_TIMESTAMP` built-in SQL function to the Zeta SQL transform, the
inverse of the existing `FROM_UNIXTIME`, as requested in #12699.
Supported forms:
- `UNIX_TIMESTAMP()` — current epoch seconds.
- `UNIX_TIMESTAMP(dateTime)` — a TIMESTAMP / TIMESTAMP_TZ / DATE column.
- `UNIX_TIMESTAMP(string[, pattern])` — parsed with an optional pattern
(default `yyyy-MM-dd HH:mm:ss`); unparseable input returns NULL rather than
raising. An explicit NULL pattern returns NULL.
Motivation: epoch-second conversion for downstream sinks and SQL-dialect
parity.
Changes (8 files, +315 lines, pure addition):
- `ZetaSQLFunction.java`: register the `UNIX_TIMESTAMP` constant and add the
dispatch case.
- `ZetaSQLType.java`: resolve the return type as LONG (BIGINT).
- `DateTimeFunction.java`: implement `unixTimestamp()` — no-arg / typed
datetime / string+pattern; resolved against the system time zone (inverse of
`fromUnixTime`). Uses only `java.time`, no new dependency.
- `SQLDateTimeFunctionsTest.java`: 11 cases (no-arg,
default/custom/date-only patterns, null input, unparseable, null pattern,
numeric, LocalDateTime/LocalDate/OffsetDateTime).
- `docs/{en,zh}/transforms/sql-functions.md`: document `UNIX_TIMESTAMP`
after `FROM_UNIXTIME`.
- E2E: `func_unix_timestamp.conf` + mounted in `TestSQLIT`.
Closes #12699
### Does this PR introduce _any_ user-facing change?
Yes — a new built-in SQL function. Pure addition; no existing function or
behavior is changed.
```sql
select UNIX_TIMESTAMP('2023-01-01 00:00:00') as ts -- 1672531200
select UNIX_TIMESTAMP(dt) as ts
```
### How was this patch tested?
```bash
./mvnw -pl seatunnel-transforms-v2 test -Dtest=SQLDateTimeFunctionsTest
./mvnw -pl seatunnel-transforms-v2 spotless:check
```
Unit: `SQLDateTimeFunctionsTest` — 16/16 pass. E2E:
`func_unix_timestamp.conf` added under `seatunnel-transforms-v2-e2e-part-2`,
mounted in `TestSQLIT`.
### Check list
* [ ] If any new Jar binary package adding in your PR, please add License
Notice according [New License
Guide](https://github.com/apache/seatunnel/blob/dev/docs/en/developer/new-license.md)
— N/A, no new dependency (java.time only).
* [x] If necessary, please update the documentation to describe the new
feature. https://github.com/apache/seatunnel/tree/dev/docs — Updated `docs/en`
and `docs/zh` `transforms/sql-functions.md`.
* [ ] If necessary, please update `incompatible-changes.md` to describe the
incompatibility caused by this PR. — N/A, pure addition, no incompatible change.
* [ ] If you are contributing the connector code, please check that the
following files are updated — N/A, not a connector change.
--
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]