danielcweeks commented on code in PR #12311:
URL: https://github.com/apache/iceberg/pull/12311#discussion_r1970288476
##########
api/src/main/java/org/apache/iceberg/variants/VariantUtil.java:
##########
@@ -18,21 +18,112 @@
*/
package org.apache.iceberg.variants;
+import java.math.BigDecimal;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.charset.StandardCharsets;
+import java.util.Map;
import java.util.function.Function;
import org.apache.iceberg.relocated.com.google.common.base.Preconditions;
+import org.apache.iceberg.relocated.com.google.common.collect.ImmutableMap;
+import org.apache.iceberg.types.Type;
+import org.apache.iceberg.types.Types;
-class VariantUtil {
+public class VariantUtil {
private static final int BASIC_TYPE_MASK = 0b11;
private static final int BASIC_TYPE_PRIMITIVE = 0;
private static final int BASIC_TYPE_SHORT_STRING = 1;
private static final int BASIC_TYPE_OBJECT = 2;
private static final int BASIC_TYPE_ARRAY = 3;
+ // TODO: Implement PhysicalType.TIME
+ // TODO: Implement PhysicalType.TIMESTAMPNTZ_NANO and
PhysicalType.TIMESTAMPTZ_NANO
+ // TODO: Implement PhysicalType.UUID
+ private static final Map<Type, PhysicalType> NO_CONVERSION_NEEDED =
+ ImmutableMap.<Type, PhysicalType>builder()
+ .put(Types.IntegerType.get(), PhysicalType.INT32)
+ .put(Types.LongType.get(), PhysicalType.INT64)
+ .put(Types.FloatType.get(), PhysicalType.FLOAT)
+ .put(Types.DoubleType.get(), PhysicalType.DOUBLE)
+ .put(Types.DateType.get(), PhysicalType.DATE)
+ .put(Types.TimestampType.withoutZone(), PhysicalType.TIMESTAMPNTZ)
+ .put(Types.TimestampType.withZone(), PhysicalType.TIMESTAMPTZ)
+ .put(Types.StringType.get(), PhysicalType.STRING)
+ .put(Types.BinaryType.get(), PhysicalType.BINARY)
+ .put(Types.UnknownType.get(), PhysicalType.NULL)
+ .build();
+
private VariantUtil() {}
+ @SuppressWarnings("unchecked")
+ public static <T> T castTo(VariantValue value, Type type) {
Review Comment:
Wouldn't this make more sense as a static method on `VariantValue`? That
would allow us to keep the the util class package protected and this feels more
closely aligned with `VariantValue` anyway.
--
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]