raminqaf commented on code in PR #28146:
URL: https://github.com/apache/flink/pull/28146#discussion_r3234339581
##########
flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/inference/strategies/ToTimestampLtzTypeStrategy.java:
##########
@@ -66,19 +70,24 @@ public Optional<DataType> inferType(CallContext
callContext) {
}
break;
case 2:
- LogicalType secondType = argumentTypes.get(1).getLogicalType();
+ LogicalType secondType =
+
argumentTypes.get(PRECISION_OR_FORMAT_ARG).getLogicalType();
LogicalTypeRoot secondTypeRoot = secondType.getTypeRoot();
if (firstType.is(LogicalTypeFamily.NUMERIC)) {
if (secondTypeRoot != LogicalTypeRoot.INTEGER) {
throw new ValidationException(
"Unsupported argument type. "
+ "TO_TIMESTAMP_LTZ(<NUMERIC>,
<INTEGER>) requires the second argument to be <INTEGER>.");
}
- Optional<Integer> precisionOpt =
callContext.getArgumentValue(1, Integer.class);
- if (precisionOpt.isPresent()) {
- int precision = precisionOpt.get();
- validatePrecision(precision);
- outputPrecision = Math.max(precision,
DEFAULT_PRECISION);
+ if
(callContext.isArgumentLiteral(PRECISION_OR_FORMAT_ARG)) {
Review Comment:
Thanks for pointing this out. I have added the log.warning to places where
we fallback to the default precision during planing
##########
flink-table/flink-table-common/src/main/java/org/apache/flink/table/expressions/ValueLiteralExpression.java:
##########
@@ -462,11 +462,18 @@ private static String serializeTimestampLtz(Instant
instant, int precision) {
/**
* Checks whether an {@link Instant} can be represented as a {@code long}
epoch value at the
- * given precision without overflow.
+ * given precision without overflow. Accounts for the sub-second nanos
term that {@link
+ * DateTimeUtils#toEpochValue} adds on top of {@code epochSeconds *
10^precision}.
*/
private static boolean canRepresentAsLong(Instant instant, int precision) {
- long factor = (long) Math.pow(10, precision);
- long epochSeconds = instant.getEpochSecond();
- return factor == 0 || Math.abs(epochSeconds) <= Long.MAX_VALUE /
factor;
+ final long factor = (long) Math.pow(10, precision);
+ final long nanoDivisor = (long) Math.pow(10, 9 - precision);
+ final long epochSeconds = instant.getEpochSecond();
+ final long nanoPart = instant.getNano() / nanoDivisor;
+ if (epochSeconds > Long.MAX_VALUE / factor || epochSeconds <
Long.MIN_VALUE / factor) {
+ return false;
+ }
+ final long base = epochSeconds * factor;
+ return base < 0 || nanoPart <= Long.MAX_VALUE - base;
Review Comment:
Added
--
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]