vvysotskyi commented on a change in pull request #1826: DRILL-7272: Drill Metastore Read / Write API and Drill Iceberg Metastore implementation URL: https://github.com/apache/drill/pull/1826#discussion_r304574798
########## File path: metastore/metastore-api/src/main/java/org/apache/drill/metastore/MetastoreTableInfo.java ########## @@ -0,0 +1,118 @@ +/* + * 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.drill.metastore; + +import org.apache.drill.metastore.metadata.TableInfo; + +import java.util.Objects; +import java.util.StringJoiner; + +/** + * Holds metastore table information, including table information, exists status, + * last modified time and metastore version. + */ +public class MetastoreTableInfo { + + private final TableInfo tableInfo; + private final Long lastModifiedTime; + private final boolean exists; + private final long metastoreVersion; + + private MetastoreTableInfo(TableInfo tableInfo, Long lastModifiedTime, boolean exists, long metastoreVersion) { + this.tableInfo = tableInfo; + this.lastModifiedTime = lastModifiedTime; + this.exists = exists; + this.metastoreVersion = metastoreVersion; + } + + public static MetastoreTableInfo of(TableInfo tableInfo, MetadataUnit unit, long metastoreVersion) { + boolean exists = unit != null; + Long lastModifiedTime = exists ? unit.lastModifiedTime() : null; + return new MetastoreTableInfo(tableInfo, lastModifiedTime, exists, metastoreVersion); + } + + public TableInfo tableInfo() { + return tableInfo; + } + + public Long lastModifiedTime() { + return lastModifiedTime; + } + + public boolean isExists() { + return exists; + } + + public long metastoreVersion() { + return metastoreVersion; + } + + /** + * Checks if table metadata has changed or not, based on given exists status and last modified time. + * Checks are done based on the following rules and order: + * <ul> + * <li>If table did not exist but now does not, return true.</li> + * <li>If table existed but now does not, return true.</li> + * <li>If both last modified times are null, return false.</li> + * <li>If one last modified time is null and other is not, return true.</li> + * <li>If both last modified times are the same, return true.</li> Review comment: ```suggestion * <li>If both last modified times are the same, return false.</li> ``` ---------------------------------------------------------------- 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
