Search in sources :

Example 91 with PrestoException

use of com.facebook.presto.spi.PrestoException in project presto by prestodb.

the class RaptorMetadata method getDistributionInfo.

private DistributionInfo getDistributionInfo(long distributionId, Map<String, RaptorColumnHandle> columnHandleMap, Map<String, Object> properties) {
    Distribution distribution = dao.getDistribution(distributionId);
    if (distribution == null) {
        throw new PrestoException(RAPTOR_ERROR, "Distribution ID does not exist: " + distributionId);
    }
    List<RaptorColumnHandle> bucketColumnHandles = getBucketColumnHandles(getBucketColumns(properties), columnHandleMap);
    return new DistributionInfo(distributionId, distribution.getBucketCount(), bucketColumnHandles);
}
Also used : Distribution(com.facebook.presto.raptor.metadata.Distribution) PrestoException(com.facebook.presto.spi.PrestoException)

Example 92 with PrestoException

use of com.facebook.presto.spi.PrestoException in project presto by prestodb.

the class RaptorMetadata method getOrCreateDistribution.

private Optional<DistributionInfo> getOrCreateDistribution(Map<String, RaptorColumnHandle> columnHandleMap, Map<String, Object> properties) {
    OptionalInt bucketCount = getBucketCount(properties);
    List<RaptorColumnHandle> bucketColumnHandles = getBucketColumnHandles(getBucketColumns(properties), columnHandleMap);
    if (bucketCount.isPresent() && bucketColumnHandles.isEmpty()) {
        throw new PrestoException(INVALID_TABLE_PROPERTY, format("Must specify '%s' along with '%s'", BUCKETED_ON_PROPERTY, BUCKET_COUNT_PROPERTY));
    }
    if (!bucketCount.isPresent() && !bucketColumnHandles.isEmpty()) {
        throw new PrestoException(INVALID_TABLE_PROPERTY, format("Must specify '%s' along with '%s'", BUCKET_COUNT_PROPERTY, BUCKETED_ON_PROPERTY));
    }
    ImmutableList.Builder<Type> bucketColumnTypes = ImmutableList.builder();
    for (RaptorColumnHandle column : bucketColumnHandles) {
        validateBucketType(column.getColumnType());
        bucketColumnTypes.add(column.getColumnType());
    }
    long distributionId;
    String distributionName = getDistributionName(properties);
    if (distributionName != null) {
        if (bucketColumnHandles.isEmpty()) {
            throw new PrestoException(INVALID_TABLE_PROPERTY, format("Must specify '%s' along with '%s'", BUCKETED_ON_PROPERTY, DISTRIBUTION_NAME_PROPERTY));
        }
        Distribution distribution = dao.getDistribution(distributionName);
        if (distribution == null) {
            if (!bucketCount.isPresent()) {
                throw new PrestoException(INVALID_TABLE_PROPERTY, "Distribution does not exist and bucket count is not specified");
            }
            distribution = getOrCreateDistribution(distributionName, bucketColumnTypes.build(), bucketCount.getAsInt());
        }
        distributionId = distribution.getId();
        if (bucketCount.isPresent() && (distribution.getBucketCount() != bucketCount.getAsInt())) {
            throw new PrestoException(INVALID_TABLE_PROPERTY, "Bucket count must match distribution");
        }
        if (!distribution.getColumnTypes().equals(bucketColumnTypes.build())) {
            throw new PrestoException(INVALID_TABLE_PROPERTY, "Bucket column types must match distribution");
        }
    } else if (bucketCount.isPresent()) {
        String types = Distribution.serializeColumnTypes(bucketColumnTypes.build());
        distributionId = dao.insertDistribution(null, types, bucketCount.getAsInt());
    } else {
        return Optional.empty();
    }
    shardManager.createBuckets(distributionId, bucketCount.getAsInt());
    return Optional.of(new DistributionInfo(distributionId, bucketCount.getAsInt(), bucketColumnHandles));
}
Also used : Type(com.facebook.presto.spi.type.Type) RaptorBucketFunction.validateBucketType(com.facebook.presto.raptor.RaptorBucketFunction.validateBucketType) ImmutableList(com.google.common.collect.ImmutableList) Distribution(com.facebook.presto.raptor.metadata.Distribution) PrestoException(com.facebook.presto.spi.PrestoException) OptionalInt(java.util.OptionalInt)

Example 93 with PrestoException

use of com.facebook.presto.spi.PrestoException in project presto by prestodb.

the class OrcFileWriter method appendRow.

public void appendRow(Row row) {
    List<Object> columns = row.getColumns();
    checkArgument(columns.size() == columnTypes.size());
    for (int channel = 0; channel < columns.size(); channel++) {
        tableInspector.setStructFieldData(orcRow, structFields.get(channel), columns.get(channel));
    }
    try {
        recordWriter.write(serializer.serialize(orcRow, tableInspector));
    } catch (IOException e) {
        throw new PrestoException(RAPTOR_ERROR, "Failed to write record", e);
    }
    rowCount++;
    uncompressedSize += row.getSizeInBytes();
}
Also used : PrestoException(com.facebook.presto.spi.PrestoException) IOException(java.io.IOException)

Example 94 with PrestoException

use of com.facebook.presto.spi.PrestoException in project presto by prestodb.

the class OrcStorageManager method getPageSource.

