@@ -201,9 +201,7 @@ private static Table toHiveTable(HiveTableMetadata hiveTable) {
201201 // table.setRetention(0);
202202 String location = hiveTable .getProperties ().get ("external_location" );
203203 table .setSd (toHiveStorageDesc (hiveTable .getColumns (),
204- hiveTable .getInputFormat (),
205- hiveTable .getOutputFormat (),
206- hiveTable .getSerDe (),
204+ hiveTable .getFileFormat (),
207205 location ));
208206 table .setPartitionKeys (hiveTable .getPartitionKeys ());
209207 // table.setViewOriginalText(hiveTable.getViewSql());
@@ -213,15 +211,10 @@ private static Table toHiveTable(HiveTableMetadata hiveTable) {
213211 return table ;
214212 }
215213
216- private static StorageDescriptor toHiveStorageDesc (List <Column > columns , String inputFormat , String outputFormat ,
217- String serDe , String location ) {
214+ private static StorageDescriptor toHiveStorageDesc (List <Column > columns , String fileFormat , String location ) {
218215 StorageDescriptor sd = new StorageDescriptor ();
219216 sd .setCols (toHiveColumns (columns ));
220- SerDeInfo serDeInfo = new SerDeInfo ();
221- serDeInfo .setSerializationLib (serDe );
222- sd .setSerdeInfo (serDeInfo );
223- sd .setInputFormat (inputFormat );
224- sd .setOutputFormat (outputFormat );
217+ setFileFormat (fileFormat , sd );
225218 if (StringUtils .isNotEmpty (location )) {
226219 sd .setLocation (location );
227220 }
@@ -231,6 +224,28 @@ private static StorageDescriptor toHiveStorageDesc(List<Column> columns, String
231224 return sd ;
232225 }
233226
227+ private static void setFileFormat (String fileFormat , StorageDescriptor sd ) {
228+ String inputFormat ;
229+ String outputFormat ;
230+ String serDe ;
231+ if (fileFormat .equalsIgnoreCase ("orc" )) {
232+ inputFormat = "org.apache.hadoop.hive.ql.io.orc.OrcInputFormat" ;
233+ outputFormat = "org.apache.hadoop.hive.ql.io.orc.OrcOutputFormat" ;
234+ serDe = "org.apache.hadoop.hive.ql.io.orc.OrcSerde" ;
235+ } else if (fileFormat .equalsIgnoreCase ("parquet" )) {
236+ inputFormat = "org.apache.hadoop.hive.ql.io.parquet.MapredParquetInputFormat" ;
237+ outputFormat = "'org.apache.hadoop.hive.ql.io.parquet.MapredParquetOutputFormat" ;
238+ serDe = "org.apache.hadoop.hive.ql.io.parquet.serde.ParquetHiveSerDe" ;
239+ } else {
240+ throw new IllegalArgumentException ("Creating table with an unsupported file format: " + fileFormat );
241+ }
242+ SerDeInfo serDeInfo = new SerDeInfo ();
243+ serDeInfo .setSerializationLib (serDe );
244+ sd .setSerdeInfo (serDeInfo );
245+ sd .setInputFormat (inputFormat );
246+ sd .setOutputFormat (outputFormat );
247+ }
248+
234249 private static List <FieldSchema > toHiveColumns (List <Column > columns ) {
235250 List <FieldSchema > result = new ArrayList <>();
236251 for (Column column : columns ) {
@@ -297,6 +312,19 @@ public List<String> listPartitionNames(String dbName, String tblName) {
297312 return listPartitionNames (dbName , tblName , MAX_LIST_PARTITION_NUM );
298313 }
299314
315+ public List <Partition > listPartitions (String dbName , String tblName ) {
316+ try (ThriftHMSClient client = getClient ()) {
317+ try {
318+ return ugiDoAs (() -> client .client .listPartitions (dbName , tblName , MAX_LIST_PARTITION_NUM ));
319+ } catch (Exception e ) {
320+ client .setThrowable (e );
321+ throw e ;
322+ }
323+ } catch (Exception e ) {
324+ throw new HMSClientException ("failed to check if table %s in db %s exists" , e , tblName , dbName );
325+ }
326+ }
327+
300328 @ Override
301329 public List <String > listPartitionNames (String dbName , String tblName , long maxListPartitionNum ) {
302330 // list all parts when the limit is greater than the short maximum
0 commit comments