Eliaaazzz opened a new pull request, #38510:
URL: https://github.com/apache/beam/pull/38510
ClickHouseIO's `TableSchema` and column-type parser only recognized
`DateTime` (second precision), so pipelines emitting sub-second timestamps
(log/event ingestion, financial data) could not write to ClickHouse tables
declared with `DateTime64(precision[, 'timezone'])` columns.
This change adds first-class `DateTime64` support to `ClickHouseIO`:
* **Schema model** — new `TypeName.DATETIME64`; `ColumnType` carries
`precision` (0–9, validated) and an optional `timezone`, with a
`ColumnType.dateTime64(precision[, timezone])` factory.
* **Parser** — JavaCC grammar rule for `DateTime64(<precision>[,
'<timezone>'])`, also reachable through `Nullable(...)` and `Array(...)` via
the existing `primitive()` rule.
* **Beam field-type mapping** — picks the narrowest logical type that
round-trips the requested precision:
* `precision ≤ 3` → Joda `DATETIME` (preserves existing pipelines).
* `precision 4–6` → `SqlTypes.TIMESTAMP` (`MicrosInstant`).
* `precision ≥ 7` → `NanosInstant`, the only built-in logical type that
preserves full nanosecond precision through a `Row`; `MicrosInstant` rejects
non-micro-aligned nanos.
* **Writer** — serializes `DateTime64` as a little-endian `Int64` of
`epoch_seconds * 10^precision + sub_second_units`, accepting both Joda
`ReadableInstant` and `java.time.Instant`. Uses `Math.floorDiv` /
`Math.floorMod` so negative timestamps match ClickHouse's encoding, and
`Math.multiplyExact` / `Math.addExact` for overflow safety.
Tests:
* `TableSchemaTest` — parser cases for `DateTime64(3)`, `DateTime64(6,
'UTC')`, `DateTime64(9)`, `Nullable(DateTime64(...))`,
`Array(DateTime64(...))`; schema-mapping tests for the millis, micros and nanos
buckets; precision-range validation.
* `ClickHouseWriterTest` — encoder unit tests covering Joda and
`java.time.Instant` inputs, precision 0/3/6/7/9, negative timestamps and the
precision-7 100 ns truncation path.
* `ClickHouseIOIT` — round-trip integration tests against the ClickHouse
test container for precisions 3/6/9 (the 9-precision case uses
non-micro-aligned nanos) and `Nullable(DateTime64(6))`.
fixes #38466
------------------------
Thank you for your contribution! Follow this checklist to help us
incorporate your contribution quickly and easily:
- [x] Mention the appropriate issue in your description (for example:
\`addresses #123\`), if applicable. This will automatically add a link to the
pull request in the issue. If you would like the issue to automatically close
on merging the pull request, comment \`fixes #<ISSUE NUMBER>\` instead.
- [x] Update \`CHANGES.md\` with noteworthy changes.
- [ ] If this contribution is large, please file an Apache [Individual
Contributor License Agreement](https://www.apache.org/licenses/icla.pdf).
See the [Contributor Guide](https://beam.apache.org/contribute) for more
tips on [how to make review process
smoother](https://github.com/apache/beam/blob/master/CONTRIBUTING.md#make-the-reviewers-job-easier).
To check the build health, please visit
[https://github.com/apache/beam/blob/master/.test-infra/BUILD_STATUS.md](https://github.com/apache/beam/blob/master/.test-infra/BUILD_STATUS.md)
GitHub Actions Tests Status (on master branch)
------------------------------------------------------------------------------------------------
[](https://github.com/apache/beam/actions?query=workflow%3A%22Build+python+source+distribution+and+wheels%22+branch%3Amaster+event%3Aschedule)
[](https://github.com/apache/beam/actions?query=workflow%3A%22Python+Tests%22+branch%3Amaster+event%3Aschedule)
[](https://github.com/apache/beam/actions?query=workflow%3A%22Java+Tests%22+branch%3Amaster+event%3Aschedule)
[](https://github.com/apache/beam/actions?query=workflow%3A%22Go+tests%22+branch%3Amaster+event%3Aschedule)
See [CI.md](https://github.com/apache/beam/blob/master/CI.md) for more
information about GitHub Actions CI or the [workflows
README](https://github.com/apache/beam/blob/master/.github/workflows/README.md)
to see a list of phrases to trigger workflows.
--
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]