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);
}
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));
}
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();
}
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;
}
}
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);
}
}
Aggregations