-
Notifications
You must be signed in to change notification settings - Fork 6
feat: Add support for Timestamp data type #33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@abandy You may want to take a look at this too. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds support for the Timestamp data type in Swift Arrow by introducing new types, builders, and helper functions for formatting and serialization/deserialization. Key changes include:
- Implementing TimestampArray, ArrowTypeTimestamp, and associated formatting utilities.
- Extending builder and reader/writer helpers to recognize and handle Timestamp.
- Adding comprehensive tests for Timestamp functionality in both CData and Array test suites.
Reviewed Changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.
Show a summary per file
File | Description |
---|---|
Arrow/Tests/ArrowTests/CDataTests.swift | Added tests for Timestamp fields with different units and timezone configurations. |
Arrow/Tests/ArrowTests/ArrayTests.swift | Introduced testTimestampArray covering various Timestamp units and formatting options. |
Arrow/Sources/Arrow/ProtoUtil.swift | Added Timestamp case handling for protobuffer conversion. |
Arrow/Sources/Arrow/ArrowWriterHelper.swift | Extended writer helper to include Timestamp serialization logic. |
Arrow/Sources/Arrow/ArrowType.swift | Introduced Timestamp alias, ArrowTypeTimestamp, and updated type-related functions. |
Arrow/Sources/Arrow/ArrowReaderHelper.swift | Added Timestamp support in array holder creation and type discovery. |
Arrow/Sources/Arrow/ArrowArrayBuilder.swift | Added TimestampArrayBuilder and integrated it into the builder registry. |
Arrow/Sources/Arrow/ArrowArray.swift | Added TimestampArray implementation with formatting utilities for date conversion. |
Comments suppressed due to low confidence (1)
Arrow/Tests/ArrowTests/CDataTests.swift:47
- [nitpick] Consider using more descriptive field names for Timestamp columns (e.g., 'colTimestampNanoseconds' instead of 'colTimestamptsn') to improve clarity in tests.
.addField("colTimestamptsn", type: ArrowTypeTimestamp(.nanoseconds), isNullable: false)
Arrow/Sources/Arrow/ArrowArray.swift
Outdated
let formatter = DateFormatter() | ||
formatter.dateFormat = options.dateFormat | ||
formatter.locale = options.locale | ||
|
||
if options.includeTimezone, let timezone = timestampType.timezone { | ||
formatter.timeZone = TimeZone(identifier: timezone) | ||
} | ||
|
||
return formatter.string(from: date) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Creating a new DateFormatter for each call of formattedDate(at:) may impact performance in tight loops; consider caching a formatter instance if possible.
let formatter = DateFormatter() | |
formatter.dateFormat = options.dateFormat | |
formatter.locale = options.locale | |
if options.includeTimezone, let timezone = timestampType.timezone { | |
formatter.timeZone = TimeZone(identifier: timezone) | |
} | |
return formatter.string(from: date) | |
if cachedFormatter == nil || cachedOptions != options { | |
let formatter = DateFormatter() | |
formatter.dateFormat = options.dateFormat | |
formatter.locale = options.locale | |
if options.includeTimezone, let timezone = timestampType.timezone { | |
formatter.timeZone = TimeZone(identifier: timezone) | |
} | |
cachedFormatter = formatter | |
cachedOptions = options | |
} | |
return cachedFormatter?.string(from: date) |
Copilot uses AI. Check for mistakes.
Could you fix lint error? You can use |
FYI: You can check CI results on your fork by enabling GitHub Actions on your fork. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm!
I've fixed linters by using the |
Co-authored-by: Sutou Kouhei <kou@cozmixng.org>
Co-authored-by: Sutou Kouhei <kou@cozmixng.org>
Co-authored-by: Sutou Kouhei <kou@cozmixng.org>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1
Rationale for this change
Currently, the Swift implementation of Arrow does not support Timestamp, although they are available in the base C interface. This PR attempts to add its support by following the current implemented design pattern.
What changes are included in this PR?
TimestampArray
with some basic formatting utilitiesTimestampArrayBuilder
Timestamp
aliasArrowTimestampUnit
, which includes extensively all the variants (seconds, milliseconds, microseconds and nanoseconds)ArrowTypeTimestamp
from baseArrow
ArrowType
support for timestampArrowWriterHelper
support for timestampfromProto
support for timestampIt properly handles the presence or absence of
timezone
.Are these changes tested?
Tests are included in both
ArrayTests.swift
andCDataTests.swift
.Are there any user-facing changes?
Yes - users can now work with Timestamp data types in Swift Arrow implementations. This is additive and doesn't break existing functionality.
Closes #32.