You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by GitBox <gi...@apache.org> on 2019/05/28 09:26:07 UTC

[GitHub] [flink] dawidwys commented on a change in pull request #8555: [FLINK-12254][table-common] More preparation for using the new type system

dawidwys commented on a change in pull request #8555: [FLINK-12254][table-common] More preparation for using the new type system
URL: https://github.com/apache/flink/pull/8555#discussion_r287955235
 
 

 ##########
 File path: flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/logical/utils/LogicalTypeChecks.java
 ##########
 @@ -55,13 +75,158 @@ public static boolean isProctimeAttribute(LogicalType logicalType) {
 		return logicalType.accept(TIME_ATTRIBUTE_CHECKER) == TimestampKind.PROCTIME;
 	}
 
+	public static int getLength(LogicalType logicalType) {
+		return logicalType.accept(LENGTH_EXTRACTOR);
+	}
+
+	public static boolean hasLength(LogicalType logicalType, int length) {
+		return getLength(logicalType) == length;
+	}
+
+	public static int getPrecision(LogicalType logicalType) {
+		return logicalType.accept(PRECISION_EXTRACTOR);
+	}
+
+	public static boolean hasPrecision(LogicalType logicalType, int precision) {
+		return getPrecision(logicalType) == precision;
+	}
+
+	public static int getScale(LogicalType logicalType) {
+		return logicalType.accept(SCALE_EXTRACTOR);
+	}
+
+	public static boolean hasScale(LogicalType logicalType, int scale) {
+		return getScale(logicalType) == scale;
+	}
+
+	public static int getYearPrecision(LogicalType logicalType) {
+		return logicalType.accept(YEAR_PRECISION_EXTRACTOR);
+	}
+
+	public static boolean hasYearPrecision(LogicalType logicalType, int yearPrecision) {
+		return getYearPrecision(logicalType) == yearPrecision;
+	}
+
+	public static int getDayPrecision(LogicalType logicalType) {
+		return logicalType.accept(DAY_PRECISION_EXTRACTOR);
+	}
+
+	public static boolean hasDayPrecision(LogicalType logicalType, int yearPrecision) {
+		return getDayPrecision(logicalType) == yearPrecision;
+	}
+
+	public static int getFractionalPrecision(LogicalType logicalType) {
+		return logicalType.accept(FRACTIONAL_PRECISION_EXTRACTOR);
+	}
+
+	public static boolean hasFractionalPrecision(LogicalType logicalType, int fractionalPrecision) {
+		return getFractionalPrecision(logicalType) == fractionalPrecision;
+	}
+
 	private LogicalTypeChecks() {
 		// no instantiation
 	}
 
 	// --------------------------------------------------------------------------------------------
 
-	private static class TimeAttributeChecker extends LogicalTypeDefaultVisitor<TimestampKind> {
+	/**
+	 * Extracts an attribute of logical types that define that attribute.
+	 */
+	private static class Extractor<T> extends LogicalTypeDefaultVisitor<T> {
+		@Override
+		protected T defaultMethod(LogicalType logicalType) {
+			throw new UnsupportedOperationException(
 
 Review comment:
   nit: `IllegalArgumentException`, but I am also fine with `UnsupportedOperation`?

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services