org.apache.hadoop.hive.metastore.api.Table类的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(14.8k)|赞(0)|评价(0)|浏览(356)

本文整理了Java中org.apache.hadoop.hive.metastore.api.Table类的一些代码示例,展示了Table类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Table类的具体详情如下:
包路径:org.apache.hadoop.hive.metastore.api.Table
类名称:Table

Table介绍

暂无

代码示例

代码示例来源:origin: apache/hive

  1. public Path getDataLocation() {
  2. if (table.isPartitioned()) {
  3. if (tPartition.getSd() == null)
  4. return null;
  5. else
  6. return new Path(tPartition.getSd().getLocation());
  7. } else {
  8. if (table.getTTable() == null || table.getTTable().getSd() == null)
  9. return null;
  10. else
  11. return new Path(table.getTTable().getSd().getLocation());
  12. }
  13. }

代码示例来源:origin: prestodb/presto

  1. public static Table fromMetastoreApiTable(org.apache.hadoop.hive.metastore.api.Table table, List<FieldSchema> schema)
  2. {
  3. StorageDescriptor storageDescriptor = table.getSd();
  4. if (storageDescriptor == null) {
  5. throw new PrestoException(HIVE_INVALID_METADATA, "Table is missing storage descriptor");
  6. }
  7. Table.Builder tableBuilder = Table.builder()
  8. .setDatabaseName(table.getDbName())
  9. .setTableName(table.getTableName())
  10. .setOwner(nullToEmpty(table.getOwner()))
  11. .setTableType(table.getTableType())
  12. .setDataColumns(schema.stream()
  13. .map(ThriftMetastoreUtil::fromMetastoreApiFieldSchema)
  14. .collect(toList()))
  15. .setPartitionColumns(table.getPartitionKeys().stream()
  16. .map(ThriftMetastoreUtil::fromMetastoreApiFieldSchema)
  17. .collect(toList()))
  18. .setParameters(table.getParameters() == null ? ImmutableMap.of() : table.getParameters())
  19. .setViewOriginalText(Optional.ofNullable(emptyToNull(table.getViewOriginalText())))
  20. .setViewExpandedText(Optional.ofNullable(emptyToNull(table.getViewExpandedText())));
  21. fromMetastoreApiStorageDescriptor(storageDescriptor, tableBuilder.getStorageBuilder(), table.getTableName());
  22. return tableBuilder.build();
  23. }

代码示例来源:origin: prestodb/presto

  1. public static org.apache.hadoop.hive.metastore.api.Table toMetastoreApiTable(Table table, PrincipalPrivileges privileges)
  2. {
  3. org.apache.hadoop.hive.metastore.api.Table result = new org.apache.hadoop.hive.metastore.api.Table();
  4. result.setDbName(table.getDatabaseName());
  5. result.setTableName(table.getTableName());
  6. result.setOwner(table.getOwner());
  7. result.setTableType(table.getTableType());
  8. result.setParameters(table.getParameters());
  9. result.setPartitionKeys(table.getPartitionColumns().stream().map(ThriftMetastoreUtil::toMetastoreApiFieldSchema).collect(toList()));
  10. result.setSd(makeStorageDescriptor(table.getTableName(), table.getDataColumns(), table.getStorage()));
  11. result.setPrivileges(toMetastoreApiPrincipalPrivilegeSet(table.getOwner(), privileges));
  12. result.setViewOriginalText(table.getViewOriginalText().orElse(null));
  13. result.setViewExpandedText(table.getViewExpandedText().orElse(null));
  14. return result;
  15. }

代码示例来源:origin: apache/hive

  1. public static Properties getTableMetadata(
  2. org.apache.hadoop.hive.metastore.api.Table table) {
  3. return MetaStoreUtils.getSchema(table.getSd(), table.getSd(), table
  4. .getParameters(), table.getDbName(), table.getTableName(), table.getPartitionKeys());
  5. }

代码示例来源:origin: apache/hive

  1. private org.apache.hadoop.hive.metastore.api.Table deepCopyAndLowerCaseTable(
  2. org.apache.hadoop.hive.metastore.api.Table tbl) {
  3. org.apache.hadoop.hive.metastore.api.Table newCopy = deepCopy(tbl);
  4. newCopy.setDbName(newCopy.getDbName().toLowerCase());
  5. newCopy.setTableName(newCopy.getTableName().toLowerCase());
  6. return newCopy;
  7. }

代码示例来源:origin: apache/hive

  1. public JSONDropPartitionMessage(String server, String servicePrincipal, Table tableObj,
  2. List<Map<String, String>> partitionKeyValues, long timestamp) {
  3. this(server, servicePrincipal, tableObj.getDbName(), tableObj.getTableName(),
  4. tableObj.getTableType(), partitionKeyValues, timestamp);
  5. try {
  6. this.tableObjJson = MessageBuilder.createTableObjJson(tableObj);
  7. } catch (TException e) {
  8. throw new IllegalArgumentException("Could not serialize: ", e);
  9. }
  10. }

