Aggarwal-Raghav commented on code in PR #6992:
URL: https://github.com/apache/hive/pull/6992#discussion_r4753020615


##########
itests/hive-unit/src/test/java/org/apache/hadoop/hive/metastore/tools/schematool/TestHiveSchemaToolUpgrade.java:
##########
@@ -0,0 +1,416 @@
+/*
+ * 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.hadoop.hive.metastore.tools.schematool;
+
+import java.io.File;
+import java.sql.DriverManager;
+import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.TreeMap;
+import java.util.TreeSet;
+
+import org.apache.commons.cli.Option;
+import org.apache.commons.cli.OptionGroup;
+import org.apache.commons.collections4.MapUtils;
+import org.apache.commons.collections4.SetUtils;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.hadoop.hive.conf.HiveConf;
+import org.apache.hadoop.hive.metastore.HiveMetaStoreClient;
+import org.apache.hadoop.hive.metastore.IMetaStoreClient;
+import org.apache.hadoop.hive.metastore.IMetaStoreSchemaInfo;
+import org.apache.hadoop.hive.metastore.ObjectStore;
+import org.apache.hadoop.hive.metastore.api.FieldSchema;
+import org.apache.hadoop.hive.metastore.api.GetTableRequest;
+import org.apache.hadoop.hive.metastore.api.PrimaryKeysRequest;
+import org.apache.hadoop.hive.metastore.api.SQLPrimaryKey;
+import org.apache.hadoop.hive.metastore.api.SerDeInfo;
+import org.apache.hadoop.hive.metastore.api.StorageDescriptor;
+import org.apache.hadoop.hive.metastore.api.Table;
+import org.apache.hadoop.hive.metastore.api.hive_metastoreConstants;
+import org.apache.hadoop.hive.metastore.conf.MetastoreConf;
+import org.apache.hadoop.hive.metastore.utils.MetaStoreUtils;
+import org.apache.hadoop.hive.ql.metadata.Hive;
+import org.apache.hive.beeline.schematool.HiveSchemaTool;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
+
+/**
+ * End-to-end regression tests for Hive SYSDB schema upgrades executed via 
{@link HiveSchemaTool}.
+ * Compares upgraded metastore schemas across all databases against a clean 
{@link HiveSchemaTool}
+ * initialization of the target version, using isolated Derby metastore 
instances initialized by
+ * {@link MetastoreSchemaTool}.
+ */
+public class TestHiveSchemaToolUpgrade {
+
+  // 
---------------------------------------------------------------------------
+  // Constants & JUnit Lifecycle
+  // 
---------------------------------------------------------------------------
+
+  // Maven (itests/hive-unit setup-metastore-scripts) copies SQL scripts into 
${test.tmp.dir}.
+  private static final String METASTORE_HOME = 
System.getProperty("test.tmp.dir", "target/tmp");
+  private static final String HIVE_SQL_QUERY_PARAM = "hive.sql.query";
+
+  @Rule
+  public final TemporaryFolder tempDir = 
TemporaryFolder.builder().assureDeletion().build();
+
+  private final Map<String, String> savedProperties = new HashMap<>();
+  private final List<String> derbyUrls = new ArrayList<>();
+
+  @Before
+  public void setUp() throws Exception {
+    resetStaticMetastoreState();
+    File protoBaseDir = tempDir.newFolder("proto_events");
+
+    // hive-site.xml in itests enables autoCreateAll and disables schema 
verification;
+    // enforce SchemaTool ownership of all DDL.
+    setTrackedProperty(MetastoreConf.ConfVars.AUTO_CREATE_ALL.getHiveName(), 
"false");
+    
setTrackedProperty(MetastoreConf.ConfVars.SCHEMA_VERIFICATION.getHiveName(), 
"true");
+    setTrackedProperty(
+        HiveConf.ConfVars.HIVE_PROTO_EVENTS_BASE_PATH.varname, 
protoBaseDir.getAbsolutePath());
+  }
+
+  @After
+  public void tearDown() {
+    try {
+      savedProperties.forEach((key, value) -> {
+        if (value == null) {
+          System.clearProperty(key);
+        } else {
+          System.setProperty(key, value);
+        }
+      });
+      resetStaticMetastoreState();
+    } finally {
+      shutdownDerbyDatabases();
+    }
+  }
+
+  // 
---------------------------------------------------------------------------
+  // Unit Tests
+  // 
---------------------------------------------------------------------------
+
+  /**
+   * Regression test for HIVE-30285: upgrading Hive SYSDB from 4.1.0 to 4.2.0 
must update
+   * SYS.VERSION to 4.2.0, match all databases/tables/views of a fresh 4.2.0 
install, and avoid
+   * leaking objects into default or new databases.
+   */
+  @Test
+  public void testUpgrade410To420OnHiveDbType() throws Exception {
+    verifyUpgrade("4.1.0", "4.2.0");
+  }
+
+  /**
+   * Verifies multi-hop Hive SYSDB upgrade chaining from 4.0.0 through 4.2.0 
via
+   * upgrade.order.hive matches a fresh 4.2.0 installation.
+   */
+  @Test
+  public void testUpgrade400To420OnHiveDbType() throws Exception {
+    verifyUpgrade("4.0.0", "4.2.0");

Review Comment:
   @dengzhhu653 , I had the same thought on how to keep the test relevant for 
future when next schema version comes.
   
   Reason:
   1. There is another PR #6993  for `4.2.0 -> 4.3.0` fix. I'll update the UT 
there. **I raised 2 separate PR thinking it should be complete backportable to 
branch-4.2**
   2. As you mentioned will get rid of 2nd arg in next PR. I have code ready 
for that :-) , just waiting for this to be merged.
   ```java
   @Test
         public void testUpgrade400ToCurrentOnHiveDbType() throws Exception {
           verifyUpgrade("4.0.0");
         }
   
         private void verifyUpgrade(String fromVersion) throws Exception {
           String currentVersion = MetaStoreSchemaInfoFactory
               .get(new HiveConf(TestHiveSchemaToolUpgrade.class), 
METASTORE_HOME, HiveSchemaHelper.DB_HIVE)
               .getHiveSchemaVersion();
           verifyUpgrade(fromVersion, currentVersion);
   ```
   3. If I make that change now, the 4.2.0 -> 4.3.0 will fail.



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