diff --git hcatalog/webhcat/java-client/src/main/java/org/apache/hcatalog/api/HCatCreateTableDesc.java hcatalog/webhcat/java-client/src/main/java/org/apache/hcatalog/api/HCatCreateTableDesc.java index cc855da..d44bfc5 100644 --- hcatalog/webhcat/java-client/src/main/java/org/apache/hcatalog/api/HCatCreateTableDesc.java +++ hcatalog/webhcat/java-client/src/main/java/org/apache/hcatalog/api/HCatCreateTableDesc.java @@ -345,6 +345,7 @@ public String toString() { private String fileFormat; private String location; private String storageHandler; + private String serDe; private Map tblProps; private boolean ifNotExists; private String dbName; @@ -472,6 +473,17 @@ public Builder fileFormat(String format) { } /** + * SerDe. + * + * @param serDe the SerDe implementation's class-name. + * @return the builder + */ + public Builder serDe(String serDe) { + this.serDe = serDe; + return this; + } + + /** * Builds the HCatCreateTableDesc. * * @return HCatCreateTableDesc @@ -494,7 +506,7 @@ public HCatCreateTableDesc build() throws HCatException { 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)) { diff --git hcatalog/webhcat/java-client/src/test/java/org/apache/hcatalog/api/TestHCatClient.java hcatalog/webhcat/java-client/src/test/java/org/apache/hcatalog/api/TestHCatClient.java index 1f416a5..8c131d6 100644 --- hcatalog/webhcat/java-client/src/test/java/org/apache/hcatalog/api/TestHCatClient.java +++ hcatalog/webhcat/java-client/src/test/java/org/apache/hcatalog/api/TestHCatClient.java @@ -36,6 +36,7 @@ import org.apache.hadoop.hive.ql.io.orc.OrcSerde; 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; @@ -51,6 +52,7 @@ import org.slf4j.LoggerFactory; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotSame; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertArrayEquals; @@ -179,6 +181,24 @@ public void testBasicDDLCommands() throws Exception { OrcSerde.class.getName())); assertTrue(table1.getCols().equals(cols)); + // Check that serDe settings stick. + String tableFour = "table4"; + String nonDefaultSerDe = "com.my.custom.SerDe"; + HCatCreateTableDesc tableDesc4 = + HCatCreateTableDesc.create(db, tableFour, cols).serDe(nonDefaultSerDe).build(); + client.createTable(tableDesc4); + HCatTable table4 = client.getTable(db, tableFour); + assertEquals("SerDe libraries don't match!", nonDefaultSerDe, table4.getSerdeLib()); + client.dropTable(db, tableFour, true); + + // Check that serDe settings don't stick when a storageHandler is used. + tableDesc4 = HCatCreateTableDesc.create(db, tableFour, cols). + serDe(nonDefaultSerDe).storageHandler(DefaultStorageHandler.class.getName()).build(); + client.createTable(tableDesc4); + table4 = client.getTable(db, tableFour); + assertNotSame("SerDe libraries shouldn't have matched!", nonDefaultSerDe, table4.getSerdeLib()); + client.dropTable(db, tableFour, true); + client.close(); }