-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
Partitioned table tests and fixed #9757
Merged
findepi
merged 8 commits into
trinodb:master
from
findepi:findepi/iceberg-convert-carefully
Oct 25, 2021
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
e662e1c
Import String.join statically
findepi b02aa2a
Move type conversion utility to a separate class
findepi 24637f4
Refactor and supplement all types Iceberg tests
findepi c8299b9
Fix Iceberg $partitions for UUID
findepi c18e2c6
Retain other settings in QueryAssert#projected
findepi 34d1c65
Convert from Iceberg to Trino representation strictly
findepi 7bf6005
Support long timestamp(tz) in InMemoryRecordSet
findepi 73e214b
Fix handling of Iceberg timestamptz partition key
findepi 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 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 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 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 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 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 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 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 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 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
101 changes: 101 additions & 0 deletions
101
plugin/trino-iceberg/src/main/java/io/trino/plugin/iceberg/IcebergTypes.java
This file contains 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,101 @@ | ||
/* | ||
* Licensed 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 io.trino.plugin.iceberg; | ||
|
||
import io.trino.spi.type.DecimalType; | ||
import io.trino.spi.type.Decimals; | ||
import io.trino.spi.type.UuidType; | ||
import org.apache.iceberg.types.Type; | ||
import org.apache.iceberg.types.Types; | ||
|
||
import java.math.BigDecimal; | ||
import java.nio.ByteBuffer; | ||
import java.nio.CharBuffer; | ||
import java.util.UUID; | ||
|
||
import static io.airlift.slice.Slices.utf8Slice; | ||
import static io.trino.plugin.iceberg.util.Timestamps.timestampTzFromMicros; | ||
import static io.trino.spi.type.Decimals.isShortDecimal; | ||
import static io.trino.spi.type.Timestamps.PICOSECONDS_PER_MICROSECOND; | ||
|
||
public final class IcebergTypes | ||
{ | ||
private IcebergTypes() {} | ||
|
||
/** | ||
* Convert value from Iceberg representation to Trino representation. | ||
*/ | ||
public static Object convertIcebergValueToTrino(Type icebergType, Object value) | ||
{ | ||
if (value == null) { | ||
return null; | ||
} | ||
if (icebergType instanceof Types.BooleanType) { | ||
//noinspection RedundantCast | ||
return (Boolean) value; | ||
} | ||
if (icebergType instanceof Types.IntegerType) { | ||
return ((Integer) value).longValue(); | ||
} | ||
if (icebergType instanceof Types.LongType) { | ||
//noinspection RedundantCast | ||
return (Long) value; | ||
} | ||
if (icebergType instanceof Types.FloatType) { | ||
return (long) Float.floatToIntBits((Float) value); | ||
} | ||
if (icebergType instanceof Types.DoubleType) { | ||
//noinspection RedundantCast | ||
return (Double) value; | ||
} | ||
if (icebergType instanceof Types.DecimalType) { | ||
Types.DecimalType icebergDecimalType = (Types.DecimalType) icebergType; | ||
DecimalType trinoDecimalType = DecimalType.createDecimalType(icebergDecimalType.precision(), icebergDecimalType.scale()); | ||
if (isShortDecimal(trinoDecimalType)) { | ||
return Decimals.encodeShortScaledValue((BigDecimal) value, trinoDecimalType.getScale()); | ||
} | ||
return Decimals.encodeScaledValue((BigDecimal) value, trinoDecimalType.getScale()); | ||
} | ||
if (icebergType instanceof Types.StringType) { | ||
// Partition values are passed as String, but min/max values are passed as a CharBuffer | ||
if (value instanceof CharBuffer) { | ||
value = new String(((CharBuffer) value).array()); | ||
} | ||
return utf8Slice(((String) value)); | ||
} | ||
if (icebergType instanceof Types.BinaryType) { | ||
// TODO the client sees the bytearray's tostring ouput instead of seeing actual bytes, needs to be fixed. | ||
// TODO return Slice | ||
return ((ByteBuffer) value).array().clone(); | ||
} | ||
if (icebergType instanceof Types.DateType) { | ||
return ((Integer) value).longValue(); | ||
} | ||
if (icebergType instanceof Types.TimeType) { | ||
return Math.multiplyExact((Long) value, PICOSECONDS_PER_MICROSECOND); | ||
} | ||
if (icebergType instanceof Types.TimestampType) { | ||
long epochMicros = (long) value; | ||
if (((Types.TimestampType) icebergType).shouldAdjustToUTC()) { | ||
return timestampTzFromMicros(epochMicros); | ||
} | ||
return epochMicros; | ||
} | ||
if (icebergType instanceof Types.UUIDType) { | ||
return UuidType.javaUuidToTrinoUuid((UUID) value); | ||
} | ||
|
||
throw new UnsupportedOperationException("Unsupported iceberg type: " + icebergType); | ||
} | ||
} |
This file contains 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.
what does
shouldAdjustToUTC
mean here?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 think it means "this is
timestamptz
, nottimestamp
type".seems the two are conflated into
Types.TimestampType
class