Java Code Examples for org.apache.hadoop.hive.metastore.api.Table#deepCopy()

The following examples show how to use org.apache.hadoop.hive.metastore.api.Table#deepCopy() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ThriftHiveMetastore.java    From presto with Apache License 2.0 5 votes vote down vote up
@Override
public void updateTableStatistics(HiveIdentity identity, String databaseName, String tableName, Function<PartitionStatistics, PartitionStatistics> update)
{
    Table originalTable = getTable(identity, databaseName, tableName)
            .orElseThrow(() -> new TableNotFoundException(new SchemaTableName(databaseName, tableName)));

    PartitionStatistics currentStatistics = getTableStatistics(identity, originalTable);
    PartitionStatistics updatedStatistics = update.apply(currentStatistics);

    Table modifiedTable = originalTable.deepCopy();
    HiveBasicStatistics basicStatistics = updatedStatistics.getBasicStatistics();
    modifiedTable.setParameters(updateStatisticsParameters(modifiedTable.getParameters(), basicStatistics));
    alterTable(identity, databaseName, tableName, modifiedTable);

    io.prestosql.plugin.hive.metastore.Table table = fromMetastoreApiTable(modifiedTable);
    OptionalLong rowCount = basicStatistics.getRowCount();
    List<ColumnStatisticsObj> metastoreColumnStatistics = updatedStatistics.getColumnStatistics().entrySet().stream()
            .flatMap(entry -> {
                Optional<Column> column = table.getColumn(entry.getKey());
                if (column.isEmpty() && isAvroTableWithSchemaSet(modifiedTable)) {
                    // Avro table can have different effective schema than declared in metastore. Still, metastore does not allow
                    // to store statistics for a column it does not know about.
                    return Stream.of();
                }

                HiveType type = column.orElseThrow(() -> new IllegalStateException("Column not found: " + entry.getKey())).getType();
                return Stream.of(createMetastoreColumnStatistics(entry.getKey(), type, entry.getValue(), rowCount));
            })
            .collect(toImmutableList());
    if (!metastoreColumnStatistics.isEmpty()) {
        setTableColumnStatistics(identity, databaseName, tableName, metastoreColumnStatistics);
    }
    Set<String> removedColumnStatistics = difference(currentStatistics.getColumnStatistics().keySet(), updatedStatistics.getColumnStatistics().keySet());
    removedColumnStatistics.forEach(column -> deleteTableColumnStatistics(identity, databaseName, tableName, column));
}
 
Example 2
Source File: InMemoryThriftMetastore.java    From presto with Apache License 2.0 5 votes vote down vote up
@Override
public synchronized void createTable(HiveIdentity identity, Table table)
{
    TableType tableType = TableType.valueOf(table.getTableType());
    checkArgument(EnumSet.of(MANAGED_TABLE, EXTERNAL_TABLE, VIRTUAL_VIEW).contains(tableType), "Invalid table type: %s", tableType);

    if (tableType == VIRTUAL_VIEW) {
        checkArgument(table.getSd().getLocation() == null, "Storage location for view must be null");
    }
    else {
        File directory = new File(new Path(table.getSd().getLocation()).toUri());
        checkArgument(directory.exists(), "Table directory does not exist");
        if (tableType == MANAGED_TABLE) {
            checkArgument(isParentDir(directory, baseDirectory), "Table directory must be inside of the metastore base directory");
        }
    }

    SchemaTableName schemaTableName = new SchemaTableName(table.getDbName(), table.getTableName());
    Table tableCopy = table.deepCopy();

    if (relations.putIfAbsent(schemaTableName, tableCopy) != null) {
        throw new TableAlreadyExistsException(schemaTableName);
    }

    if (tableType == VIRTUAL_VIEW) {
        views.put(schemaTableName, tableCopy);
    }

    PrincipalPrivilegeSet privileges = table.getPrivileges();
    if (privileges != null) {
        throw new UnsupportedOperationException();
    }
}
 
Example 3
Source File: HiveMetaStoreBasedRegister.java    From incubator-gobblin with Apache License 2.0 5 votes vote down vote up
/**
 * Sets create time if not already set.
 */
private Table gettableWithCreateTime(Table table, int createTime) {
  if (table.isSetCreateTime() && table.getCreateTime() > 0) {
    return table;
  }
  Table actualtable = table.deepCopy();
  actualtable.setCreateTime(createTime);
  return actualtable;
}