You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flink.apache.org by tw...@apache.org on 2019/05/23 08:01:26 UTC

[flink] 01/06: [hotfix][table-common] Add default precision temporal data types

This is an automated email from the ASF dual-hosted git repository.

twalthr pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/flink.git

commit 36fef4457a7f1de47989c8a2485581bcf8633b32
Author: Timo Walther <tw...@apache.org>
AuthorDate: Tue May 21 12:19:04 2019 +0200

    [hotfix][table-common] Add default precision temporal data types
---
 .../java/org/apache/flink/table/api/DataTypes.java | 83 ++++++++++++++++++++++
 .../apache/flink/table/types/DataTypesTest.java    | 12 ++++
 2 files changed, 95 insertions(+)

diff --git a/flink-table/flink-table-common/src/main/java/org/apache/flink/table/api/DataTypes.java b/flink-table/flink-table-common/src/main/java/org/apache/flink/table/api/DataTypes.java
index 2591227..dc7c319 100644
--- a/flink-table/flink-table-common/src/main/java/org/apache/flink/table/api/DataTypes.java
+++ b/flink-table/flink-table-common/src/main/java/org/apache/flink/table/api/DataTypes.java
@@ -240,6 +240,7 @@ public final class DataTypes {
 	 * <p>Compared to the SQL standard, leap seconds (23:59:60 and 23:59:61) are not supported as the
 	 * semantics are closer to {@link java.time.LocalTime}. A time WITH time zone is not provided.
 	 *
+	 * @see #TIME()
 	 * @see TimeType
 	 */
 	public static DataType TIME(int precision) {
@@ -247,6 +248,22 @@ public final class DataTypes {
 	}
 
 	/**
+	 * Data type of a time WITHOUT time zone {@code TIME} with no fractional seconds by default.
+	 *
+	 * <p>An instance consists of {@code hour:minute:second} with up to second precision
+	 * and values ranging from {@code 00:00:00} to {@code 23:59:59}.
+	 *
+	 * <p>Compared to the SQL standard, leap seconds (23:59:60 and 23:59:61) are not supported as the
+	 * semantics are closer to {@link java.time.LocalTime}. A time WITH time zone is not provided.
+	 *
+	 * @see #TIME(int)
+	 * @see TimeType
+	 */
+	public static DataType TIME() {
+		return new AtomicDataType(new TimeType());
+	}
+
+	/**
 	 * Data type of a timestamp WITHOUT time zone {@code TIMESTAMP(p)} where {@code p} is the number
 	 * of digits of fractional seconds (=precision). {@code p} must have a value between 0 and 9 (both
 	 * inclusive).
@@ -267,6 +284,26 @@ public final class DataTypes {
 	}
 
 	/**
+	 * Data type of a timestamp WITHOUT time zone {@code TIMESTAMP} with 6 digits of fractional seconds
+	 * by default.
+	 *
+	 * <p>An instance consists of {@code year-month-day hour:minute:second[.fractional]} with up to
+	 * microsecond precision and values ranging from {@code 0000-01-01 00:00:00.000000} to
+	 * {@code 9999-12-31 23:59:59.999999}.
+	 *
+	 * <p>Compared to the SQL standard, leap seconds (23:59:60 and 23:59:61) are not supported as the
+	 * semantics are closer to {@link java.time.LocalDateTime}.
+	 *
+	 * @see #TIMESTAMP(int)
+	 * @see #TIMESTAMP_WITH_TIME_ZONE(int)
+	 * @see #TIMESTAMP_WITH_LOCAL_TIME_ZONE(int)
+	 * @see TimestampType
+	 */
+	public static DataType TIMESTAMP() {
+		return new AtomicDataType(new TimestampType());
+	}
+
+	/**
 	 * Data type of a timestamp WITH time zone {@code TIMESTAMP(p) WITH TIME ZONE} where {@code p} is
 	 * the number of digits of fractional seconds (=precision). {@code p} must have a value between 0
 	 * and 9 (both inclusive).
@@ -287,6 +324,26 @@ public final class DataTypes {
 	}
 
 	/**
+	 * Data type of a timestamp WITH time zone {@code TIMESTAMP WITH TIME ZONE} with 6 digits of fractional
+	 * seconds by default.
+	 *
+	 * <p>An instance consists of {@code year-month-day hour:minute:second[.fractional] zone} with up
+	 * to microsecond precision and values ranging from {@code 0000-01-01 00:00:00.000000 +14:59} to
+	 * {@code 9999-12-31 23:59:59.999999 -14:59}.
+	 *
+	 * <p>Compared to the SQL standard, leap seconds (23:59:60 and 23:59:61) are not supported as the
+	 * semantics are closer to {@link java.time.OffsetDateTime}.
+	 *
+	 * @see #TIMESTAMP_WITH_TIME_ZONE(int)
+	 * @see #TIMESTAMP(int)
+	 * @see #TIMESTAMP_WITH_LOCAL_TIME_ZONE(int)
+	 * @see ZonedTimestampType
+	 */
+	public static DataType TIMESTAMP_WITH_TIME_ZONE() {
+		return new AtomicDataType(new ZonedTimestampType());
+	}
+
+	/**
 	 * Data type of a timestamp WITH LOCAL time zone {@code TIMESTAMP(p) WITH LOCAL TIME ZONE} where
 	 * {@code p} is the number of digits of fractional seconds (=precision). {@code p} must have a value
 	 * between 0 and 9 (both inclusive).
@@ -313,6 +370,32 @@ public final class DataTypes {
 	}
 
 	/**
+	 * Data type of a timestamp WITH LOCAL time zone {@code TIMESTAMP WITH LOCAL TIME ZONE} with 6 digits
+	 * of fractional seconds by default.
+	 *
+	 * <p>An instance consists of {@code year-month-day hour:minute:second[.fractional] zone} with up
+	 * to microsecond precision and values ranging from {@code 0000-01-01 00:00:00.000000 +14:59} to
+	 * {@code 9999-12-31 23:59:59.999999 -14:59}. Leap seconds (23:59:60 and 23:59:61) are not supported
+	 * as the semantics are closer to {@link java.time.OffsetDateTime}.
+	 *
+	 * <p>Compared to {@link ZonedTimestampType}, the time zone offset information is not stored physically
+	 * in every datum. Instead, the type assumes {@link java.time.Instant} semantics in UTC time zone
+	 * at the edges of the table ecosystem. Every datum is interpreted in the local time zone configured
+	 * in the current session for computation and visualization.
+	 *
+	 * <p>This type fills the gap between time zone free and time zone mandatory timestamp types by
+	 * allowing the interpretation of UTC timestamps according to the configured session timezone.
+	 *
+	 * @see #TIMESTAMP_WITH_LOCAL_TIME_ZONE(int)
+	 * @see #TIMESTAMP(int)
+	 * @see #TIMESTAMP_WITH_TIME_ZONE(int)
+	 * @see LocalZonedTimestampType
+	 */
+	public static DataType TIMESTAMP_WITH_LOCAL_TIME_ZONE() {
+		return new AtomicDataType(new LocalZonedTimestampType());
+	}
+
+	/**
 	 * Data type of a temporal interval. There are two types of temporal intervals: day-time intervals
 	 * with up to nanosecond granularity or year-month intervals with up to month granularity.
 	 *
diff --git a/flink-table/flink-table-common/src/test/java/org/apache/flink/table/types/DataTypesTest.java b/flink-table/flink-table-common/src/test/java/org/apache/flink/table/types/DataTypesTest.java
index badfc9a..3945fb5 100644
--- a/flink-table/flink-table-common/src/test/java/org/apache/flink/table/types/DataTypesTest.java
+++ b/flink-table/flink-table-common/src/test/java/org/apache/flink/table/types/DataTypesTest.java
@@ -144,16 +144,28 @@ public class DataTypesTest {
 
 				{TIME(3), new TimeType(3), java.time.LocalTime.class},
 
+				{TIME(), new TimeType(0), java.time.LocalTime.class},
+
 				{TIMESTAMP(3), new TimestampType(3), java.time.LocalDateTime.class},
 
+				{TIMESTAMP(), new TimestampType(6), java.time.LocalDateTime.class},
+
 				{TIMESTAMP_WITH_TIME_ZONE(3),
 					new ZonedTimestampType(3),
 					java.time.OffsetDateTime.class},
 
+				{TIMESTAMP_WITH_TIME_ZONE(),
+					new ZonedTimestampType(6),
+					java.time.OffsetDateTime.class},
+
 				{TIMESTAMP_WITH_LOCAL_TIME_ZONE(3),
 					new LocalZonedTimestampType(3),
 					java.time.Instant.class},
 
+				{TIMESTAMP_WITH_LOCAL_TIME_ZONE(),
+					new LocalZonedTimestampType(6),
+					java.time.Instant.class},
+
 				{INTERVAL(MINUTE(), SECOND(3)),
 					new DayTimeIntervalType(MINUTE_TO_SECOND, DEFAULT_DAY_PRECISION, 3),
 					java.time.Duration.class},