代码示例来源:origin: apache/hive

  1. @Test
  2. public void testDropTableWithPurge() throws Exception {
  3. Table table = testTables[0];
  4. client.dropTable(table.getDbName(), table.getTableName(), true, true, true);
  5. Assert.assertFalse("Table path should be removed",
  6. metaStore.isPathExists(new Path(table.getSd().getLocation())));
  7. Assert.assertFalse("Table path should not be in trash",
  8. metaStore.isPathExistsInTrash(new Path(table.getSd().getLocation())));
  9. }

代码示例来源:origin: apache/hive

  1. MetaException, NoSuchObjectException, TException {
  2. boolean isVirtualTable = tbl.getTableName().startsWith(SemanticAnalyzer.VALUES_TMP_TABLE_NAME_PREFIX);
  3. String dbName = tbl.getDbName();
  4. String tblName = tbl.getTableName();
  5. Map<String, Table> tables = getTempTablesForDatabase(dbName, tblName);
  6. if (tables != null && tables.containsKey(tblName)) {
  7. if (tbl.getSd().getLocation() == null) {
  8. tbl.getSd().setLocation(SessionState.generateTempTableLocation(conf));
  9. Path tblPath = wh.getDnsPath(new Path(tbl.getSd().getLocation()));
  10. if (tblPath == null) {
  11. throw new MetaException("Temp table path not set for " + tbl.getTableName());
  12. } else {
  13. if (!wh.isDir(tblPath)) {
  14. tbl.getSd().setLocation(tblPath.toString());
  15. Table tTable = new Table(tbl);
  16. if (!isVirtualTable) {
  17. StatsSetupConst.setStatsStateForCreateTable(tbl.getParameters(),
  18. org.apache.hadoop.hive.metastore.utils.MetaStoreUtils.getColumnNamesForTable(tbl), StatsSetupConst.TRUE);

代码示例来源:origin: apache/hive

  1. private String getFinalDynamicPartitionDestination(Table table, Map<String, String> partKVs,
  2. OutputJobInfo jobInfo) {
  3. Path partPath = new Path(table.getTTable().getSd().getLocation());
  4. if (!customDynamicLocationUsed) {
  5. // file:///tmp/hcat_junit_warehouse/employee/_DYN0.7770480401313761/emp_country=IN/emp_state=KA ->
  6. // file:///tmp/hcat_junit_warehouse/employee/emp_country=IN/emp_state=KA
  7. for (FieldSchema partKey : table.getPartitionKeys()) {
  8. partPath = constructPartialPartPath(partPath, partKey.getName().toLowerCase(), partKVs);
  9. }
  10. return partPath.toString();
  11. } else {
  12. // if custom root specified, update the parent path
  13. if (jobInfo.getCustomDynamicRoot() != null
  14. && jobInfo.getCustomDynamicRoot().length() > 0) {
  15. partPath = new Path(partPath, jobInfo.getCustomDynamicRoot());
  16. }
  17. return new Path(partPath, HCatFileUtil.resolveCustomPath(jobInfo, partKVs, false)).toString();
  18. }
  19. }

代码示例来源:origin: apache/hive

  1. FileSystem fs = null;
  2. Table tbl = tableEvent.getTable();
  3. String name = tbl.getTableName();
  4. org.apache.hadoop.hive.ql.metadata.Table mTbl = new org.apache.hadoop.hive.ql.metadata.Table(
  5. tbl);
  6. IHMSHandler handler = tableEvent.getHandler();
  7. Configuration conf = handler.getConf();
  8. Warehouse wh = new Warehouse(conf);
  9. Path tblPath = new Path(tbl.getSd().getLocation());
  10. fs = wh.getFs(tblPath);
  11. Date now = new Date();
  12. exportPath = fs.getHomeDirectory();
  13. } else {
  14. exportPath = new Path(exportPathString);
  15. Path metaPath = new Path(exportPath, name + "." + dateString);
  16. LOG.info("Exporting the metadata of table " + tbl.toString() + " to path "
  17. + metaPath.toString());
  18. try {

代码示例来源:origin: apache/hive

  1. @Test
  2. public void testAlterTableChangeCols() throws Exception {
  3. Table originalTable = partitionedTable;
  4. Table newTable = originalTable.deepCopy();
  5. List<FieldSchema> cols = newTable.getSd().getCols();
  6. // Change a column
  7. cols.get(0).setName("modified_col");
  8. // Remove a column
  9. cols.remove(1);
  10. // Add a new column
  11. cols.add(new FieldSchema("new_col", "int", null));
  12. // Store the changes
  13. client.alter_table(originalTable.getDbName(), originalTable.getTableName(), newTable);
  14. Table alteredTable = client.getTable(newTable.getDbName(), newTable.getTableName());
  15. Assert.assertTrue("Original table directory should be kept",
  16. metaStore.isPathExists(new Path(originalTable.getSd().getLocation())));
  17. // The following data might be changed
  18. alteredTable.setParameters(newTable.getParameters());
  19. Assert.assertEquals("The table data should be the same", newTable, alteredTable);
  20. // Modify partition column type, and comment
  21. newTable.getPartitionKeys().get(0).setType("string");
  22. newTable.getPartitionKeys().get(0).setComment("changed comment");
  23. client.alter_table(originalTable.getDbName(), originalTable.getTableName(), newTable);
  24. alteredTable = client.getTable(newTable.getDbName(), newTable.getTableName());
  25. // The following data might be changed
  26. alteredTable.setParameters(newTable.getParameters());
  27. Assert.assertEquals("The table data should be the same", newTable, alteredTable);
  28. }

代码示例来源:origin: apache/hive

  1. if (!table.isImmutable()){
  2. return;
  3. if (table.getPartitionKeys().size() > 0) {
  4. if (!outputInfo.isDynamicPartitioningUsed()) {
  5. List<String> partitionValues = getPartitionValueList(
  6. table, outputInfo.getPartitionValues());
  7. List<String> currentParts = client.listPartitionNames(outputInfo.getDatabaseName(),
  8. outputInfo.getTableName(), partitionValues, (short) 1);
  9. Path tablePath = new Path(table.getTTable().getSd().getLocation());
  10. FileSystem fs = tablePath.getFileSystem(context.getConfiguration());

代码示例来源:origin: apache/hive

  1. @Test
  2. public void testAlterTableExternalTableChangeLocation() throws Exception {
  3. Table originalTable = externalTable;
  4. // Change the location, and see the results
  5. Table newTable = originalTable.deepCopy();
  6. newTable.getSd().setLocation(newTable.getSd().getLocation() + "_modified");
  7. client.alter_table(originalTable.getDbName(), originalTable.getTableName(), newTable);
  8. Table alteredTable = client.getTable(newTable.getDbName(), newTable.getTableName());
  9. Assert.assertTrue("Original table directory should be kept",
  10. metaStore.isPathExists(new Path(originalTable.getSd().getLocation())));
  11. Assert.assertEquals("New location should be the new one", newTable.getSd().getLocation(),
  12. alteredTable.getSd().getLocation());
  13. Path dataFile = new Path(alteredTable.getSd().getLocation() + "/dataFile");
  14. Assert.assertFalse("The location should not contain data", metaStore.isPathExists(dataFile));
  15. // The extra parameters will be added on server side, so check that the required ones are
  16. // present
  17. for(String key: newTable.getParameters().keySet()) {
  18. Assert.assertEquals("parameters are present", newTable.getParameters().get(key),
  19. alteredTable.getParameters().get(key));
  20. }
  21. // The parameters are checked manually, so do not check them
  22. newTable.setParameters(alteredTable.getParameters());
  23. // The following data should be changed, other data should be the same
  24. newTable.getSd().setLocation(alteredTable.getSd().getLocation());
  25. Assert.assertEquals("The table data should be the same", newTable, alteredTable);
  26. }

代码示例来源:origin: apache/hive

  1. @Test
  2. public void testAlterTableExternalTable() throws Exception {
  3. Table originalTable = externalTable;
  4. String originalTableName = originalTable.getTableName();
  5. String originalDatabase = originalTable.getDbName();
  6. Table newTable = originalTable.deepCopy();
  7. newTable.setTableName("new_external_table_for_test");
  8. client.alter_table(originalDatabase, originalTableName, newTable);
  9. List<String> tableNames = client.getTables(originalDatabase, originalTableName);
  10. Assert.assertEquals("Original table should be removed", 0, tableNames.size());
  11. Assert.assertTrue("Original table directory should be kept",
  12. metaStore.isPathExists(new Path(originalTable.getSd().getLocation())));
  13. Table alteredTable = client.getTable(newTable.getDbName(), newTable.getTableName());
  14. Assert.assertEquals("New location should be the same", originalTable.getSd().getLocation(),
  15. alteredTable.getSd().getLocation());
  16. Path dataFile = new Path(alteredTable.getSd().getLocation() + "/dataFile");
  17. Assert.assertTrue("The location should contain data", metaStore.isPathExists(dataFile));
  18. // The extra parameters will be added on server side, so check that the required ones are
  19. // present
  20. for(String key: newTable.getParameters().keySet()) {
  21. Assert.assertEquals("parameters are present", newTable.getParameters().get(key),
  22. alteredTable.getParameters().get(key));
  23. }
  24. // The parameters are checked manually, so do not check them
  25. newTable.setParameters(alteredTable.getParameters());
  26. Assert.assertEquals("The table data should be the same", newTable, alteredTable);
  27. }

代码示例来源:origin: apache/hive

  1. private PartitionHelper newWarehousePartitionHelper() throws MetaException, WorkerException {
  2. String location = table.getTable().getSd().getLocation();
  3. Path tablePath = new Path(location);
  4. List<FieldSchema> partitionFields = table.getTable().getPartitionKeys();
  5. List<String> partitionColumns = new ArrayList<>(partitionFields.size());
  6. for (FieldSchema field : partitionFields) {
  7. partitionColumns.add(field.getName());
  8. }
  9. return new WarehousePartitionHelper(configuration, tablePath, partitionColumns);
  10. }

代码示例来源:origin: apache/hive

  1. private Path getPartitionLocation() throws NoSuchObjectException, MetaException, TException {
  2. Path partitionLocacation;
  3. if (partition.isEmpty()) {
  4. partitionLocacation = new Path(table.getSd().getLocation());
  5. } else {
  6. // TODO: calculate this instead. Just because we're writing to the location doesn't mean that it'll
  7. // always be wanted in the meta store right away.
  8. List<Partition> partitionEntries = metaStoreClient.listPartitions(table.getDbName(), table.getTableName(),
  9. partition, (short) 1);
  10. partitionLocacation = new Path(partitionEntries.get(0).getSd().getLocation());
  11. }
  12. return partitionLocacation;
  13. }

代码示例来源:origin: apache/hive

  1. @Test
  2. public void testTruncateTableUnpartitioned() throws Exception {
  3. // Unpartitioned table
  4. Path dataFile = new Path(testTables[0].getSd().getLocation() + "/dataFile");
  5. client.truncateTable(testTables[0].getDbName(), testTables[0].getTableName(), null);
  6. Assert.assertTrue("Location should exist",
  7. metaStore.isPathExists(new Path(testTables[0].getSd().getLocation())));
  8. Assert.assertFalse("DataFile should be removed", metaStore.isPathExists(dataFile));
  9. }

代码示例来源:origin: apache/hive

  1. /**
  2. * Make location in specified sd qualified.
  3. *
  4. * @param databaseName
  5. * Database name.
  6. * @param sd
  7. * Storage descriptor.
  8. * @param name
  9. * Object name.
  10. */
  11. public static void makeLocationQualified(String databaseName, Table table, HiveConf conf) throws HiveException {
  12. Path path = null;
  13. StorageDescriptor sd = table.getTTable().getSd();
  14. // If the table's location is currently unset, it is left unset, allowing the metastore to
  15. // fill in the table's location.
  16. // Note that the previous logic for some reason would make a special case if the DB was the
  17. // default database, and actually attempt to generate a location.
  18. // This seems incorrect and uncessary, since the metastore is just as able to fill in the
  19. // default table location in the case of the default DB, as it is for non-default DBs.
  20. if (sd.isSetLocation())
  21. {
  22. path = new Path(sd.getLocation());
  23. }
  24. if (path != null)
  25. {
  26. sd.setLocation(Utilities.getQualifiedPath(conf, path));
  27. }
  28. }

代码示例来源:origin: apache/hive

  1. @Test
  2. public void testAddPartitionSpecEmptyLocationInTableToo() throws Exception {
  3. Table table = createTable(DB_NAME, TABLE_NAME, getYearPartCol(), null);
  4. Partition partition = buildPartition(DB_NAME, TABLE_NAME, DEFAULT_YEAR_VALUE, "");
  5. PartitionSpecProxy partitionSpecProxy =
  6. buildPartitionSpec(DB_NAME, TABLE_NAME, null, Lists.newArrayList(partition));
  7. client.add_partitions_pspec(partitionSpecProxy);
  8. Partition resultPart =
  9. client.getPartition(DB_NAME, TABLE_NAME, Lists.newArrayList(DEFAULT_YEAR_VALUE));
  10. Assert.assertEquals(table.getSd().getLocation() + "/year=2017",
  11. resultPart.getSd().getLocation());
  12. Assert.assertTrue(metaStore.isPathExists(new Path(resultPart.getSd().getLocation())));
  13. }

代码示例来源:origin: apache/hive

  1. protected Table getDummyTable() throws SemanticException {
  2. Path dummyPath = createDummyFile();
  3. Table desc = new Table(DUMMY_DATABASE, DUMMY_TABLE);
  4. desc.getTTable().getSd().setLocation(dummyPath.toString());
  5. desc.getTTable().getSd().getSerdeInfo().setSerializationLib(NullStructSerDe.class.getName());
  6. desc.setInputFormatClass(NullRowsInputFormat.class);
  7. desc.setOutputFormatClass(HiveIgnoreKeyTextOutputFormat.class);
  8. return desc;
  9. }

相关文章

Table类方法