Index: storage-handlers/hbase/src/test/org/apache/hcatalog/hbase/TestHBaseHCatStorageHandler.java =================================================================== --- storage-handlers/hbase/src/test/org/apache/hcatalog/hbase/TestHBaseHCatStorageHandler.java (revision 1303016) +++ storage-handlers/hbase/src/test/org/apache/hcatalog/hbase/TestHBaseHCatStorageHandler.java (working copy) @@ -36,6 +36,8 @@ import org.apache.hadoop.hive.ql.session.SessionState; import org.apache.hcatalog.cli.HCatDriver; import org.apache.hcatalog.cli.SemanticAnalysis.HCatSemanticAnalyzer; +import org.apache.hcatalog.hbase.snapshot.RevisionManager; +import org.apache.zookeeper.KeeperException.NoNodeException; import org.junit.Test; public class TestHBaseHCatStorageHandler extends SkeletonHBaseTest { @@ -84,11 +86,57 @@ boolean doesTableExist = hAdmin.tableExists("test_table"); assertTrue(doesTableExist); + + RevisionManager rm = HBaseRevisionManagerUtil.getOpenedRevisionManager(getHbaseConf()); + rm.open(); + //Should be able to successfully query revision manager + rm.getAbortedWriteTransactions("test_table", "cf1"); hcatDriver.run("drop table test_table"); doesTableExist = hAdmin.tableExists("test_table"); + assertTrue(doesTableExist == false); + + try { + rm.getAbortedWriteTransactions("test_table", "cf1"); + } catch (Exception e) { + assertTrue(e.getCause() instanceof NoNodeException); + } + rm.close(); + } + + @Test + public void testTableCreateDropCaseSensitive() throws Exception { + Initialize(); + + hcatDriver.run("drop table test_Table"); + CommandProcessorResponse response = hcatDriver + .run("create table test_Table(key int, value string) STORED BY " + + "'org.apache.hcatalog.hbase.HBaseHCatStorageHandler'" + + "TBLPROPERTIES ('hbase.columns.mapping'=':key,cf1:val')"); + + assertEquals(0, response.getResponseCode()); + + HBaseAdmin hAdmin = new HBaseAdmin(getHbaseConf()); + boolean doesTableExist = hAdmin.tableExists("test_Table"); + + assertTrue(doesTableExist); + + RevisionManager rm = HBaseRevisionManagerUtil.getOpenedRevisionManager(getHbaseConf()); + rm.open(); + //Should be able to successfully query revision manager + rm.getAbortedWriteTransactions("test_Table", "cf1"); + + hcatDriver.run("drop table test_Table"); + doesTableExist = hAdmin.tableExists("test_Table"); assertTrue(doesTableExist == false); + + try { + rm.getAbortedWriteTransactions("test_Table", "cf1"); + } catch (Exception e) { + assertTrue(e.getCause() instanceof NoNodeException); + } + rm.close(); } Index: storage-handlers/hbase/src/test/org/apache/hcatalog/hbase/TestHBaseDirectOutputFormat.java =================================================================== --- storage-handlers/hbase/src/test/org/apache/hcatalog/hbase/TestHBaseDirectOutputFormat.java (revision 1303016) +++ storage-handlers/hbase/src/test/org/apache/hcatalog/hbase/TestHBaseDirectOutputFormat.java (working copy) @@ -264,9 +264,9 @@ public void directModeAbortTest() throws Exception { String testName = "directModeAbortTest"; Path methodTestDir = new Path(getTestDir(), testName); - String databaseName = testName.toLowerCase(); + String databaseName = testName; String dbDir = new Path(methodTestDir, "DB_" + testName).toString(); - String tableName = newTableName(testName).toLowerCase(); + String tableName = newTableName(testName); String familyName = "my_family"; byte[] familyNameBytes = Bytes.toBytes(familyName); Index: storage-handlers/hbase/src/test/org/apache/hcatalog/hbase/TestHBaseInputFormat.java =================================================================== --- storage-handlers/hbase/src/test/org/apache/hcatalog/hbase/TestHBaseInputFormat.java (revision 1303016) +++ storage-handlers/hbase/src/test/org/apache/hcatalog/hbase/TestHBaseInputFormat.java (working copy) @@ -172,8 +172,8 @@ @Test public void TestHBaseTableReadMR() throws Exception { Initialize(); - String tableName = newTableName("mytable"); - String databaseName = newTableName("mydatabase"); + String tableName = newTableName("MyTable"); + String databaseName = newTableName("MyDatabase"); String db_dir = getTestDir() + "/hbasedb"; String dbquery = "CREATE DATABASE IF NOT EXISTS " + databaseName + " LOCATION '" Index: storage-handlers/hbase/src/java/org/apache/hcatalog/hbase/snapshot/RevisionManager.java =================================================================== --- storage-handlers/hbase/src/java/org/apache/hcatalog/hbase/snapshot/RevisionManager.java (revision 1303016) +++ storage-handlers/hbase/src/java/org/apache/hcatalog/hbase/snapshot/RevisionManager.java (working copy) @@ -48,6 +48,19 @@ public void close() throws IOException; /** + * Setup revision management for a newly created hbase table. + * @param table the hbase table name + * @param columnFamilies the column families in the table + */ + public void setupTable(String table, List columnFamilies) throws IOException; + + /** + * Remove table data from revision manager for a dropped table. + * @param table the hbase table name + */ + public void dropTable(String table) throws IOException; + + /** * Start the write transaction. * * @param table Index: storage-handlers/hbase/src/java/org/apache/hcatalog/hbase/snapshot/ZKBasedRevisionManager.java =================================================================== --- storage-handlers/hbase/src/java/org/apache/hcatalog/hbase/snapshot/ZKBasedRevisionManager.java (revision 1303016) +++ storage-handlers/hbase/src/java/org/apache/hcatalog/hbase/snapshot/ZKBasedRevisionManager.java (working copy) @@ -88,7 +88,17 @@ } } + @Override + public void setupTable(String table, List columnFamilies) throws IOException { + zkUtil.createRootZNodes(); + zkUtil.setUpZnodesForTable(table, columnFamilies); + } + @Override + public void dropTable(String table) throws IOException { + zkUtil.deleteZNodes(table); + } + /* @param table /* @param families /* @param keepAlive @@ -413,29 +423,6 @@ return lockPath; } - /** - * Sets up the table, column family znodes in zookeeper. - * - * @param tableName the hbase table name - * @param columnFamilies the column families in hbase - * @throws IOException Signals that an I/O exception has occurred. - */ - public void setUpZNodes(String tableName, List columnFamilies) throws IOException{ - zkUtil.createRootZNodes(); - zkUtil.setUpZnodesForTable(tableName, columnFamilies); - } - - /** - * Delete the table znodes from zookeeper. - * - * @param tableName the table name - * @throws IOException Signals that an I/O exception has occurred. - */ - public void deleteZNodes(String tableName) throws IOException { - zkUtil.deleteZNodes(tableName); - } - - /* * This class is a listener class for the locks used in revision management. * TBD: Use the following class to signal that that the lock is actually Index: storage-handlers/hbase/src/java/org/apache/hcatalog/hbase/HBaseHCatStorageHandler.java =================================================================== --- storage-handlers/hbase/src/java/org/apache/hcatalog/hbase/HBaseHCatStorageHandler.java (revision 1303016) +++ storage-handlers/hbase/src/java/org/apache/hcatalog/hbase/HBaseHCatStorageHandler.java (working copy) @@ -94,7 +94,7 @@ try { InputJobInfo inputJobInfo = (InputJobInfo) HCatUtil.deserialize(jobString); HCatTableInfo tableInfo = inputJobInfo.getTableInfo(); - String qualifiedTableName = HBaseHCatStorageHandler.getFullyQualifiedName(tableInfo); + String qualifiedTableName = HBaseHCatStorageHandler.getFullyQualifiedHBaseTableName(tableInfo); jobProperties.put(TableInputFormat.INPUT_TABLE, qualifiedTableName); Configuration jobConf = getConf(); @@ -140,7 +140,7 @@ try { OutputJobInfo outputJobInfo = (OutputJobInfo) HCatUtil.deserialize(jobString); HCatTableInfo tableInfo = outputJobInfo.getTableInfo(); - String qualifiedTableName = HBaseHCatStorageHandler.getFullyQualifiedName(tableInfo); + String qualifiedTableName = HBaseHCatStorageHandler.getFullyQualifiedHBaseTableName(tableInfo); jobProperties.put(HBaseConstants.PROPERTY_OUTPUT_TABLE_NAME_KEY, qualifiedTableName); jobProperties.put(TableOutputFormat.OUTPUT_TABLE, qualifiedTableName); @@ -259,7 +259,7 @@ } try { - String tableName = getHBaseTableName(tbl); + String tableName = getFullyQualifiedHBaseTableName(tbl); String hbaseColumnsMapping = tbl.getParameters().get( HBaseSerDe.HBASE_COLUMNS_MAPPING); @@ -272,6 +272,8 @@ + " properties."); } + tbl.putToParameters(HBaseSerDe.HBASE_TABLE_NAME, tableName); + List hbaseColumnFamilies = new ArrayList(); List hbaseColumnQualifiers = new ArrayList(); List hbaseColumnFamiliesBytes = new ArrayList(); @@ -331,13 +333,9 @@ // ensure the table is online new HTable(hbaseConf, tableDesc.getName()); - //Set up znodes in revision manager. + //Set up table in revision manager. RevisionManager rm = HBaseRevisionManagerUtil.getOpenedRevisionManager(hbaseConf); - if (rm instanceof ZKBasedRevisionManager) { - ZKBasedRevisionManager zkRM = (ZKBasedRevisionManager) rm; - zkRM.setUpZNodes(tableName, new ArrayList( - uniqueColumnFamilies)); - } + rm.setupTable(tableName, new ArrayList(uniqueColumnFamilies)); } catch (MasterNotRunningException mnre) { throw new MetaException(StringUtils.stringifyException(mnre)); @@ -409,7 +407,7 @@ } } - private String getHBaseTableName(Table tbl) { + private String getFullyQualifiedHBaseTableName(Table tbl) { String tableName = tbl.getParameters().get(HBaseSerDe.HBASE_TABLE_NAME); if (tableName == null) { tableName = tbl.getSd().getSerdeInfo().getParameters() @@ -425,6 +423,22 @@ return tableName; } + static String getFullyQualifiedHBaseTableName(HCatTableInfo tableInfo){ + String qualifiedName = tableInfo.getStorerInfo().getProperties() + .getProperty(HBaseSerDe.HBASE_TABLE_NAME); + if (qualifiedName == null) { + String databaseName = tableInfo.getDatabaseName(); + String tableName = tableInfo.getTableName(); + if ((databaseName == null) + || (databaseName.equals(MetaStoreUtils.DEFAULT_DATABASE_NAME))) { + qualifiedName = tableName; + } else { + qualifiedName = databaseName + "." + tableName; + } + } + return qualifiedName; + } + @Override public Class getInputFormatClass() { return HBaseInputFormat.class; @@ -468,7 +482,7 @@ private void checkDeleteTable(Table table) throws MetaException { boolean isExternal = MetaStoreUtils.isExternalTable(table); - String tableName = getHBaseTableName(table); + String tableName = getFullyQualifiedHBaseTableName(table); RevisionManager rm = null; try { if (!isExternal && getHBaseAdmin().tableExists(tableName)) { @@ -478,12 +492,9 @@ } getHBaseAdmin().deleteTable(tableName); - //Set up znodes in revision manager. + //Drop table in revision manager. rm = HBaseRevisionManagerUtil.getOpenedRevisionManager(hbaseConf); - if (rm instanceof ZKBasedRevisionManager) { - ZKBasedRevisionManager zkRM = (ZKBasedRevisionManager) rm; - zkRM.deleteZNodes(tableName); - } + rm.dropTable(tableName); } } catch (IOException ie) { throw new MetaException(StringUtils.stringifyException(ie)); @@ -492,20 +503,6 @@ } } - static String getFullyQualifiedName(HCatTableInfo tableInfo){ - String qualifiedName; - String databaseName = tableInfo.getDatabaseName(); - String tableName = tableInfo.getTableName(); - - if ((databaseName == null) || (databaseName.equals(MetaStoreUtils.DEFAULT_DATABASE_NAME))) { - qualifiedName = tableName; - } else { - qualifiedName = databaseName + "." + tableName; - } - - return qualifiedName; - } - /** * Helper method for users to add the required depedency jars to distributed cache. * @param conf