commit 220cc6f9740afa25571070c81b774f81cdae6ac0 Author: Vihang Karajgaonkar Date: Fri May 19 13:44:56 2017 -0700 HIVE-16723 : Enable configurable MetaStoreSchemaInfo diff --git beeline/src/java/org/apache/hive/beeline/HiveSchemaTool.java beeline/src/java/org/apache/hive/beeline/HiveSchemaTool.java index a45358077a07f09f07dd14eb028fb54b812e8a69..3d816872d920f625082f97afc3a851d28279680a 100644 --- beeline/src/java/org/apache/hive/beeline/HiveSchemaTool.java +++ beeline/src/java/org/apache/hive/beeline/HiveSchemaTool.java @@ -34,7 +34,9 @@ import org.apache.hadoop.hive.conf.HiveConf; import org.apache.hadoop.hive.conf.HiveConf.ConfVars; import org.apache.hadoop.hive.metastore.HiveMetaException; +import org.apache.hadoop.hive.metastore.IMetaStoreSchemaInfo; import org.apache.hadoop.hive.metastore.MetaStoreSchemaInfo; +import org.apache.hadoop.hive.metastore.MetaStoreSchemaInfoFactory; import org.apache.hadoop.hive.metastore.TableType; import org.apache.hadoop.hive.metastore.api.MetaException; import org.apache.hadoop.hive.shims.ShimLoader; @@ -78,7 +80,7 @@ private final HiveConf hiveConf; private final String dbType; private final String metaDbType; - private final MetaStoreSchemaInfo metaStoreSchemaInfo; + private final IMetaStoreSchemaInfo metaStoreSchemaInfo; static final private Logger LOG = LoggerFactory.getLogger(HiveSchemaTool.class.getName()); @@ -94,7 +96,7 @@ public HiveSchemaTool(String hiveHome, HiveConf hiveConf, String dbType, String this.hiveConf = hiveConf; this.dbType = dbType; this.metaDbType = metaDbType; - this.metaStoreSchemaInfo = new MetaStoreSchemaInfo(hiveHome, dbType); + this.metaStoreSchemaInfo = MetaStoreSchemaInfoFactory.get(hiveConf, hiveHome, dbType); } public HiveConf getHiveConf() { @@ -167,7 +169,7 @@ private NestedScriptParser getDbCommandParser(String dbType) { */ public void showInfo() throws HiveMetaException { Connection metastoreConn = getConnectionToMetastore(true); - String hiveVersion = MetaStoreSchemaInfo.getHiveSchemaVersion(); + String hiveVersion = metaStoreSchemaInfo.getHiveSchemaVersion(); String dbVersion = getMetaStoreSchemaVersion(metastoreConn); System.out.println("Hive distribution version:\t " + hiveVersion); System.out.println("Metastore schema version:\t " + dbVersion); @@ -499,13 +501,13 @@ public void verifySchemaVersion() throws HiveMetaException { String newSchemaVersion = getMetaStoreSchemaVersion( getConnectionToMetastore(false)); // verify that the new version is added to schema - assertCompatibleVersion(MetaStoreSchemaInfo.getHiveSchemaVersion(), newSchemaVersion); + assertCompatibleVersion(metaStoreSchemaInfo.getHiveSchemaVersion(), newSchemaVersion); } private void assertCompatibleVersion(String hiveSchemaVersion, String dbSchemaVersion) throws HiveMetaException { - if (!MetaStoreSchemaInfo.isVersionCompatible(hiveSchemaVersion, dbSchemaVersion)) { + if (!metaStoreSchemaInfo.isVersionCompatible(hiveSchemaVersion, dbSchemaVersion)) { throw new HiveMetaException("Metastore schema version is not compatible. Hive Version: " + hiveSchemaVersion + ", Database Schema Version: " + dbSchemaVersion); } @@ -533,7 +535,7 @@ public void doUpgrade() throws HiveMetaException { * @throws MetaException */ public void doUpgrade(String fromSchemaVer) throws HiveMetaException { - if (MetaStoreSchemaInfo.getHiveSchemaVersion().equals(fromSchemaVer)) { + if (metaStoreSchemaInfo.getHiveSchemaVersion().equals(fromSchemaVer)) { System.out.println("No schema upgrade required from version " + fromSchemaVer); return; } @@ -542,7 +544,7 @@ public void doUpgrade(String fromSchemaVer) throws HiveMetaException { metaStoreSchemaInfo.getUpgradeScripts(fromSchemaVer); testConnectionToMetastore(); System.out.println("Starting upgrade metastore schema from version " + - fromSchemaVer + " to " + MetaStoreSchemaInfo.getHiveSchemaVersion()); + fromSchemaVer + " to " + metaStoreSchemaInfo.getHiveSchemaVersion()); String scriptDir = metaStoreSchemaInfo.getMetaStoreScriptDir(); try { for (String scriptFile : upgradeScripts) { @@ -568,7 +570,7 @@ public void doUpgrade(String fromSchemaVer) throws HiveMetaException { * @throws MetaException */ public void doInit() throws HiveMetaException { - doInit(MetaStoreSchemaInfo.getHiveSchemaVersion()); + doInit(metaStoreSchemaInfo.getHiveSchemaVersion()); // Revalidated the new version after upgrade verifySchemaVersion(); @@ -715,7 +717,7 @@ boolean validateSchemaVersions(Connection conn) throws HiveMetaException { System.out.println("Validating schema version"); try { String newSchemaVersion = getMetaStoreSchemaVersion(conn, true); - assertCompatibleVersion(MetaStoreSchemaInfo.getHiveSchemaVersion(), newSchemaVersion); + assertCompatibleVersion(metaStoreSchemaInfo.getHiveSchemaVersion(), newSchemaVersion); } catch (HiveMetaException hme) { if (hme.getMessage().contains("Metastore schema version is not compatible") || hme.getMessage().contains("Multiple versions were found in metastore") @@ -927,7 +929,7 @@ boolean validateColumnNullValues(Connection conn) throws HiveMetaException { private void runPreUpgrade(String scriptDir, String scriptFile) { for (int i = 0;; i++) { String preUpgradeScript = - MetaStoreSchemaInfo.getPreUpgradeScriptName(i, scriptFile); + metaStoreSchemaInfo.getPreUpgradeScriptName(i, scriptFile); File preUpgradeScriptFile = new File(scriptDir, preUpgradeScript); if (!preUpgradeScriptFile.isFile()) { break; diff --git common/src/java/org/apache/hadoop/hive/conf/HiveConf.java common/src/java/org/apache/hadoop/hive/conf/HiveConf.java index 1c37b6e091cb02f5bf1a6a795712807b50d61424..deaed2c16648a198ecc58fe30a871b5f13dcc51f 100644 --- common/src/java/org/apache/hadoop/hive/conf/HiveConf.java +++ common/src/java/org/apache/hadoop/hive/conf/HiveConf.java @@ -777,6 +777,9 @@ private static void populateLlapDaemonVarsSet(Set llapDaemonVarsSetLocal METASTORE_SCHEMA_VERIFICATION_RECORD_VERSION("hive.metastore.schema.verification.record.version", false, "When true the current MS version is recorded in the VERSION table. If this is disabled and verification is\n" + " enabled the MS will be unusable."), + METASTORE_SCHEMA_INFO_CLASS("hive.metastore.schema.info.class", "org.apache.hadoop.hive.metastore.MetaStoreSchemaInfo", + "Fully qualified class name for the metastore schema information class which is used by \n" + + "schematool to fetch the schema information. This class should implement the IMetaStoreSchemaInfo interface"), METASTORE_TRANSACTION_ISOLATION("datanucleus.transactionIsolation", "read-committed", "Default transaction isolation level for identity generation."), METASTORE_CACHE_LEVEL2("datanucleus.cache.level2", false, diff --git itests/hive-unit/src/test/java/org/apache/hadoop/hive/metastore/TestMetastoreVersion.java itests/hive-unit/src/test/java/org/apache/hadoop/hive/metastore/TestMetastoreVersion.java index 7188af62acb3cb0305e2cdaf9727576d61418013..0a034d3593468b1704769fa2b0fde2330d61b546 100644 --- itests/hive-unit/src/test/java/org/apache/hadoop/hive/metastore/TestMetastoreVersion.java +++ itests/hive-unit/src/test/java/org/apache/hadoop/hive/metastore/TestMetastoreVersion.java @@ -41,6 +41,7 @@ private Driver driver; private String metaStoreRoot; private String testMetastoreDB; + private IMetaStoreSchemaInfo metastoreSchemaInfo; @Override protected void setUp() throws Exception { @@ -63,6 +64,8 @@ protected void setUp() throws Exception { System.setProperty(HiveConf.ConfVars.METASTORECONNECTURLKEY.varname, "jdbc:derby:" + testMetastoreDB + ";create=true"); metaStoreRoot = System.getProperty("test.tmp.dir"); + metastoreSchemaInfo = MetaStoreSchemaInfoFactory.get(hiveConf, + System.getProperty("test.tmp.dir", "target/tmp"), "derby"); } @Override @@ -121,7 +124,7 @@ public void testMetastoreVersion () throws Exception { driver.run("show tables"); // correct version stored by Metastore during startup - assertEquals(MetaStoreSchemaInfo.getHiveSchemaVersion(), getVersion(hiveConf)); + assertEquals(metastoreSchemaInfo.getHiveSchemaVersion(), getVersion(hiveConf)); setVersion(hiveConf, "foo"); assertEquals("foo", getVersion(hiveConf)); } @@ -139,7 +142,7 @@ public void testVersionMatching () throws Exception { ObjectStore.setSchemaVerified(false); hiveConf.setBoolVar(HiveConf.ConfVars.METASTORE_SCHEMA_VERIFICATION, true); - setVersion(hiveConf, MetaStoreSchemaInfo.getHiveSchemaVersion()); + setVersion(hiveConf, metastoreSchemaInfo.getHiveSchemaVersion()); driver = new Driver(hiveConf); CommandProcessorResponse proc = driver.run("show tables"); assertTrue(proc.getResponseCode() == 0); @@ -189,13 +192,11 @@ public void testVersionCompatibility () throws Exception { // write the given version to metastore private String getVersion(HiveConf conf) throws HiveMetaException { - MetaStoreSchemaInfo schemInfo = new MetaStoreSchemaInfo(metaStoreRoot, "derby"); return getMetaStoreVersion(); } // write the given version to metastore private void setVersion(HiveConf conf, String version) throws HiveMetaException { - MetaStoreSchemaInfo schemInfo = new MetaStoreSchemaInfo(metaStoreRoot, "derby"); setMetaStoreVersion(version, "setVersion test"); } diff --git itests/hive-unit/src/test/java/org/apache/hive/beeline/TestSchemaTool.java itests/hive-unit/src/test/java/org/apache/hive/beeline/TestSchemaTool.java index 438a7d6dc86cb291d7d0a9b4501a9df07f1934d7..3e1650bdeba863d5bba275a293872f64c8043cc4 100644 --- itests/hive-unit/src/test/java/org/apache/hive/beeline/TestSchemaTool.java +++ itests/hive-unit/src/test/java/org/apache/hive/beeline/TestSchemaTool.java @@ -35,7 +35,9 @@ import org.apache.commons.lang.StringUtils; import org.apache.hadoop.hive.conf.HiveConf; import org.apache.hadoop.hive.metastore.HiveMetaException; +import org.apache.hadoop.hive.metastore.IMetaStoreSchemaInfo; import org.apache.hadoop.hive.metastore.MetaStoreSchemaInfo; +import org.apache.hadoop.hive.metastore.MetaStoreSchemaInfoFactory; import org.apache.hadoop.hive.shims.ShimLoader; import org.apache.hive.beeline.HiveSchemaHelper.NestedScriptParser; import org.apache.hive.beeline.HiveSchemaHelper.PostgresCommandParser; @@ -219,7 +221,9 @@ public void testSchemaUpgradeDryRun() throws Exception { * @throws Exception */ public void testSchemaInit() throws Exception { - schemaTool.doInit(MetaStoreSchemaInfo.getHiveSchemaVersion()); + IMetaStoreSchemaInfo metastoreSchemaInfo = MetaStoreSchemaInfoFactory.get(hiveConf, + System.getProperty("test.tmp.dir", "target/tmp"), "derby"); + schemaTool.doInit(metastoreSchemaInfo.getHiveSchemaVersion()); schemaTool.verifySchemaVersion(); } diff --git metastore/src/java/org/apache/hadoop/hive/metastore/IMetaStoreSchemaInfo.java metastore/src/java/org/apache/hadoop/hive/metastore/IMetaStoreSchemaInfo.java new file mode 100644 index 0000000000000000000000000000000000000000..b714bf3eba84930424eccfe2021462b40199b36d --- /dev/null +++ metastore/src/java/org/apache/hadoop/hive/metastore/IMetaStoreSchemaInfo.java @@ -0,0 +1,55 @@ +/** + * 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; + +import java.util.List; + +public interface IMetaStoreSchemaInfo { + static String SQL_FILE_EXTENSION = ".sql"; + + /*** + * Get the list of sql scripts required to upgrade from the give version to current + * + * @param fromVersion + * @return + * @throws HiveMetaException + */ + List getUpgradeScripts(String fromVersion) throws HiveMetaException; + + /*** + * Get the name of the script to initialize the schema for given version + * + * @param toVersion Target version. If it's null, then the current server version is used + * @return + * @throws HiveMetaException + */ + String generateInitFileName(String toVersion) throws HiveMetaException; + + /** + * Find the directory of metastore scripts + * + * @return the path of directory where the sql scripts are + */ + String getMetaStoreScriptDir(); + + String getPreUpgradeScriptName(int index, String scriptName); + + String getHiveSchemaVersion(); + + boolean isVersionCompatible(String productVersion, String dbVersion); +} \ No newline at end of file diff --git metastore/src/java/org/apache/hadoop/hive/metastore/MetaStoreSchemaInfo.java metastore/src/java/org/apache/hadoop/hive/metastore/MetaStoreSchemaInfo.java index 320902bed5fc49323d2b372354fe28d38358459e..09ef04ab68d05d9b65aa40df7987c5a334ad564d 100644 --- metastore/src/java/org/apache/hadoop/hive/metastore/MetaStoreSchemaInfo.java +++ metastore/src/java/org/apache/hadoop/hive/metastore/MetaStoreSchemaInfo.java @@ -31,14 +31,13 @@ import com.google.common.collect.ImmutableMap; -public class MetaStoreSchemaInfo { - private static final String SQL_FILE_EXTENSION = ".sql"; - private static final String UPGRADE_FILE_PREFIX = "upgrade-"; +public class MetaStoreSchemaInfo implements IMetaStoreSchemaInfo { + protected static final String UPGRADE_FILE_PREFIX = "upgrade-"; private static final String INIT_FILE_PREFIX = "hive-schema-"; private static final String VERSION_UPGRADE_LIST = "upgrade.order"; private static final String PRE_UPGRADE_PREFIX = "pre-"; - private final String dbType; - private final String hiveSchemaVersions[]; + protected final String dbType; + private String hiveSchemaVersions[]; private final String hiveHome; // Some version upgrades often don't change schema. So they are equivalent to @@ -55,6 +54,9 @@ public MetaStoreSchemaInfo(String hiveHome, String dbType) throws HiveMetaException { this.hiveHome = hiveHome; this.dbType = dbType; + } + + private void loadAllUpgradeScripts(String dbType) throws HiveMetaException { // load upgrade order for the given dbType List upgradeOrderList = new ArrayList(); String upgradeListFile = getMetaStoreScriptDir() + File.separator + @@ -79,6 +81,7 @@ public MetaStoreSchemaInfo(String hiveHome, String dbType) throws HiveMetaExcept * @return * @throws HiveMetaException */ + @Override public List getUpgradeScripts(String fromVersion) throws HiveMetaException { List upgradeScriptList = new ArrayList(); @@ -87,6 +90,7 @@ public MetaStoreSchemaInfo(String hiveHome, String dbType) throws HiveMetaExcept if (getHiveSchemaVersion().equals(fromVersion)) { return upgradeScriptList; } + loadAllUpgradeScripts(dbType); // Find the list of scripts to execute for this upgrade int firstScript = hiveSchemaVersions.length; for (int i=0; i < hiveSchemaVersions.length; i++) { @@ -112,6 +116,7 @@ public MetaStoreSchemaInfo(String hiveHome, String dbType) throws HiveMetaExcept * @return * @throws HiveMetaException */ + @Override public String generateInitFileName(String toVersion) throws HiveMetaException { if (toVersion == null) { toVersion = getHiveSchemaVersion(); @@ -130,6 +135,7 @@ public String generateInitFileName(String toVersion) throws HiveMetaException { * Find the directory of metastore scripts * @return */ + @Override public String getMetaStoreScriptDir() { return hiveHome + File.separatorChar + "scripts" + File.separatorChar + "metastore" + @@ -141,11 +147,13 @@ private String generateUpgradeFileName(String fileVersion) { return UPGRADE_FILE_PREFIX + fileVersion + "." + dbType + SQL_FILE_EXTENSION; } - public static String getPreUpgradeScriptName(int index, String upgradeScriptName) { + @Override + public String getPreUpgradeScriptName(int index, String upgradeScriptName) { return PRE_UPGRADE_PREFIX + index + "-" + upgradeScriptName; } - public static String getHiveSchemaVersion() { + @Override + public String getHiveSchemaVersion() { String hiveVersion = HiveVersionInfo.getShortVersion(); return getEquivalentVersion(hiveVersion); } @@ -174,7 +182,8 @@ private static String getEquivalentVersion(String hiveVersion) { * version of metastore rdbms schema * @return true if versions are compatible */ - public static boolean isVersionCompatible(String hiveVersion, String dbVersion) { + @Override + public boolean isVersionCompatible(String hiveVersion, String dbVersion) { hiveVersion = getEquivalentVersion(hiveVersion); dbVersion = getEquivalentVersion(dbVersion); if (hiveVersion.equals(dbVersion)) { diff --git metastore/src/java/org/apache/hadoop/hive/metastore/MetaStoreSchemaInfoFactory.java metastore/src/java/org/apache/hadoop/hive/metastore/MetaStoreSchemaInfoFactory.java new file mode 100644 index 0000000000000000000000000000000000000000..088af08d1e0ca5ea0b3fafc24e43a9ce2042d9b4 --- /dev/null +++ metastore/src/java/org/apache/hadoop/hive/metastore/MetaStoreSchemaInfoFactory.java @@ -0,0 +1,62 @@ +/** + * 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; + +import java.lang.reflect.Constructor; +import java.lang.reflect.InvocationTargetException; + +import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.hive.conf.HiveConf; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class MetaStoreSchemaInfoFactory { + public static final Logger LOG = LoggerFactory.getLogger(MetaStoreSchemaInfoFactory.class); + + public static IMetaStoreSchemaInfo get(Configuration conf) { + String hiveHome = System.getenv("HIVE_HOME"); + if (hiveHome == null) { + LOG.debug("HIVE_HOME is not set. Using current directory instead"); + hiveHome = "."; + } + return get(conf, hiveHome, null); + } + + public static IMetaStoreSchemaInfo get(Configuration conf, String hiveHome, String dbType) { + String className = null; + className = conf.get(HiveConf.ConfVars.METASTORE_SCHEMA_INFO_CLASS.varname, + HiveConf.ConfVars.METASTORE_SCHEMA_INFO_CLASS.defaultStrVal); + Class clasz = null; + try { + clasz = conf.getClassByName(className); + } catch (ClassNotFoundException e) { + LOG.error("Unable to load class " + className, e); + throw new IllegalArgumentException(e); + } + Constructor constructor = null; + try { + constructor = clasz.getConstructor(String.class, String.class); + constructor.setAccessible(true); + return (IMetaStoreSchemaInfo) constructor.newInstance(hiveHome, dbType); + } catch (NoSuchMethodException | InstantiationException | IllegalAccessException + | IllegalArgumentException | InvocationTargetException e) { + LOG.error("Unable to create instance of class " + className, e); + throw new IllegalArgumentException(e); + } + } +} diff --git metastore/src/java/org/apache/hadoop/hive/metastore/ObjectStore.java metastore/src/java/org/apache/hadoop/hive/metastore/ObjectStore.java index b28983f7a9e36832d643c8a2293e19665dd79528..fac3c2906d678af6a2cfa9026cf97c844d95a4a0 100644 --- metastore/src/java/org/apache/hadoop/hive/metastore/ObjectStore.java +++ metastore/src/java/org/apache/hadoop/hive/metastore/ObjectStore.java @@ -7671,7 +7671,8 @@ private synchronized void checkSchema() throws MetaException { // read the schema version stored in metastore db String dbSchemaVer = getMetaStoreSchemaVersion(); // version of schema for this version of hive - String hiveSchemaVer = MetaStoreSchemaInfo.getHiveSchemaVersion(); + IMetaStoreSchemaInfo metastoreSchemaInfo = MetaStoreSchemaInfoFactory.get(getConf()); + String hiveSchemaVer = metastoreSchemaInfo.getHiveSchemaVersion(); if (dbSchemaVer == null) { if (strictValidation) { @@ -7685,7 +7686,7 @@ private synchronized void checkSchema() throws MetaException { "Set by MetaStore " + USER + "@" + HOSTNAME); } } else { - if (MetaStoreSchemaInfo.isVersionCompatible(hiveSchemaVer, dbSchemaVer)) { + if (metastoreSchemaInfo.isVersionCompatible(hiveSchemaVer, dbSchemaVer)) { LOG.debug("Found expected HMS version of " + dbSchemaVer); } else { // metastore schema version is different than Hive distribution needs @@ -7734,7 +7735,7 @@ private MVersionTable getMSchemaVersion() throws NoSuchObjectException, MetaExce } catch (JDODataStoreException e) { if (e.getCause() instanceof MissingTableException) { throw new MetaException("Version table not found. " + "The metastore is not upgraded to " - + MetaStoreSchemaInfo.getHiveSchemaVersion()); + + MetaStoreSchemaInfoFactory.get(getConf()).getHiveSchemaVersion()); } else { throw MetaStoreUtils.newMetaException(e); } diff --git metastore/src/test/org/apache/hadoop/hive/metastore/TestMetaStoreSchemaFactory.java metastore/src/test/org/apache/hadoop/hive/metastore/TestMetaStoreSchemaFactory.java new file mode 100644 index 0000000000000000000000000000000000000000..93986fada17deb69d783791ab4aa2496b707112a --- /dev/null +++ metastore/src/test/org/apache/hadoop/hive/metastore/TestMetaStoreSchemaFactory.java @@ -0,0 +1,48 @@ +/** + * 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; + +import org.apache.hadoop.hive.conf.HiveConf; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +public class TestMetaStoreSchemaFactory { + private HiveConf conf; + + @Before + public void setup() { + conf = new HiveConf(this.getClass()); + } + + @Test + public void testDefaultConfig() { + IMetaStoreSchemaInfo metastoreSchemaInfo = MetaStoreSchemaInfoFactory.get(conf); + Assert.assertNotNull(metastoreSchemaInfo); + } + + @Test + public void testWithConfigSet() { + conf.set(HiveConf.ConfVars.METASTORE_SCHEMA_INFO_CLASS.varname, + MetaStoreSchemaInfo.class.getCanonicalName()); + IMetaStoreSchemaInfo metastoreSchemaInfo = MetaStoreSchemaInfoFactory.get(conf); + Assert.assertNotNull(metastoreSchemaInfo); + Assert.assertTrue("Unexpected instance type of the class MetaStoreSchemaInfo", + metastoreSchemaInfo instanceof MetaStoreSchemaInfo); + } +} diff --git metastore/src/test/org/apache/hadoop/hive/metastore/TestMetaStoreSchemaInfo.java metastore/src/test/org/apache/hadoop/hive/metastore/TestMetaStoreSchemaInfo.java index 71420012756ca26bf399228efdf011597eb70b17..35e862f10aaa3444a5a318e634dfadf86b66a79f 100644 --- metastore/src/test/org/apache/hadoop/hive/metastore/TestMetaStoreSchemaInfo.java +++ metastore/src/test/org/apache/hadoop/hive/metastore/TestMetaStoreSchemaInfo.java @@ -18,6 +18,7 @@ package org.apache.hadoop.hive.metastore; +import org.apache.hadoop.hive.conf.HiveConf; import org.junit.Assert; import org.junit.Test; @@ -31,18 +32,20 @@ public void testIsVersionCompatible() throws Exception { // first argument is hiveVersion, it is compatible if 2nd argument - dbVersion is // greater than or equal to it // check the compatible case - Assert.assertTrue(MetaStoreSchemaInfo.isVersionCompatible("0.0.1", "0.0.1")); - Assert.assertTrue(MetaStoreSchemaInfo.isVersionCompatible("0.0.1", "0.0.2")); - Assert.assertTrue(MetaStoreSchemaInfo.isVersionCompatible("1.0.2", "2.0.1")); - Assert.assertTrue(MetaStoreSchemaInfo.isVersionCompatible("0.0.9", "9.0.0")); + IMetaStoreSchemaInfo metastoreSchemaInfo = + MetaStoreSchemaInfoFactory.get(new HiveConf(TestMetaStoreSchemaInfo.class)); + Assert.assertTrue(metastoreSchemaInfo.isVersionCompatible("0.0.1", "0.0.1")); + Assert.assertTrue(metastoreSchemaInfo.isVersionCompatible("0.0.1", "0.0.2")); + Assert.assertTrue(metastoreSchemaInfo.isVersionCompatible("1.0.2", "2.0.1")); + Assert.assertTrue(metastoreSchemaInfo.isVersionCompatible("0.0.9", "9.0.0")); // check equivalent versions, should be compatible - Assert.assertTrue(MetaStoreSchemaInfo.isVersionCompatible("0.13.0", "0.13.1")); - Assert.assertTrue(MetaStoreSchemaInfo.isVersionCompatible("0.13.1", "0.13.0")); + Assert.assertTrue(metastoreSchemaInfo.isVersionCompatible("0.13.0", "0.13.1")); + Assert.assertTrue(metastoreSchemaInfo.isVersionCompatible("0.13.1", "0.13.0")); // check incompatible versions - Assert.assertFalse(MetaStoreSchemaInfo.isVersionCompatible("0.1.1", "0.1.0")); - Assert.assertFalse(MetaStoreSchemaInfo.isVersionCompatible("4.0.1", "0.1.0")); + Assert.assertFalse(metastoreSchemaInfo.isVersionCompatible("0.1.1", "0.1.0")); + Assert.assertFalse(metastoreSchemaInfo.isVersionCompatible("4.0.1", "0.1.0")); }