You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hive.apache.org by ct...@apache.org on 2016/12/05 13:25:30 UTC
hive git commit: HIVE-15074: Schematool provides a way to detect
invalid entries in VERSION table (Chaoyu Tang, reviewed by Aihua Xu,
Naveen Gangam)
Repository: hive
Updated Branches:
refs/heads/master c4380fae1 -> a40122323
HIVE-15074: Schematool provides a way to detect invalid entries in VERSION table (Chaoyu Tang, reviewed by Aihua Xu, Naveen Gangam)
Project: http://git-wip-us.apache.org/repos/asf/hive/repo
Commit: http://git-wip-us.apache.org/repos/asf/hive/commit/a4012232
Tree: http://git-wip-us.apache.org/repos/asf/hive/tree/a4012232
Diff: http://git-wip-us.apache.org/repos/asf/hive/diff/a4012232
Branch: refs/heads/master
Commit: a401223230174997cc6f66bde49859bbe02379b9
Parents: c4380fa
Author: Chaoyu Tang <ct...@apache.org>
Authored: Mon Dec 5 08:25:22 2016 -0500
Committer: Chaoyu Tang <ct...@apache.org>
Committed: Mon Dec 5 08:25:22 2016 -0500
----------------------------------------------------------------------
.../org/apache/hive/beeline/HiveSchemaTool.java | 31 ++++++++++++++++-
.../org/apache/hive/beeline/TestSchemaTool.java | 36 +++++++++++++++++++-
2 files changed, 65 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/hive/blob/a4012232/beeline/src/java/org/apache/hive/beeline/HiveSchemaTool.java
----------------------------------------------------------------------
diff --git a/beeline/src/java/org/apache/hive/beeline/HiveSchemaTool.java b/beeline/src/java/org/apache/hive/beeline/HiveSchemaTool.java
index 23f3cf2..88b6b2b 100644
--- a/beeline/src/java/org/apache/hive/beeline/HiveSchemaTool.java
+++ b/beeline/src/java/org/apache/hive/beeline/HiveSchemaTool.java
@@ -152,9 +152,14 @@ public class HiveSchemaTool {
}
- // read schema version from metastore
private String getMetaStoreSchemaVersion(Connection metastoreConn)
throws HiveMetaException {
+ return getMetaStoreSchemaVersion(metastoreConn, false);
+ }
+
+ // read schema version from metastore
+ private String getMetaStoreSchemaVersion(Connection metastoreConn,
+ boolean checkDuplicatedVersion) throws HiveMetaException {
String versionQuery;
if (getDbCommandParser(dbType).needsQuotedIdentifier()) {
versionQuery = "select t.\"SCHEMA_VERSION\" from \"VERSION\" t";
@@ -167,6 +172,9 @@ public class HiveSchemaTool {
throw new HiveMetaException("Didn't find version data in metastore");
}
String currentSchemaVersion = res.getString(1);
+ if (checkDuplicatedVersion && res.next()) {
+ throw new HiveMetaException("Multiple versions were found in metastore.");
+ }
return currentSchemaVersion;
} catch (SQLException e) {
throw new HiveMetaException("Failed to get schema version.", e);
@@ -575,6 +583,7 @@ public class HiveSchemaTool {
public void doValidate() throws HiveMetaException {
System.out.print("Starting metastore validation");
+ validateSchemaVersions();
validateSequences();
validateSchemaTables();
validateLocations(null);
@@ -643,6 +652,26 @@ public class HiveSchemaTool {
}
}
+ boolean validateSchemaVersions() throws HiveMetaException {
+ System.out.println("Validating schema version");
+ try {
+ String newSchemaVersion = getMetaStoreSchemaVersion(
+ getConnectionToMetastore(false), true);
+ 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")
+ || hme.getMessage().contains("Didn't find version data in metastore")) {
+ System.out.println("Failed in schema version validation: " + hme.getMessage());
+ return false;
+ } else {
+ throw hme;
+ }
+ }
+ System.out.println("Succeeded in schema version validation.");
+ return true;
+ }
+
boolean validateSchemaTables() throws HiveMetaException {
ResultSet rs = null;
DatabaseMetaData metadata = null;
http://git-wip-us.apache.org/repos/asf/hive/blob/a4012232/itests/hive-unit/src/test/java/org/apache/hive/beeline/TestSchemaTool.java
----------------------------------------------------------------------
diff --git a/itests/hive-unit/src/test/java/org/apache/hive/beeline/TestSchemaTool.java b/itests/hive-unit/src/test/java/org/apache/hive/beeline/TestSchemaTool.java
index 3b5c6c0..ac2c927 100644
--- a/itests/hive-unit/src/test/java/org/apache/hive/beeline/TestSchemaTool.java
+++ b/itests/hive-unit/src/test/java/org/apache/hive/beeline/TestSchemaTool.java
@@ -209,7 +209,41 @@ public class TestSchemaTool extends TestCase {
public void testSchemaInit() throws Exception {
schemaTool.doInit(MetaStoreSchemaInfo.getHiveSchemaVersion());
schemaTool.verifySchemaVersion();
- }
+ }
+
+ /**
+ * Test validation for schema versions
+ * @throws Exception
+ */
+ public void testValidateSchemaVersions() throws Exception {
+ schemaTool.doInit();
+ boolean isValid = schemaTool.validateSchemaVersions();
+ // Test an invalid case with multiple versions
+ String[] scripts = new String[] {
+ "insert into VERSION values(100, '2.2.0', 'Hive release version 2.2.0')"
+ };
+ File scriptFile = generateTestScript(scripts);
+ schemaTool.runBeeLine(scriptFile.getPath());
+ isValid = schemaTool.validateSchemaVersions();
+ assertFalse(isValid);
+
+ scripts = new String[] {
+ "delete from VERSION where VER_ID = 100"
+ };
+ scriptFile = generateTestScript(scripts);
+ schemaTool.runBeeLine(scriptFile.getPath());
+ isValid = schemaTool.validateSchemaVersions();
+ assertTrue(isValid);
+
+ // Test an invalid case without version
+ scripts = new String[] {
+ "delete from VERSION"
+ };
+ scriptFile = generateTestScript(scripts);
+ schemaTool.runBeeLine(scriptFile.getPath());
+ isValid = schemaTool.validateSchemaVersions();
+ assertFalse(isValid);
+ }
/**
* Test schema upgrade