-
Notifications
You must be signed in to change notification settings - Fork 3k
Add support for reading/writing timestamps without timezone. #2757
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
Merged
RussellSpitzer
merged 23 commits into
apache:master
from
sshkvar:spark-parquet-read-ts-as-tstz
Jul 15, 2021
Merged
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
3268799
spark: Add in support to read timestamp without timezone from parquet
bkahloon 4b9a190
spark: Remove ORC vectorized test for reading timestamp without timezone
bkahloon f5036fb
Spark: address PR comments
bkahloon bac19c6
Spark: fix build failure due to import of all iceberg packages
bkahloon ab0bf3a
Spark: remove unsed imports and try to fix package import ordering
bkahloon f8a5293
Spark: fix code formatting issue
bkahloon ee386b9
Spark: fix code formatting issue
bkahloon fc6ee0e
Spark: Fix formatting error of long line
bkahloon e537c0b
Spark: Fix formatting error of long line
bkahloon abb607e
Add support for writing timestamps without timezone.
sshkvar 4bee290
Added missed check for handling tomestamp without zone for Writer in …
sshkvar 0259262
Added missed check for handling tomestamp without zone for Writer in …
sshkvar 1579abc
Address PR comments.
sshkvar 4f37486
Address PR comments.
sshkvar bafaffb
Address PR comments.
sshkvar 7acaec0
Address PR comments.
sshkvar cee72a0
Address few little clean up
sshkvar 459ce89
Address few little clean up
sshkvar d14b2b2
Address few little clean up
sshkvar 398a2a0
fix for `'lambda arguments' has incorrect indentation level 12, expec…
sshkvar 3f6b0f2
fix for `incorrect indentation level 6, expected level should be 8.`
sshkvar bc316c4
Added withSQLConf method to AvroDataTest.java as suggested in the PR …
sshkvar c5917c6
Fixed overly indented as requested in PR
sshkvar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
spark/src/main/java/org/apache/iceberg/spark/SparkFixupTimestampType.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
|
|
||
| package org.apache.iceberg.spark; | ||
|
|
||
| import org.apache.iceberg.Schema; | ||
| import org.apache.iceberg.types.FixupTypes; | ||
| import org.apache.iceberg.types.Type; | ||
| import org.apache.iceberg.types.TypeUtil; | ||
| import org.apache.iceberg.types.Types; | ||
|
|
||
| /** | ||
| * By default Spark type {@link org.apache.iceberg.types.Types.TimestampType} should be converted to | ||
| * {@link Types.TimestampType#withZone()} iceberg type. But we also can convert | ||
| * {@link org.apache.iceberg.types.Types.TimestampType} to {@link Types.TimestampType#withoutZone()} iceberg type | ||
| * by setting {@link SparkUtil#USE_TIMESTAMP_WITHOUT_TIME_ZONE_IN_NEW_TABLES} to 'true' | ||
| */ | ||
| class SparkFixupTimestampType extends FixupTypes { | ||
|
|
||
| private SparkFixupTimestampType(Schema referenceSchema) { | ||
| super(referenceSchema); | ||
| } | ||
|
|
||
| static Schema fixup(Schema schema) { | ||
| return new Schema(TypeUtil.visit(schema, | ||
| new SparkFixupTimestampType(schema)).asStructType().fields()); | ||
| } | ||
|
|
||
| @Override | ||
| public Type primitive(Type.PrimitiveType primitive) { | ||
| if (primitive.typeId() == Type.TypeID.TIMESTAMP) { | ||
| return Types.TimestampType.withoutZone(); | ||
| } | ||
| return primitive; | ||
| } | ||
|
|
||
| @Override | ||
| protected boolean fixupPrimitive(Type.PrimitiveType type, Type source) { | ||
| return Type.TypeID.TIMESTAMP.equals(type.typeId()); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
As a follow up PR (in a separate PR either before or after this one is merged), particularly if you're looking for some more work to do to contribute to the project, you might explore if this combination of
withSQLConfand the corresponding@FunctionalInterfacecan be abstracted into their own interface that one could mix into tests.I'm not 100% sure how that would look, maybe an interface like
ConfigurableTestSQLConfor something?Again, just copying it for now is fine, but it would be nice to reduce the code duplication and make this easier for others to use in the future. Your exploration might find that it’s better to not do that (I’m more of a Scala developer myself and so to me it feels like a mixin). Something to think about for later though!
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.
I am fully agree with you, it can be moved to separate interface with static method and placed in some general package like
But this part better to do in separate PR, because other packages will be affected