@Test public void testGetHiveTable() throws Exception { final String databaseName = "testdb"; final String tableName = "testtable"; final String tableSdLoc = "/tmp/testtable"; final String partitionName = "partitionName"; State serdeProps = new State(); serdeProps.setProp("avro.schema.literal", "{\"type\": \"record\", \"name\": \"TestEvent\"," + " \"namespace\": \"test.namespace\", \"fields\": [{\"name\":\"testName\"," + " \"type\": \"int\"}]}"); List<FieldSchema> fieldSchemas = new ArrayList<>(); fieldSchemas.add(new FieldSchema("testName","int", "testContent")); SerDeInfo si = new SerDeInfo(); si.setParameters(getParameters(serdeProps)); si.setName(tableName); StorageDescriptor sd = new StorageDescriptor(fieldSchemas, tableSdLoc, AvroContainerInputFormat.class.getName(), AvroContainerOutputFormat.class.getName(), false, 0, si, null, Lists.<Order>newArrayList(), null); sd.setParameters(getParameters(serdeProps)); Table table = new Table(tableName, databaseName, "testOwner", 0, 0, 0, sd, Lists.<FieldSchema>newArrayList(), Maps.<String,String>newHashMap(), "", "", ""); table.addToPartitionKeys(new FieldSchema(partitionName, "string", "some comment")); HiveTable hiveTable = HiveMetaStoreUtils.getHiveTable(table); Assert.assertEquals(hiveTable.getDbName(), databaseName); Assert.assertEquals(hiveTable.getTableName(), tableName); Assert.assertTrue(hiveTable.getInputFormat().isPresent()); Assert.assertTrue(hiveTable.getOutputFormat().isPresent()); Assert.assertEquals(hiveTable.getInputFormat().get(), AvroContainerInputFormat.class.getName()); Assert.assertEquals(hiveTable.getOutputFormat().get(), AvroContainerOutputFormat.class.getName()); Assert.assertNotNull(hiveTable.getSerDeType()); List<HiveRegistrationUnit.Column> fields = hiveTable.getColumns(); Assert.assertTrue(fields != null && fields.size() == 1); HiveRegistrationUnit.Column fieldA = fields.get(0); Assert.assertEquals(fieldA.getName(), "testName"); Assert.assertEquals(fieldA.getType(), "int"); }
public static HiveTable getHiveTable(Table table) { State tableProps = getTableProps(table); State storageProps = getStorageProps(table.getSd()); State serDeProps = getSerDeProps(table.getSd().getSerdeInfo()); HiveTable hiveTable = new HiveTable.Builder().withDbName(table.getDbName()).withTableName(table.getTableName()) .withPartitionKeys(getColumns(table.getPartitionKeys())).withProps(tableProps).withStorageProps(storageProps) .withSerdeProps(serDeProps).build(); if (table.getCreateTime() > 0) { hiveTable.setCreateTime(table.getCreateTime()); } if (table.getSd().getCols() != null) { hiveTable.setColumns(getColumns(table.getSd().getCols())); } if (table.getSd().getBucketCols() != null) { hiveTable.setBucketColumns(table.getSd().getBucketCols()); } return hiveTable; }
HiveMetaStoreUtils { public static HiveTable getHiveTable(Table table) { State tableProps = getTableProps(table); State storageProps = getStorageProps(table.getSd()); State serDeProps = getSerDeProps(table.getSd().getSerdeInfo()); HiveTable hiveTable = new HiveTable.Builder().withDbName(table.getDbName()).withTableName(table.getTableName()) .withPartitionKeys(getColumns(table.getPartitionKeys())).withProps(tableProps).withStorageProps(storageProps) .withSerdeProps(serDeProps).build(); if (table.getCreateTime() > 0) { hiveTable.setCreateTime(table.getCreateTime()); } if (table.getSd().getCols() != null) { hiveTable.setColumns(getColumns(table.getSd().getCols())); } if (table.getSd().getBucketCols() != null) { hiveTable.setBucketColumns(table.getSd().getBucketCols()); } return hiveTable; } }
HiveMetaStoreUtils { public static HiveTable getHiveTable(Table table) { State tableProps = getTableProps(table); State storageProps = getStorageProps(table.getSd()); State serDeProps = getSerDeProps(table.getSd().getSerdeInfo()); HiveTable hiveTable = new HiveTable.Builder().withDbName(table.getDbName()).withTableName(table.getTableName()) .withPartitionKeys(getColumns(table.getPartitionKeys())).withProps(tableProps).withStorageProps(storageProps) .withSerdeProps(serDeProps).build(); if (table.getCreateTime() > 0) { hiveTable.setCreateTime(table.getCreateTime()); } if (table.getSd().getCols() != null) { hiveTable.setColumns(getColumns(table.getSd().getCols())); } if (table.getSd().getBucketCols() != null) { hiveTable.setBucketColumns(table.getSd().getBucketCols()); } return hiveTable; } private  HiveMetaStoreUtils(); }
HiveMetaStoreUtils { public static HiveTable getHiveTable(Table table) { State tableProps = getTableProps(table); State storageProps = getStorageProps(table.getSd()); State serDeProps = getSerDeProps(table.getSd().getSerdeInfo()); HiveTable hiveTable = new HiveTable.Builder().withDbName(table.getDbName()).withTableName(table.getTableName()) .withPartitionKeys(getColumns(table.getPartitionKeys())).withProps(tableProps).withStorageProps(storageProps) .withSerdeProps(serDeProps).build(); if (table.getCreateTime() > 0) { hiveTable.setCreateTime(table.getCreateTime()); } if (table.getSd().getCols() != null) { hiveTable.setColumns(getColumns(table.getSd().getCols())); } if (table.getSd().getBucketCols() != null) { hiveTable.setBucketColumns(table.getSd().getBucketCols()); } return hiveTable; } private  HiveMetaStoreUtils(); static Table getTable(HiveTable hiveTable); static HiveTable getHiveTable(Table table); static Partition getPartition(HivePartition hivePartition); static HivePartition getHivePartition(Partition partition); static Map<String, String> getParameters(State props); static SerDeInfo getSerDeInfo(HiveRegistrationUnit unit); static State getTableProps(Table table); }
HiveMetaStoreUtils { public static HiveTable getHiveTable(Table table) { State tableProps = getTableProps(table); State storageProps = getStorageProps(table.getSd()); State serDeProps = getSerDeProps(table.getSd().getSerdeInfo()); HiveTable hiveTable = new HiveTable.Builder().withDbName(table.getDbName()).withTableName(table.getTableName()) .withPartitionKeys(getColumns(table.getPartitionKeys())).withProps(tableProps).withStorageProps(storageProps) .withSerdeProps(serDeProps).build(); if (table.getCreateTime() > 0) { hiveTable.setCreateTime(table.getCreateTime()); } if (table.getSd().getCols() != null) { hiveTable.setColumns(getColumns(table.getSd().getCols())); } if (table.getSd().getBucketCols() != null) { hiveTable.setBucketColumns(table.getSd().getBucketCols()); } return hiveTable; } private  HiveMetaStoreUtils(); static Table getTable(HiveTable hiveTable); static HiveTable getHiveTable(Table table); static Partition getPartition(HivePartition hivePartition); static HivePartition getHivePartition(Partition partition); static Map<String, String> getParameters(State props); static SerDeInfo getSerDeInfo(HiveRegistrationUnit unit); static State getTableProps(Table table); static final String RUNTIME_PROPS; }