-
Notifications
You must be signed in to change notification settings - Fork 4.5k
Add portable Date type #37830
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
base: master
Are you sure you want to change the base?
Add portable Date type #37830
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| { | ||
| "comment": "Modify this file in a trivial way to cause this test suite to run", | ||
| "modification": 0 | ||
| "modification": 1 | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| { | ||
| "comment": "Modify this file in a trivial way to cause this test suite to run", | ||
| "modification": 2 | ||
| "modification": 3 | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -34,6 +34,7 @@ | |
| bytes <-----> BYTES | ||
| ByteString ------> BYTES | ||
| Timestamp <-----> LogicalType(urn="beam:logical_type:micros_instant:v1") | ||
| datetime.date <---> LogicalType(urn="beam:logical_type:date:v1") | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Most Java SDK's IO uses joda data and time, and are serialized as joda timestamp. Then JDBCDateType and JDBCTimeType were created to accomadate them. WIth the introducation of "ture" portable data/time logical types, we need to make sure it doesn't break existing Python JdbcIO. We can run https://github.com/apache/beam/actions/workflows/beam_PostCommit_Python_Xlang_Gcp_Direct.yml against this PR to test |
||
| Decimal <-----> LogicalType(urn="beam:logical_type:fixed_decimal:v1") | ||
| Mapping <-----> MapType | ||
| Sequence <-----> ArrayType | ||
|
|
@@ -991,6 +992,33 @@ def to_language_type(self, value): | |
| return Timestamp(seconds=int(value.seconds), micros=int(value.micros)) | ||
|
|
||
|
|
||
| # @LogicalType._register_internal | ||
ahmedabu98 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| # class Date(NoArgumentLogicalType[datetime.date, np.int64]): | ||
| # """Date logical type that handles ``datetime.date``, days since epoch.""" | ||
| # EPOCH = datetime.date(1970, 1, 1) | ||
| # | ||
| # @classmethod | ||
| # def urn(cls): | ||
| # return common_urns.date.urn | ||
| # | ||
| # @classmethod | ||
| # def representation_type(cls): | ||
| # # type: () -> type | ||
| # return np.int64 | ||
| # | ||
| # @classmethod | ||
| # def language_type(cls): | ||
| # return datetime.date | ||
| # | ||
| # def to_representation_type(self, value): | ||
| # # type: (datetime.date) -> np.int64 | ||
| # return (value - self.EPOCH).days | ||
| # | ||
| # def to_language_type(self, value): | ||
| # # type: (np.int64) -> datetime.date | ||
| # return self.EPOCH + datetime.timedelta(days=value) | ||
|
|
||
|
|
||
| @LogicalType._register_internal | ||
| class PythonCallable(NoArgumentLogicalType[PythonCallableWithSource, str]): | ||
| """A logical type for PythonCallableSource objects.""" | ||
|
|
||
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.
Consider adding TIME as well?