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

 ##########
 File path: 
flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/logical/utils/LogicalTypeChecks.java
 ##########
 @@ -0,0 +1,86 @@
+/*
+ * 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.types.logical.utils;
+
+import org.apache.flink.annotation.Internal;
+import org.apache.flink.table.types.logical.LocalZonedTimestampType;
+import org.apache.flink.table.types.logical.LogicalType;
+import org.apache.flink.table.types.logical.LogicalTypeFamily;
+import org.apache.flink.table.types.logical.LogicalTypeRoot;
+import org.apache.flink.table.types.logical.TimestampKind;
+import org.apache.flink.table.types.logical.TimestampType;
+import org.apache.flink.table.types.logical.ZonedTimestampType;
+
+/**
+ * Utilities for checking {@link LogicalType}.
+ */
+@Internal
+public final class LogicalTypeChecks {
+
+       private static final TimeAttributeChecker TIME_ATTRIBUTE_CHECKER = new 
TimeAttributeChecker();
+
+       public static boolean hasRoot(LogicalType logicalType, LogicalTypeRoot 
typeRoot) {
+               return logicalType.getTypeRoot() == typeRoot;
+       }
+
+       public static boolean hasFamily(LogicalType logicalType, 
LogicalTypeFamily family) {
+               return logicalType.getTypeRoot().getFamilies().contains(family);
+       }
+
+       public static boolean isTimeAttribute(LogicalType logicalType) {
+               return logicalType.accept(TIME_ATTRIBUTE_CHECKER) != 
TimestampKind.REGULAR;
+       }
+
+       public static boolean isRowtimeAttribute(LogicalType logicalType) {
+               return logicalType.accept(TIME_ATTRIBUTE_CHECKER) == 
TimestampKind.ROWTIME;
+       }
+
+       public static boolean isProctimeAttribute(LogicalType logicalType) {
+               return logicalType.accept(TIME_ATTRIBUTE_CHECKER) == 
TimestampKind.PROCTIME;
+       }
+
+       private LogicalTypeChecks() {
+               // no instantiation
+       }
+
+       // 
--------------------------------------------------------------------------------------------
+
+       private static class TimeAttributeChecker extends 
LogicalTypeDefaultVisitor<TimestampKind> {
+
+               @Override
+               public TimestampKind visit(TimestampType timestampType) {
+                       return timestampType.getKind();
+               }
+
+               @Override
+               public TimestampKind visit(ZonedTimestampType 
zonedTimestampType) {
+                       return zonedTimestampType.getKind();
+               }
+
+               @Override
+               public TimestampKind visit(LocalZonedTimestampType 
localZonedTimestampType) {
+                       return localZonedTimestampType.getKind();
+               }
+
+               @Override
+               protected TimestampKind defaultMethod(LogicalType logicalType) {
+                       return TimestampKind.REGULAR;
 
 Review comment:
   nit: Could we at least add a comment, that this does not mean that the 
`logicalType` is actually a *Timestamp? (This is really minor)
   

----------------------------------------------------------------
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:
[email protected]


With regards,
Apache Git Services

Reply via email to