@Override
public ConnectorPageSource getPageSource(UUID shardUuid, OptionalInt bucketNumber, List<Long> columnIds, List<Type> columnTypes, TupleDomain<RaptorColumnHandle> effectivePredicate, ReaderAttributes readerAttributes, OptionalLong transactionId) {
    OrcDataSource dataSource = openShard(shardUuid, readerAttributes);
    AggregatedMemoryContext systemMemoryUsage = new AggregatedMemoryContext();
    try {
        OrcReader reader = new OrcReader(dataSource, new OrcMetadataReader(), readerAttributes.getMaxMergeDistance(), readerAttributes.getMaxReadSize());
        Map<Long, Integer> indexMap = columnIdIndex(reader.getColumnNames());
        ImmutableMap.Builder<Integer, Type> includedColumns = ImmutableMap.builder();
        ImmutableList.Builder<Integer> columnIndexes = ImmutableList.builder();
        for (int i = 0; i < columnIds.size(); i++) {
            long columnId = columnIds.get(i);
            if (isHiddenColumn(columnId)) {
                columnIndexes.add(toSpecialIndex(columnId));
                continue;
            }
            Integer index = indexMap.get(columnId);
            if (index == null) {
                columnIndexes.add(NULL_COLUMN);
            } else {
                columnIndexes.add(index);
                includedColumns.put(index, columnTypes.get(i));
            }
        }
        OrcPredicate predicate = getPredicate(effectivePredicate, indexMap);
        OrcRecordReader recordReader = reader.createRecordReader(includedColumns.build(), predicate, UTC, systemMemoryUsage);
        Optional<ShardRewriter> shardRewriter = Optional.empty();
        if (transactionId.isPresent()) {
            shardRewriter = Optional.of(createShardRewriter(transactionId.getAsLong(), bucketNumber, shardUuid));
        }
        return new OrcPageSource(shardRewriter, recordReader, dataSource, columnIds, columnTypes, columnIndexes.build(), shardUuid, bucketNumber, systemMemoryUsage);
    } catch (IOException | RuntimeException e) {
        closeQuietly(dataSource);
        throw new PrestoException(RAPTOR_ERROR, "Failed to create page source for shard " + shardUuid, e);
    } catch (Throwable t) {
        closeQuietly(dataSource);
        throw t;
    }
}
Also used : FileOrcDataSource(com.facebook.presto.orc.FileOrcDataSource) OrcDataSource(com.facebook.presto.orc.OrcDataSource) ImmutableList(com.google.common.collect.ImmutableList) OrcMetadataReader(com.facebook.presto.orc.metadata.OrcMetadataReader) PrestoException(com.facebook.presto.spi.PrestoException) IOException(java.io.IOException) OrcRecordReader(com.facebook.presto.orc.OrcRecordReader) AggregatedMemoryContext(com.facebook.presto.orc.memory.AggregatedMemoryContext) ImmutableMap(com.google.common.collect.ImmutableMap) Type(com.facebook.presto.spi.type.Type) VarcharType.createUnboundedVarcharType(com.facebook.presto.spi.type.VarcharType.createUnboundedVarcharType) DecimalType(com.facebook.presto.spi.type.DecimalType) OrcType(com.facebook.presto.orc.metadata.OrcType) OrcReader(com.facebook.presto.orc.OrcReader) OptionalLong(java.util.OptionalLong) TupleDomainOrcPredicate(com.facebook.presto.orc.TupleDomainOrcPredicate) OrcPredicate(com.facebook.presto.orc.OrcPredicate)

Example 95 with PrestoException

use of com.facebook.presto.spi.PrestoException in project presto by prestodb.

the class OrcStorageManager method writeShard.

private void writeShard(UUID shardUuid) {
    if (backupStore.isPresent() && !backupStore.get().shardExists(shardUuid)) {
        throw new PrestoException(RAPTOR_ERROR, "Backup does not exist after write");
    }
    File stagingFile = storageService.getStagingFile(shardUuid);
    File storageFile = storageService.getStorageFile(shardUuid);
    storageService.createParents(storageFile);
    try {
        Files.move(stagingFile.toPath(), storageFile.toPath(), ATOMIC_MOVE);
    } catch (IOException e) {
        throw new PrestoException(RAPTOR_ERROR, "Failed to move shard file", e);
    }
}
Also used : PrestoException(com.facebook.presto.spi.PrestoException) IOException(java.io.IOException) File(java.io.File)

Aggregations

PrestoException (com.facebook.presto.spi.PrestoException)273 IOException (java.io.IOException)58 Type (com.facebook.presto.spi.type.Type)48 ImmutableList (com.google.common.collect.ImmutableList)40 SchemaTableName (com.facebook.presto.spi.SchemaTableName)32 ArrayList (java.util.ArrayList)32 List (java.util.List)28 Path (org.apache.hadoop.fs.Path)28 Map (java.util.Map)24 Slice (io.airlift.slice.Slice)23 TableNotFoundException (com.facebook.presto.spi.TableNotFoundException)22 SqlType (com.facebook.presto.spi.function.SqlType)22 ImmutableMap (com.google.common.collect.ImmutableMap)22 Optional (java.util.Optional)20 ColumnMetadata (com.facebook.presto.spi.ColumnMetadata)19 Block (com.facebook.presto.spi.block.Block)19 Test (org.testng.annotations.Test)19 ConnectorSession (com.facebook.presto.spi.ConnectorSession)17 Table (com.facebook.presto.hive.metastore.Table)15 Session (com.facebook.presto.Session)14