diff --git a/beeline/src/java/org/apache/hive/beeline/HiveSchemaTool.java b/beeline/src/java/org/apache/hive/beeline/HiveSchemaTool.java index 7dd4d5f..e64ac23 100644 --- a/beeline/src/java/org/apache/hive/beeline/HiveSchemaTool.java +++ b/beeline/src/java/org/apache/hive/beeline/HiveSchemaTool.java @@ -174,7 +174,7 @@ private String getMetaStoreSchemaVersion(Connection metastoreConn, try(Statement stmt = metastoreConn.createStatement(); ResultSet res = stmt.executeQuery(versionQuery)) { if (!res.next()) { - throw new HiveMetaException("Could not find version info in metastore VERSION table"); + throw new HiveMetaException("Could not find version info in metastore VERSION table."); } String currentSchemaVersion = res.getString(1); if (checkDuplicatedVersion && res.next()) { @@ -227,7 +227,6 @@ private boolean checkMetaStoreDBLocation(Connection conn, URI[] defaultServers) } if (numOfInvalid > 0) { isValid = false; - System.err.println("Total number of invalid DB locations is: "+ numOfInvalid); } return isValid; } @@ -288,7 +287,6 @@ private boolean checkMetaStoreTableLocation(Connection conn, URI[] defaultServer } if (numOfInvalid > 0) { isValid = false; - System.err.println("Total number of invalid TABLE locations is: "+ numOfInvalid); } return isValid; } @@ -350,7 +348,6 @@ private boolean checkMetaStorePartitionLocation(Connection conn, URI[] defaultSe } if (numOfInvalid > 0) { isValid = false; - System.err.println("Total number of invalid PARTITION locations is: "+ numOfInvalid); } return isValid; } @@ -367,11 +364,11 @@ private boolean checkMetaStoreSkewedColumnsLocation(Connection conn, URI[] defau } if (getDbCommandParser(dbType).needsQuotedIdentifier()) { - skewedColLoc = "select t.\"TBL_NAME\", t.\"TBL_ID\", sk.\"STRING_LIST_ID_KID\", sk.\"LOCATION\" from \"TBLS\" t, \"SDS\" s, \"SKEWED_COL_VALUE_LOC_MAP\" sk " - + "where sk.\"SD_ID\" = s.\"SD_ID\" and s.\"SD_ID\" = t.\"SD_ID\" and sk.\"STRING_LIST_ID_KID\" >= ? and sk.\"STRING_LIST_ID_KID\" <= ? "; + skewedColLoc = "select t.\"TBL_NAME\", t.\"TBL_ID\", sk.\"STRING_LIST_ID_KID\", sk.\"LOCATION\", db.\"NAME\", db.\"DB_ID\" from \"TBLS\" t, \"SDS\" s, \"DBS\" db, \"SKEWED_COL_VALUE_LOC_MAP\" sk " + + "where sk.\"SD_ID\" = s.\"SD_ID\" and s.\"SD_ID\" = t.\"SD_ID\" and t.\"DB_ID\" = db.\"DB_ID\" and sk.\"STRING_LIST_ID_KID\" >= ? and sk.\"STRING_LIST_ID_KID\" <= ? "; } else { - skewedColLoc = "select t.TBL_NAME, t.TBL_ID, sk.STRING_LIST_ID_KID, sk.LOCATION from TBLS t, SDS s, SKEWED_COL_VALUE_LOC_MAP sk " - + "where sk.SD_ID = s.SD_ID and s.SD_ID = t.SD_ID and sk.STRING_LIST_ID_KID >= ? and sk.STRING_LIST_ID_KID <= ? "; + skewedColLoc = "select t.TBL_NAME, t.TBL_ID, sk.STRING_LIST_ID_KID, sk.LOCATION, db.NAME, db.DB_ID from TBLS t, SDS s, DBS db, SKEWED_COL_VALUE_LOC_MAP sk " + + "where sk.SD_ID = s.SD_ID and s.SD_ID = t.SD_ID and t.DB_ID = db.DB_ID and sk.STRING_LIST_ID_KID >= ? and sk.STRING_LIST_ID_KID <= ? "; } long maxID = 0, minID = 0; @@ -393,7 +390,8 @@ private boolean checkMetaStoreSkewedColumnsLocation(Connection conn, URI[] defau res = pStmt.executeQuery(); while (res.next()) { String locValue = res.getString(4); - String entity = "Table " + getNameOrID(res,1,2) + + String entity = "Database " + getNameOrID(res,5,6) + + ", Table " + getNameOrID(res,1,2) + ", String list " + res.getString(3); if (!checkLocation(entity, locValue, defaultServers)) { numOfInvalid++; @@ -408,7 +406,6 @@ private boolean checkMetaStoreSkewedColumnsLocation(Connection conn, URI[] defau } if (numOfInvalid > 0) { isValid = false; - System.err.println("Total number of invalid SKEWED_COL_VALUE_LOC_MAP locations is: "+ numOfInvalid); } return isValid; } @@ -428,14 +425,14 @@ private boolean checkLocation( URI[] defaultServers) { boolean isValid = true; if (entityLocation == null) { - System.err.println(entity + ", error: empty location"); + System.err.println(entity + ", Error: empty location"); isValid = false; } else { try { URI currentUri = new Path(entityLocation).toUri(); String scheme = currentUri.getScheme(); if (StringUtils.isEmpty(scheme)) { - System.err.println(entity + ", location: "+ entityLocation + ", error: missing location scheme"); + System.err.println(entity + ", Location: "+ entityLocation + ", Error: missing location scheme"); isValid = false; } else if (ArrayUtils.isNotEmpty(defaultServers) && currentUri.getAuthority() != null) { String authority = currentUri.getAuthority(); @@ -448,12 +445,12 @@ private boolean checkLocation( } } if (!matchServer) { - System.err.println(entity + ", location: " + entityLocation + ", error: mismatched server"); + System.err.println(entity + ", Location: " + entityLocation + ", Error: mismatched server"); isValid = false; } } } catch (Exception pe) { - System.err.println(entity + ", error: invalid location " + pe.getMessage()); + System.err.println(entity + ", Error: invalid location - " + pe.getMessage()); isValid =false; } } @@ -705,11 +702,12 @@ boolean validateSchemaVersions(Connection conn) throws HiveMetaException { if (hme.getMessage().contains("Metastore schema version is not compatible") || hme.getMessage().contains("Multiple versions were found in metastore") || hme.getMessage().contains("Could not find version info in metastore VERSION table")) { - System.out.println("Failed in schema version validation: " + hme.getMessage()); - return false; - } else { - throw hme; - } + System.err.println(hme.getMessage()); + System.out.println("Failed in schema version validation."); + return false; + } else { + throw hme; + } } System.out.println("Succeeded in schema version validation."); return true; @@ -728,7 +726,8 @@ boolean validateSchemaTables(Connection conn) throws HiveMetaException { try { version = getMetaStoreSchemaVersion(hmsConn); } catch (HiveMetaException he) { - System.err.println("Failed to determine schema version from Hive Metastore DB," + he.getMessage()); + System.err.println("Failed to determine schema version from Hive Metastore DB. " + he.getMessage()); + System.out.println("Failed in schema version validation."); LOG.debug("Failed to determine schema version from Hive Metastore DB," + he.getMessage()); return false; } @@ -775,17 +774,16 @@ boolean validateSchemaTables(Connection conn) throws HiveMetaException { } } catch (Exception e) { System.err.println("Exception in parsing schema file. Cause:" + e.getMessage()); - System.out.println("Schema table validation failed!!!"); + System.out.println("Failed in schema table validation."); return false; } LOG.debug("Schema tables:[ " + Arrays.toString(schemaTables.toArray()) + " ]"); LOG.debug("DB tables:[ " + Arrays.toString(dbTables.toArray()) + " ]"); // now diff the lists - int schemaSize = schemaTables.size(); schemaTables.removeAll(dbTables); if (schemaTables.size() > 0) { - System.out.println("Table(s) [ " + Arrays.toString(schemaTables.toArray()) + System.err.println("Table(s) [ " + Arrays.toString(schemaTables.toArray()) + " ] are missing from the metastore database schema."); System.out.println("Schema table validation failed!!!"); return false; @@ -1055,7 +1053,7 @@ private static void initOptions(Options cmdLineOptions) { Option dryRunOpt = new Option("dryRun", "list SQL scripts (no execute)"); Option verboseOpt = new Option("verbose", "only print SQL statements"); Option serversOpt = OptionBuilder.withArgName("serverList") - .hasArgs().withDescription("a comma-separated list of servers used in location validation") + .hasArgs().withDescription("a comma-separated list of servers used in location validation in the format of scheme://authority (e.g. hdfs://localhost:8000)") .create("servers"); cmdLineOptions.addOption(help); cmdLineOptions.addOption(dryRunOpt);