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


##########
flink-table/flink-table-planner/src/main/java/org/apache/flink/table/planner/functions/casting/PrimitiveToVariantCastRule.java:
##########
@@ -0,0 +1,149 @@
+/*
+ * 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.flink.table.planner.functions.casting;
+
+import org.apache.flink.table.runtime.functions.VariantCastUtils;
+import org.apache.flink.table.types.logical.LogicalType;
+import org.apache.flink.table.types.logical.LogicalTypeRoot;
+import org.apache.flink.table.types.logical.utils.LogicalTypeChecks;
+import org.apache.flink.types.variant.Variant;
+
+import static 
org.apache.flink.table.planner.functions.casting.CastRuleUtils.staticCall;
+
+/**
+ * Primitive type to {@link LogicalTypeRoot#VARIANT} cast rule.
+ *
+ * <p>The value keeps the kind of its SQL type, so a {@code BIGINT} is stored 
as a {@code BIGINT}
+ * even when it would fit a smaller one. Unlike {@code PARSE_JSON}, a {@code 
NaN} or infinite {@code
+ * FLOAT} or {@code DOUBLE} is accepted, since a {@code VARIANT} is not 
limited to what JSON can
+ * express. A timestamp keeps its declared precision, so a {@code 
TIMESTAMP(p)} with {@code p} above
+ * 6 is stored with nanoseconds. That kind only covers 1677-09-21 to 
2262-04-11, so such a cast
+ * fails for a value outside that range. Every other cast never fails.
+ */
+class PrimitiveToVariantCastRule extends 
AbstractExpressionCodeGeneratorCastRule<Object, Variant> {
+
+    static final PrimitiveToVariantCastRule INSTANCE = new 
PrimitiveToVariantCastRule();
+
+    /** The highest precision a VARIANT stores with microseconds, above it 
nanoseconds are used. */
+    private static final int MAX_MICROS_PRECISION = 6;

Review Comment:
   Done. Remove and reuse `TIMESTAMP_PRECISION`



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