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 d7d24425e47408eb094b7f5aa6ecfcffd7f89db7
Author: Timo Walther <twal...@apache.org>
AuthorDate: Tue May 21 14:42:02 2019 +0200

    [hotfix][table-common] Add logical type check utilities
---
 .../types/logical/utils/LogicalTypeChecks.java     | 87 ++++++++++++++++++++++
 1 file changed, 87 insertions(+)

diff --git 
a/flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/logical/utils/LogicalTypeChecks.java
 
b/flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/logical/utils/LogicalTypeChecks.java
new file mode 100644
index 0000000..3958922
--- /dev/null
+++ 
b/flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/logical/utils/LogicalTypeChecks.java
@@ -0,0 +1,87 @@
+/*
+ * 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) {
+                       // we don't verify that type is actually a timestamp
+                       return TimestampKind.REGULAR;
+               }
+       }
+}

Reply via email to