commit fd2f7c85c84ad1f0a955325d886286d6eb515f16 Author: Vihang Karajgaonkar Date: Fri Mar 29 12:47:05 2019 -0700 HIVE-21484 : Metastore API getVersion() should return real version (Vihang Karajgaonkar, reviewed by Naveen Gangam and Peter Vary) diff --git a/itests/hive-unit/src/test/java/org/apache/hadoop/hive/metastore/TestHiveMetaStore.java b/itests/hive-unit/src/test/java/org/apache/hadoop/hive/metastore/TestHiveMetaStore.java index 8ba1b9a5b1ef0a6f1b4c69a0ec83964c06145f84..7e919ccc2cbaef911580b399b5b8f843c370f817 100644 --- a/itests/hive-unit/src/test/java/org/apache/hadoop/hive/metastore/TestHiveMetaStore.java +++ b/itests/hive-unit/src/test/java/org/apache/hadoop/hive/metastore/TestHiveMetaStore.java @@ -35,6 +35,7 @@ import junit.framework.TestCase; +import org.apache.hive.common.util.HiveVersionInfo; import org.datanucleus.api.jdo.JDOPersistenceManager; import org.datanucleus.api.jdo.JDOPersistenceManagerFactory; import org.slf4j.Logger; @@ -3265,6 +3266,11 @@ public void testDBLocationChange() throws IOException, TException { silentDropDatabase(dbName); } + @Test + public void testVersion() throws TException { + assertEquals(HiveVersionInfo.getVersion(), client.getServerVersion()); + } + private void checkDbOwnerType(String dbName, String ownerName, PrincipalType ownerType) throws NoSuchObjectException, MetaException, TException { Database db = client.getDatabase(dbName); diff --git a/metastore/src/java/org/apache/hadoop/hive/metastore/HiveMetaStore.java b/metastore/src/java/org/apache/hadoop/hive/metastore/HiveMetaStore.java index 813b8aae1338664854e055dd38fadcbb16143875..454b9408e859f30c61f83d0c32428728fcb23f6c 100644 --- a/metastore/src/java/org/apache/hadoop/hive/metastore/HiveMetaStore.java +++ b/metastore/src/java/org/apache/hadoop/hive/metastore/HiveMetaStore.java @@ -132,6 +132,7 @@ import org.apache.hadoop.util.ReflectionUtils; import org.apache.hadoop.util.StringUtils; import org.apache.hive.common.util.HiveStringUtils; +import org.apache.hive.common.util.HiveVersionInfo; import org.apache.hive.common.util.ShutdownHookManager; import org.apache.thrift.TException; import org.apache.thrift.TProcessor; @@ -3988,8 +3989,9 @@ public void alter_index(final String dbname, final String base_table_name, @Override public String getVersion() throws TException { - endFunction(startFunction("getVersion"), true, null); - return "3.0"; + String version = HiveVersionInfo.getVersion(); + endFunction(startFunction("getVersion"), version != null, null); + return version; } @Override diff --git a/metastore/src/java/org/apache/hadoop/hive/metastore/HiveMetaStoreClient.java b/metastore/src/java/org/apache/hadoop/hive/metastore/HiveMetaStoreClient.java index 83c2860413fa846b1c1dfa49ba96362231786188..6dc198fa84ca1fb922f25807102ac6eaa62068f8 100644 --- a/metastore/src/java/org/apache/hadoop/hive/metastore/HiveMetaStoreClient.java +++ b/metastore/src/java/org/apache/hadoop/hive/metastore/HiveMetaStoreClient.java @@ -2567,4 +2567,9 @@ public boolean cacheFileMetadata( CacheFileMetadataResult result = client.cache_file_metadata(req); return result.isIsSupported(); } + + @Override + public String getServerVersion() throws TException { + return client.getVersion(); + } } diff --git a/metastore/src/java/org/apache/hadoop/hive/metastore/IMetaStoreClient.java b/metastore/src/java/org/apache/hadoop/hive/metastore/IMetaStoreClient.java index a28c510c6449330befc91e2f95efb88ca09f47a2..fb17187f5b4b22b45faae1fe83d87b3131278352 100644 --- a/metastore/src/java/org/apache/hadoop/hive/metastore/IMetaStoreClient.java +++ b/metastore/src/java/org/apache/hadoop/hive/metastore/IMetaStoreClient.java @@ -1704,4 +1704,11 @@ void addPrimaryKey(List primaryKeyCols) throws void addForeignKey(List foreignKeyCols) throws MetaException, NoSuchObjectException, TException; + + /** + * Gets the version string of the metastore server which this client is connected to + * + * @return String representation of the version number of Metastore server (eg: 3.1.0-SNAPSHOT) + */ + String getServerVersion() throws TException; }