raminqaf commented on code in PR #29311:
URL: https://github.com/apache/flink/pull/29311#discussion_r4152651788


##########
flink-table/flink-table-runtime/src/main/java/org/apache/flink/table/runtime/functions/VariantCastUtils.java:
##########
@@ -540,6 +551,111 @@ private static Number numeric(Variant variant, String 
targetType) {
         }
     }
 
+    public static Variant fromBoolean(boolean value) {
+        return BUILDER.of(value);
+    }
+
+    /**
+     * Stores an integer in the integer kind of its SQL type, so a {@code 
BIGINT} stays a {@code
+     * BIGINT} whatever its value. The generated code passes the primitive of 
the source type, which
+     * selects the overload.
+     */
+    public static Variant fromIntegral(byte value) {
+        return BUILDER.of(value);
+    }
+
+    public static Variant fromIntegral(short value) {
+        return BUILDER.of(value);
+    }
+
+    public static Variant fromIntegral(int value) {
+        return BUILDER.of(value);
+    }
+
+    public static Variant fromIntegral(long value) {
+        return BUILDER.of(value);
+    }
+
+    public static Variant fromFloat(float value) {
+        return BUILDER.of(value);
+    }
+
+    public static Variant fromDouble(double value) {
+        return BUILDER.of(value);
+    }
+
+    public static Variant fromDecimal(DecimalData value) {
+        return BUILDER.of(value.toBigDecimal());
+    }
+
+    public static Variant fromString(StringData value) {
+        return BUILDER.of(value.toString());
+    }
+
+    public static Variant fromBytes(byte[] value) {
+        return BUILDER.of(value);
+    }
+
+    public static Variant fromDate(int epochDay) {
+        return BUILDER.of(LocalDate.ofEpochDay(epochDay));
+    }
+
+    public static Variant fromTime(int millisOfDay) {
+        return BUILDER.of(LocalTime.ofNanoOfDay(millisOfDay * 1_000_000L));
+    }
+
+    /**
+     * Stores a timestamp in the kind its declared precision needs: 
microseconds up to {@code
+     * TIMESTAMP(6)} and nanoseconds above, whatever the digits of the value. 
A nanosecond kind only
+     * covers 1677-09-21 to 2262-04-11, so a {@code TIMESTAMP(7)} to {@code 
TIMESTAMP(9)} value
+     * outside that range fails.
+     */
+    public static Variant fromTimestamp(TimestampData value, int precision) {
+        final BinaryVariantInternalBuilder builder = new 
BinaryVariantInternalBuilder(false);
+        if (precision <= TIMESTAMP_PRECISION) {
+            builder.appendTimestamp(timestampMicros(value));
+        } else {
+            builder.appendTimestampNanos(timestampNanos(value, "TIMESTAMP(" + 
precision + ")"));
+        }
+        return builder.build();
+    }
+
+    /** Like {@link #fromTimestamp(TimestampData, int)}, for {@code 
TIMESTAMP_LTZ}. */
+    public static Variant fromTimestampLtz(TimestampData value, int precision) 
{
+        final BinaryVariantInternalBuilder builder = new 
BinaryVariantInternalBuilder(false);
+        if (precision <= TIMESTAMP_PRECISION) {
+            builder.appendTimestampLtz(timestampMicros(value));
+        } else {
+            builder.appendTimestampLtzNanos(
+                    timestampNanos(value, "TIMESTAMP_LTZ(" + precision + ")"));
+        }
+        return builder.build();
+    }
+
+    /** Microseconds since the epoch, which cover every year a {@link 
TimestampData} can hold. */
+    private static long timestampMicros(TimestampData value) {

Review Comment:
   Added `TIMESTAMP(6)` and `TIMESTAMP_LTZ(6)` cases for 
`1969-12-31T23:59:59.999999`, which is micros `-1`.



-- 
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]

Reply via email to