forked from projectnessie/nessie
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support Iceberg's timestamp with nano-precision data type
NOTE On hold, because Iceberg code as of 1.7.1 does not yet fully support that new data type, causing test failures. Fixes projectnessie#10236
- Loading branch information
Showing
9 changed files
with
179 additions
and
40 deletions.
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
80 changes: 80 additions & 0 deletions
80
.../main/java/org/projectnessie/catalog/formats/iceberg/types/IcebergTimestampNanosType.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,80 @@ | ||
/* | ||
* Copyright (C) 2023 Dremio | ||
* | ||
* 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 org.projectnessie.catalog.formats.iceberg.types; | ||
|
||
import org.apache.avro.LogicalTypes; | ||
import org.apache.avro.Schema; | ||
|
||
/** Iceberg timestamp, nanosecond precision. */ | ||
public final class IcebergTimestampNanosType extends IcebergPrimitiveType { | ||
private static final Schema TIMESTAMP_NS_SCHEMA = | ||
LogicalTypes.timestampNanos().addToSchema(Schema.create(Schema.Type.LONG)); | ||
private static final Schema TIMESTAMPTZ_NS_SCHEMA = | ||
LogicalTypes.timestampNanos().addToSchema(Schema.create(Schema.Type.LONG)); | ||
public static final String ADJUST_TO_UTC_PROP = "adjust-to-utc"; | ||
|
||
static { | ||
TIMESTAMP_NS_SCHEMA.addProp(ADJUST_TO_UTC_PROP, false); | ||
TIMESTAMPTZ_NS_SCHEMA.addProp(ADJUST_TO_UTC_PROP, true); | ||
} | ||
|
||
private final boolean adjustToUTC; | ||
|
||
IcebergTimestampNanosType(boolean adjustToUTC) { | ||
this.adjustToUTC = adjustToUTC; | ||
} | ||
|
||
public boolean adjustToUTC() { | ||
return adjustToUTC; | ||
} | ||
|
||
@Override | ||
public String type() { | ||
return adjustToUTC() ? TYPE_TIMESTAMP_NS_TZ : TYPE_TIMESTAMP_NS; | ||
} | ||
|
||
@Override | ||
public Schema avroSchema(int fieldId) { | ||
return adjustToUTC() ? TIMESTAMPTZ_NS_SCHEMA : TIMESTAMP_NS_SCHEMA; | ||
} | ||
|
||
@Override | ||
public byte[] serializeSingleValue(Object value) { | ||
return IcebergLongType.serializeLong((Long) value); | ||
} | ||
|
||
@Override | ||
public Object deserializeSingleValue(byte[] value) { | ||
return IcebergLongType.deserializeLong(value); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return type().hashCode() ^ (adjustToUTC ? 1 : 0); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object obj) { | ||
if (!(obj instanceof IcebergTimestampNanosType)) { | ||
return false; | ||
} | ||
if (obj == this) { | ||
return true; | ||
} | ||
IcebergTimestampNanosType o = (IcebergTimestampNanosType) obj; | ||
return o.adjustToUTC == adjustToUTC; | ||
} | ||
} |
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
Oops, something went wrong.