Search in sources :

Example 1 with PartitionStatistics

use of io.prestosql.plugin.hive.PartitionStatistics in project hetu-core by openlookeng.

the class CarbondataMetadata method createTable.

@Override
public void createTable(ConnectorSession session, ConnectorTableMetadata tableMetadata, boolean ignoreExisting) {
    SchemaTableName localSchemaTableName = tableMetadata.getTable();
    String localSchemaName = localSchemaTableName.getSchemaName();
    String tableName = localSchemaTableName.getTableName();
    this.user = session.getUser();
    this.schemaName = localSchemaName;
    currentState = State.CREATE_TABLE;
    List<String> partitionedBy = new ArrayList<String>();
    List<SortingColumn> sortBy = new ArrayList<SortingColumn>();
    List<HiveColumnHandle> columnHandles = new ArrayList<HiveColumnHandle>();
    Map<String, String> tableProperties = new HashMap<String, String>();
    getParametersForCreateTable(session, tableMetadata, partitionedBy, sortBy, columnHandles, tableProperties);
    metastore.getDatabase(localSchemaName).orElseThrow(() -> new SchemaNotFoundException(localSchemaName));
    BaseStorageFormat hiveStorageFormat = CarbondataTableProperties.getCarbondataStorageFormat(tableMetadata.getProperties());
    // it will get final path to create carbon table
    LocationHandle locationHandle = getCarbonDataTableCreationPath(session, tableMetadata, HiveWriteUtils.OpertionType.CREATE_TABLE);
    Path targetPath = locationService.getQueryWriteInfo(locationHandle).getTargetPath();
    AbsoluteTableIdentifier finalAbsoluteTableIdentifier = AbsoluteTableIdentifier.from(targetPath.toString(), new CarbonTableIdentifier(localSchemaName, tableName, UUID.randomUUID().toString()));
    hdfsEnvironment.doAs(session.getUser(), () -> {
        initialConfiguration = ConfigurationUtils.toJobConf(this.hdfsEnvironment.getConfiguration(new HdfsEnvironment.HdfsContext(session, localSchemaName, tableName), new Path(locationHandle.getJsonSerializableTargetPath())));
        CarbondataMetadataUtils.createMetaDataFolderSchemaFile(hdfsEnvironment, session, columnHandles, finalAbsoluteTableIdentifier, partitionedBy, sortBy.stream().map(s -> s.getColumnName().toLowerCase(Locale.ENGLISH)).collect(toList()), targetPath.toString(), initialConfiguration);
        this.tableStorageLocation = Optional.of(targetPath.toString());
        try {
            Map<String, String> serdeParameters = initSerDeProperties(tableName);
            Table localTable = buildTableObject(session.getQueryId(), localSchemaName, tableName, session.getUser(), columnHandles, hiveStorageFormat, partitionedBy, Optional.empty(), tableProperties, targetPath, // carbon table is set as external table
            true, prestoVersion, serdeParameters);
            PrincipalPrivileges principalPrivileges = MetastoreUtil.buildInitialPrivilegeSet(localTable.getOwner());
            HiveBasicStatistics basicStatistics = localTable.getPartitionColumns().isEmpty() ? HiveBasicStatistics.createZeroStatistics() : HiveBasicStatistics.createEmptyStatistics();
            metastore.createTable(session, localTable, principalPrivileges, Optional.empty(), ignoreExisting, new PartitionStatistics(basicStatistics, ImmutableMap.of()));
        } catch (RuntimeException ex) {
            throw new PrestoException(GENERIC_INTERNAL_ERROR, format("Error: creating table: %s ", ex.getMessage()), ex);
        }
    });
}
Also used : CarbonTablePath(org.apache.carbondata.core.util.path.CarbonTablePath) Path(org.apache.hadoop.fs.Path) SortingColumn(io.prestosql.plugin.hive.metastore.SortingColumn) Table(io.prestosql.plugin.hive.metastore.Table) CarbonTable(org.apache.carbondata.core.metadata.schema.table.CarbonTable) PrincipalPrivileges(io.prestosql.plugin.hive.metastore.PrincipalPrivileges) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) PrestoException(io.prestosql.spi.PrestoException) HiveBasicStatistics(io.prestosql.plugin.hive.HiveBasicStatistics) SchemaTableName(io.prestosql.spi.connector.SchemaTableName) LocationHandle(io.prestosql.plugin.hive.LocationHandle) HdfsEnvironment(io.prestosql.plugin.hive.HdfsEnvironment) CarbonTableIdentifier(org.apache.carbondata.core.metadata.CarbonTableIdentifier) AbsoluteTableIdentifier(org.apache.carbondata.core.metadata.AbsoluteTableIdentifier) PartitionStatistics(io.prestosql.plugin.hive.PartitionStatistics) SchemaNotFoundException(io.prestosql.spi.connector.SchemaNotFoundException) BaseStorageFormat(io.prestosql.plugin.hive.BaseStorageFormat) HiveColumnHandle(io.prestosql.plugin.hive.HiveColumnHandle)

Example 2 with PartitionStatistics

use of io.prestosql.plugin.hive.PartitionStatistics in project hetu-core by openlookeng.

the class InMemoryThriftMetastore method getTableStatistics.

