bujjibabukatta commented on code in PR #17895: URL: https://github.com/apache/iceberg/pull/17895#discussion_r3943199032
########## api/src/main/java/org/apache/iceberg/transforms/UUIDv7Timestamps.java: ########## @@ -0,0 +1,187 @@ +/* + * 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.transforms; + +import com.google.errorprone.annotations.Immutable; +import java.time.temporal.ChronoUnit; +import java.util.UUID; +import org.apache.iceberg.expressions.BoundPredicate; +import org.apache.iceberg.expressions.BoundTransform; +import org.apache.iceberg.expressions.Expression; +import org.apache.iceberg.expressions.Expressions; +import org.apache.iceberg.expressions.UnboundPredicate; +import org.apache.iceberg.relocated.com.google.common.base.Preconditions; +import org.apache.iceberg.types.Type; +import org.apache.iceberg.types.Types; +import org.apache.iceberg.util.DateTimeUtil; +import org.apache.iceberg.util.SerializableFunction; + +enum UUIDv7Timestamps implements Transform<UUID, Integer> { + UUID_TO_YEAR(ChronoUnit.YEARS, "year"), + UUID_TO_MONTH(ChronoUnit.MONTHS, "month"), + UUID_TO_DAY(ChronoUnit.DAYS, "day"), + UUID_TO_HOUR(ChronoUnit.HOURS, "hour"); + + private static final int VERSION_AND_RAND_A_BITS = 16; + + @Immutable + static class Apply implements SerializableFunction<UUID, Integer> { + private final ChronoUnit granularity; + + Apply(ChronoUnit granularity) { + this.granularity = granularity; + } + + @Override + public Integer apply(UUID uuid) { + if (uuid == null) { + return null; + } + long unixMillis = uuid.getMostSignificantBits() >>> VERSION_AND_RAND_A_BITS; Review Comment: Hi @pvary, thanks for flagging this. I've added a check in Apply.apply() that reads the UUID's version nibble and throws IllegalArgumentException if it isn't 7, instead of silently deriving a bogus timestamp from a non-v7 UUID. This means a column with any non-v7 UUIDs will now throw at read/write time when this transform is applied. Let me know if you'd prefer different behavior — e.g. treating non-v7 values as unpartitionable instead of failing loudly. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
