veghlaci05 commented on code in PR #4060:
URL: https://github.com/apache/hive/pull/4060#discussion_r1221446510


##########
beeline/src/java/org/apache/hive/beeline/schematool/tasks/HiveSchemaInfo.java:
##########
@@ -0,0 +1,170 @@
+/*
+ * 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.hive.beeline.schematool.tasks;
+
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.hive.metastore.HiveMetaException;
+import org.apache.hadoop.hive.metastore.SchemaInfo;
+import org.apache.hadoop.hive.metastore.tools.schematool.HiveSchemaHelper;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileReader;
+import java.io.IOException;
+import java.sql.Connection;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.ArrayList;
+import java.util.List;
+
+class HiveSchemaInfo extends SchemaInfo {
+
+  private static final Logger LOG = 
LoggerFactory.getLogger(HiveSchemaInfo.class);
+  private static final String UPGRADE_FILE_PREFIX = "upgrade-";
+  protected static final String VERSION_UPGRADE_LIST = "upgrade.order";
+  protected static final String INITIAL_VERSION = "0.0.0";
+
+  String[] hiveSchemaVersions = null;
+
+  @Override
+  public List<String> getUnappliedScripts() throws HiveMetaException {
+    if (hiveSchemaVersions == null) {
+      loadAllUpgradeScripts();
+    }
+    String schemaVersion = INITIAL_VERSION;
+    try {
+      schemaVersion = getSchemaVersion();
+    } catch (HiveMetaException e) {
+      if (e.getMessage().startsWith("Failed to get schema version")) {
+        LOG.warn("Unable to get schema version, assuming it's an empty 
schema.");
+      } else throw e;
+    }
+    List <String> upgradeScriptList = new ArrayList<>();
+
+    // check if we are already at the required schema level
+    if (isVersionCompatible(getRequiredHiveSchemaVersion(), schemaVersion)) {
+      return upgradeScriptList;
+    }
+
+    // Find the list of scripts to execute for this upgrade
+    int firstScript = -1;
+    for (int i=0; i < hiveSchemaVersions.length; i++) {
+      if (hiveSchemaVersions[i].startsWith(schemaVersion + "-to-")) {
+        firstScript = i;
+      }
+    }
+    if (firstScript == -1) {
+      throw new HiveMetaException("Unknown version specified for upgrade " + 
schemaVersion + " Metastore schema may be too old or newer");

Review Comment:
   Good point, this is no longer valid. Removed.



-- 
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.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to