private PartitionStatistics getTableStatistics(HiveIdentity identity, String databaseName, String tableName) {
    SchemaTableName schemaTableName = new SchemaTableName(databaseName, tableName);
    PartitionStatistics statistics = columnStatistics.get(schemaTableName);
    if (statistics == null) {
        statistics = new PartitionStatistics(createEmptyStatistics(), ImmutableMap.of());
    }
    return statistics;
}
Also used : PartitionStatistics(io.prestosql.plugin.hive.PartitionStatistics) SchemaTableName(io.prestosql.spi.connector.SchemaTableName)

Example 3 with PartitionStatistics

use of io.prestosql.plugin.hive.PartitionStatistics in project hetu-core by openlookeng.

the class TestSemiTransactionalHiveMetastore method updatePartitionsStatistics.

private void updatePartitionsStatistics() {
    Map<String, Function<PartitionStatistics, PartitionStatistics>> partNamesUpdateMap = new HashMap<>();
    List<PartitionStatistics> statistics = ImmutableList.of(STATISTICS_1, STATISTICS_1);
    for (int index = 0; index < partitions.size(); index++) {
        PartitionStatistics partitionStatistics = statistics.get(index);
        partNamesUpdateMap.put(partitions.get(index), actualStatistics -> partitionStatistics);
    }
    thriftHiveMetastore.updatePartitionsStatistics(IDENTITY, MockThriftMetastoreClient.TEST_DATABASE, MockThriftMetastoreClient.TEST_TABLE_UP_NAME, partNamesUpdateMap);
}
Also used : Function(java.util.function.Function) HashMap(java.util.HashMap) PartitionStatistics(io.prestosql.plugin.hive.PartitionStatistics)

Example 4 with PartitionStatistics

use of io.prestosql.plugin.hive.PartitionStatistics in project hetu-core by openlookeng.

the class ThriftHiveMetastore method storePartitionColumnStatistics.

private void storePartitionColumnStatistics(HiveIdentity identity, String databaseName, String tableName, String partitionName, PartitionWithStatistics partitionWithStatistics) {
    PartitionStatistics statistics = partitionWithStatistics.getStatistics();
    Map<String, HiveColumnStatistics> columnStatistics = statistics.getColumnStatistics();
    if (columnStatistics.isEmpty()) {
        return;
    }
    Map<String, HiveType> columnTypes = partitionWithStatistics.getPartition().getColumns().stream().collect(toImmutableMap(Column::getName, Column::getType));
    setPartitionColumnStatistics(identity, databaseName, tableName, partitionName, columnTypes, columnStatistics, statistics.getBasicStatistics().getRowCount());
}
Also used : PartitionStatistics(io.prestosql.plugin.hive.PartitionStatistics) HiveColumnStatistics(io.prestosql.plugin.hive.metastore.HiveColumnStatistics) HiveType(io.prestosql.plugin.hive.HiveType)

Example 5 with PartitionStatistics

use of io.prestosql.plugin.hive.PartitionStatistics in project hetu-core by openlookeng.

the class ThriftHiveMetastore method getTableStatistics.

@Override
public PartitionStatistics getTableStatistics(HiveIdentity identity, Table table) {
    List<String> dataColumns = table.getSd().getCols().stream().map(FieldSchema::getName).collect(toImmutableList());
    HiveBasicStatistics basicStatistics = ThriftMetastoreUtil.getHiveBasicStatistics(table.getParameters());
    Map<String, HiveColumnStatistics> columnStatistics = getTableColumnStatistics(identity, table.getDbName(), table.getTableName(), dataColumns, basicStatistics.getRowCount());
    return new PartitionStatistics(basicStatistics, columnStatistics);
}
Also used : PartitionStatistics(io.prestosql.plugin.hive.PartitionStatistics) HiveColumnStatistics(io.prestosql.plugin.hive.metastore.HiveColumnStatistics) HiveBasicStatistics(io.prestosql.plugin.hive.HiveBasicStatistics)

Aggregations

PartitionStatistics (io.prestosql.plugin.hive.PartitionStatistics)32 PrestoException (io.prestosql.spi.PrestoException)17 HiveBasicStatistics (io.prestosql.plugin.hive.HiveBasicStatistics)16 SchemaTableName (io.prestosql.spi.connector.SchemaTableName)16 HivePartition (io.prestosql.plugin.hive.HivePartition)10 HiveIdentity (io.prestosql.plugin.hive.authentication.HiveIdentity)9 TableNotFoundException (io.prestosql.spi.connector.TableNotFoundException)9 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)8 ImmutableMap (com.google.common.collect.ImmutableMap)8 PartitionNotFoundException (io.prestosql.plugin.hive.PartitionNotFoundException)8 ArrayList (java.util.ArrayList)8 HiveColumnStatistics (io.prestosql.plugin.hive.metastore.HiveColumnStatistics)7 List (java.util.List)7 OptionalLong (java.util.OptionalLong)7 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)6 ImmutableList (com.google.common.collect.ImmutableList)6 Logger (io.airlift.log.Logger)6 HiveErrorCode (io.prestosql.plugin.hive.HiveErrorCode)6 ImmutableMap.toImmutableMap (com.google.common.collect.ImmutableMap.toImmutableMap)5 Table (io.prestosql.plugin.hive.metastore.Table)5