Repository: hive Updated Branches: refs/heads/branch-1 1a647c420 -> b9af10d28
HIVE-11534: Improve validateTableCols error message (Mohit via Xuefu) Project: http://git-wip-us.apache.org/repos/asf/hive/repo Commit: http://git-wip-us.apache.org/repos/asf/hive/commit/b9af10d2 Tree: http://git-wip-us.apache.org/repos/asf/hive/tree/b9af10d2 Diff: http://git-wip-us.apache.org/repos/asf/hive/diff/b9af10d2 Branch: refs/heads/branch-1 Commit: b9af10d2821c6428a5a5778625a167434537bc85 Parents: 1a647c4 Author: Xuefu Zhang <xzh...@cloudera.com> Authored: Fri Aug 14 06:48:19 2015 -0700 Committer: Xuefu Zhang <xzh...@cloudera.com> Committed: Fri Aug 14 15:38:05 2015 -0700 ---------------------------------------------------------------------- .../hive/metastore/TestHiveMetaStore.java | 66 ++++++++++++++++++++ .../hadoop/hive/metastore/ObjectStore.java | 7 ++- 2 files changed, 71 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/hive/blob/b9af10d2/itests/hive-unit/src/test/java/org/apache/hadoop/hive/metastore/TestHiveMetaStore.java ---------------------------------------------------------------------- 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 5a344bb..160667d 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 @@ -2966,4 +2966,70 @@ public abstract class TestHiveMetaStore extends TestCase { }; return hookLoader; } + + public void testValidateTableCols() throws Throwable { + + try { + String dbName = "compdb"; + String tblName = "comptbl"; + + client.dropTable(dbName, tblName); + silentDropDatabase(dbName); + Database db = new Database(); + db.setName(dbName); + db.setDescription("Validate Table Columns test"); + client.createDatabase(db); + + ArrayList<FieldSchema> cols = new ArrayList<FieldSchema>(2); + cols.add(new FieldSchema("name", serdeConstants.STRING_TYPE_NAME, "")); + cols.add(new FieldSchema("income", serdeConstants.INT_TYPE_NAME, "")); + + Table tbl = new Table(); + tbl.setDbName(dbName); + tbl.setTableName(tblName); + StorageDescriptor sd = new StorageDescriptor(); + tbl.setSd(sd); + sd.setCols(cols); + sd.setCompressed(false); + sd.setSerdeInfo(new SerDeInfo()); + sd.getSerdeInfo().setName(tbl.getTableName()); + sd.getSerdeInfo().setParameters(new HashMap<String, String>()); + sd.getSerdeInfo().getParameters() + .put(serdeConstants.SERIALIZATION_FORMAT, "1"); + sd.getSerdeInfo().setSerializationLib(LazySimpleSerDe.class.getName()); + sd.setInputFormat(HiveInputFormat.class.getName()); + sd.setOutputFormat(HiveOutputFormat.class.getName()); + sd.setSortCols(new ArrayList<Order>()); + + client.createTable(tbl); + if (isThriftClient) { + tbl = client.getTable(dbName, tblName); + } + + List<String> expectedCols = Lists.newArrayList(); + expectedCols.add("name"); + ObjectStore objStore = new ObjectStore(); + try { + objStore.validateTableCols(tbl, expectedCols); + } catch (MetaException ex) { + throw new RuntimeException(ex); + } + + expectedCols.add("doesntExist"); + boolean exceptionFound = false; + try { + objStore.validateTableCols(tbl, expectedCols); + } catch (MetaException ex) { + assertEquals(ex.getMessage(), + "Column doesntExist doesn't exist in table comptbl in database compdb"); + exceptionFound = true; + } + assertTrue(exceptionFound); + + } catch (Exception e) { + System.err.println(StringUtils.stringifyException(e)); + System.err.println("testValidateTableCols() failed."); + throw e; + } + } } http://git-wip-us.apache.org/repos/asf/hive/blob/b9af10d2/metastore/src/java/org/apache/hadoop/hive/metastore/ObjectStore.java ---------------------------------------------------------------------- diff --git a/metastore/src/java/org/apache/hadoop/hive/metastore/ObjectStore.java b/metastore/src/java/org/apache/hadoop/hive/metastore/ObjectStore.java index a37fbde..d165fc8 100644 --- a/metastore/src/java/org/apache/hadoop/hive/metastore/ObjectStore.java +++ b/metastore/src/java/org/apache/hadoop/hive/metastore/ObjectStore.java @@ -51,6 +51,7 @@ import javax.jdo.Transaction; import javax.jdo.datastore.DataStoreCache; import javax.jdo.identity.IntIdentity; +import com.google.common.annotations.VisibleForTesting; import org.antlr.runtime.CommonTokenStream; import org.antlr.runtime.RecognitionException; import org.apache.commons.logging.Log; @@ -6261,7 +6262,8 @@ public class ObjectStore implements RawStore, Configurable { } } - private void validateTableCols(Table table, List<String> colNames) throws MetaException { + @VisibleForTesting + public void validateTableCols(Table table, List<String> colNames) throws MetaException { List<FieldSchema> colList = table.getSd().getCols(); for (String colName : colNames) { boolean foundCol = false; @@ -6272,7 +6274,8 @@ public class ObjectStore implements RawStore, Configurable { } } if (!foundCol) { - throw new MetaException("Column " + colName + " doesn't exist."); + throw new MetaException("Column " + colName + " doesn't exist in table " + + table.getTableName() + " in database " + table.getDbName()); } } }