Index: webhcat/java-client/src/test/java/org/apache/hcatalog/api/TestHCatClient.java =================================================================== --- webhcat/java-client/src/test/java/org/apache/hcatalog/api/TestHCatClient.java (revision 1459116) +++ webhcat/java-client/src/test/java/org/apache/hcatalog/api/TestHCatClient.java (working copy) @@ -33,6 +33,7 @@ import org.apache.hadoop.hive.ql.io.IgnoreKeyTextOutputFormat; import org.apache.hadoop.hive.ql.io.RCFileInputFormat; import org.apache.hadoop.hive.ql.io.RCFileOutputFormat; +import org.apache.hadoop.hive.ql.metadata.DefaultStorageHandler; import org.apache.hadoop.hive.serde2.columnar.ColumnarSerDe; import org.apache.hadoop.mapred.TextInputFormat; import org.apache.hcatalog.cli.SemanticAnalysis.HCatSemanticAnalyzer; @@ -50,6 +51,7 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotSame; import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertArrayEquals; @@ -158,6 +160,25 @@ IgnoreKeyTextOutputFormat.class.getName())); assertTrue(table2.getLocation().equalsIgnoreCase( "file:" + warehouseDir + "/" + db + ".db/" + tableTwo)); + + // Check that serDe settings stick. + String tableThree = "table3"; + String nonDefaultSerDe = "com.my.custom.SerDe"; + HCatCreateTableDesc tableDesc3 = HCatCreateTableDesc.create(db, tableThree, cols) + .serDe(nonDefaultSerDe).build(); + client.createTable(tableDesc3); + HCatTable table3 = client.getTable(db, tableThree); + assertEquals("SerDe libraries don't match!", nonDefaultSerDe, table3.getSerdeLib()); + client.dropTable(db, tableThree, true); + + // Check that serDe settings don't stick when a storageHandler is used. + tableDesc3 = HCatCreateTableDesc.create(db, tableThree, cols) + .serDe(nonDefaultSerDe).storageHandler(DefaultStorageHandler.class.getName()).build(); + client.createTable(tableDesc3); + table3 = client.getTable(db, tableThree); + assertNotSame("SerDe libraries shouldn't have matched!", nonDefaultSerDe, table3.getSerdeLib()); + client.dropTable(db, tableThree, true); + client.close(); } Index: webhcat/java-client/src/main/java/org/apache/hcatalog/api/HCatCreateTableDesc.java =================================================================== --- webhcat/java-client/src/main/java/org/apache/hcatalog/api/HCatCreateTableDesc.java (revision 1459116) +++ webhcat/java-client/src/main/java/org/apache/hcatalog/api/HCatCreateTableDesc.java (working copy) @@ -341,6 +341,7 @@ private String fileFormat; private String location; private String storageHandler; + private String serDe; private Map tblProps; private boolean ifNotExists; private String dbName; @@ -402,6 +403,17 @@ } /** + * SerDe. + * + * @param serDe the SerDe implementation's class-name. + * @return the builder + */ + public Builder serDe(String serDe) { + this.serDe = serDe; + return this; + } + + /** * Location. * * @param location the location @@ -490,7 +502,7 @@ desc.location = this.location; desc.tblProps = this.tblProps; desc.sortCols = this.sortCols; - desc.serde = null; + desc.serde = this.serDe; if (!StringUtils.isEmpty(fileFormat)) { desc.fileFormat = fileFormat; if ("SequenceFile".equalsIgnoreCase(fileFormat)) { @@ -500,10 +512,15 @@ } else if ("RCFile".equalsIgnoreCase(fileFormat)) { desc.inputformat = RCFileInputFormat.class.getName(); desc.outputformat = RCFileOutputFormat.class.getName(); + if (!StringUtils.isEmpty(this.serDe)) + LOG.info("Ignoring SerDe setting, and using ColumnarSerDe instead."); desc.serde = ColumnarSerDe.class.getName(); } desc.storageHandler = StringUtils.EMPTY; } else if (!StringUtils.isEmpty(storageHandler)) { + if (!StringUtils.isEmpty(this.serDe)) + LOG.info("SerDe specification will be ignored, since StorageHandler is specified."); + desc.serde = null; desc.storageHandler = storageHandler; } else { desc.fileFormat = "TextFile";