use of com.facebook.presto.common.NotSupportedException in project presto by prestodb.
the class OrcType method toOrcType.
private static List<OrcType> toOrcType(int nextFieldTypeIndex, Type type) {
if (BOOLEAN.equals(type)) {
return ImmutableList.of(new OrcType(OrcTypeKind.BOOLEAN));
}
if (TINYINT.equals(type)) {
return ImmutableList.of(new OrcType(OrcTypeKind.BYTE));
}
if (SMALLINT.equals(type)) {
return ImmutableList.of(new OrcType(OrcTypeKind.SHORT));
}
if (INTEGER.equals(type)) {
return ImmutableList.of(new OrcType(OrcTypeKind.INT));
}
if (BIGINT.equals(type)) {
return ImmutableList.of(new OrcType(OrcTypeKind.LONG));
}
if (DOUBLE.equals(type)) {
return ImmutableList.of(new OrcType(OrcTypeKind.DOUBLE));
}
if (REAL.equals(type)) {
return ImmutableList.of(new OrcType(OrcTypeKind.FLOAT));
}
if (type instanceof VarcharType) {
VarcharType varcharType = (VarcharType) type;
if (varcharType.isUnbounded()) {
return ImmutableList.of(new OrcType(OrcTypeKind.STRING));
}
return ImmutableList.of(new OrcType(OrcTypeKind.VARCHAR, varcharType.getLengthSafe()));
}
if (type instanceof CharType) {
return ImmutableList.of(new OrcType(OrcTypeKind.CHAR, ((CharType) type).getLength()));
}
if (VARBINARY.equals(type)) {
return ImmutableList.of(new OrcType(OrcTypeKind.BINARY));
}
if (DATE.equals(type)) {
return ImmutableList.of(new OrcType(OrcTypeKind.DATE));
}
if (TIMESTAMP.equals(type)) {
return ImmutableList.of(new OrcType(OrcTypeKind.TIMESTAMP));
}
if (type instanceof DecimalType) {
DecimalType decimalType = (DecimalType) type;
return ImmutableList.of(new OrcType(OrcTypeKind.DECIMAL, decimalType.getPrecision(), decimalType.getScale()));
}
if (type.getTypeSignature().getBase().equals(ARRAY)) {
return createOrcArrayType(nextFieldTypeIndex, type.getTypeParameters().get(0));
}
if (type.getTypeSignature().getBase().equals(MAP)) {
return createOrcMapType(nextFieldTypeIndex, type.getTypeParameters().get(0), type.getTypeParameters().get(1));
}
if (type.getTypeSignature().getBase().equals(ROW)) {
List<String> fieldNames = new ArrayList<>();
for (int i = 0; i < type.getTypeSignature().getParameters().size(); i++) {
TypeSignatureParameter parameter = type.getTypeSignature().getParameters().get(i);
fieldNames.add(parameter.getNamedTypeSignature().getName().orElse("field" + i));
}
List<Type> fieldTypes = type.getTypeParameters();
return createOrcRowType(nextFieldTypeIndex, fieldNames, fieldTypes);
}
throw new NotSupportedException(format("Unsupported Hive type: %s", type));
}
use of com.facebook.presto.common.NotSupportedException in project presto by prestodb.
the class SimplePagesHashStrategy method positionEqualsRowIgnoreNulls.
@Override
public boolean positionEqualsRowIgnoreNulls(int leftBlockIndex, int leftPosition, int rightPosition, Page rightPage) {
for (int i = 0; i < hashChannels.size(); i++) {
int hashChannel = hashChannels.get(i);
Type type = types.get(hashChannel);
Block leftBlock = channels.get(hashChannel).get(leftBlockIndex);
Block rightBlock = rightPage.getBlock(i);
try {
if (!type.equalTo(leftBlock, leftPosition, rightBlock, rightPosition)) {
return false;
}
} catch (NotSupportedException e) {
throw new PrestoException(NOT_SUPPORTED, e.getMessage(), e);
}
}
return true;
}
use of com.facebook.presto.common.NotSupportedException in project presto by prestodb.
the class SimplePageWithPositionComparator method compareTo.
@Override
public int compareTo(Page left, int leftPosition, Page right, int rightPosition) {
for (int i = 0; i < sortChannels.length; i++) {
int sortChannel = sortChannels[i];
SortOrder sortOrder = sortOrders[i];
Type type = types[i];
Block leftBlock = left.getBlock(sortChannel);
Block rightBlock = right.getBlock(sortChannel);
try {
int compare = sortOrder.compareBlockValue(type, leftBlock, leftPosition, rightBlock, rightPosition);
if (compare != 0) {
return compare;
}
} catch (NotSupportedException e) {
throw new PrestoException(NOT_SUPPORTED, e.getMessage(), e);
}
}
return 0;
}
use of com.facebook.presto.common.NotSupportedException in project presto by prestodb.
the class TuplePageFilter method matches.
private boolean matches(Page page, int position) {
for (int channel = 0; channel < inputChannels.size(); channel++) {
Type type = types.get(channel);
Block outputBlock = page.getBlock(channel);
Block singleTupleBlock = tuplePage.getBlock(channel);
try {
if (!type.equalTo(singleTupleBlock, 0, outputBlock, position)) {
return false;
}
} catch (NotSupportedException e) {
throw new PrestoException(NOT_SUPPORTED, e.getMessage(), e);
}
}
return true;
}
use of com.facebook.presto.common.NotSupportedException in project presto by prestodb.
the class OrcFileRewriter method rewrite.
public OrcFileInfo rewrite(FileSystem fileSystem, Map<String, Type> allColumnTypes, Path input, Path output, BitSet rowsToDelete) throws IOException {
try (ThreadContextClassLoader ignored = new ThreadContextClassLoader(FileSystem.class.getClassLoader());
OrcDataSource dataSource = orcDataEnvironment.createOrcDataSource(fileSystem, input, readerAttributes)) {
OrcReader reader = new OrcReader(dataSource, ORC, orcFileTailSource, stripeMetadataSourceFactory, new RaptorOrcAggregatedMemoryContext(), new OrcReaderOptions(readerAttributes.getMaxMergeDistance(), readerAttributes.getTinyStripeThreshold(), HUGE_MAX_READ_BLOCK_SIZE, readerAttributes.isZstdJniDecompressionEnabled()), false, NO_ENCRYPTION, DwrfKeyProvider.EMPTY, new RuntimeStats());
if (reader.getFooter().getNumberOfRows() < rowsToDelete.length()) {
throw new IOException("File has fewer rows than deletion vector");
}
int deleteRowCount = rowsToDelete.cardinality();
if (reader.getFooter().getNumberOfRows() == deleteRowCount) {
return new OrcFileInfo(0, 0);
}
if (reader.getFooter().getNumberOfRows() >= Integer.MAX_VALUE) {
throw new IOException("File has too many rows");
}
int inputRowCount = toIntExact(reader.getFooter().getNumberOfRows());
Map<String, Integer> currentColumnIds = IntStream.range(0, reader.getColumnNames().size()).boxed().collect(toMap(reader.getColumnNames()::get, i -> i));
ImmutableList.Builder<Type> writerColumnTypesBuilder = ImmutableList.builder();
ImmutableList.Builder<String> writerColumnIdsBuilder = ImmutableList.builder();
ImmutableList.Builder<Integer> readerColumnIndexBuilder = ImmutableList.builder();
// Build columns for writer; keep the right ordinal
Map<String, Type> orderedAllColumnTypes = new TreeMap<>(Comparator.comparingLong(Long::parseLong));
orderedAllColumnTypes.putAll(allColumnTypes);
for (Map.Entry<String, Type> columnType : orderedAllColumnTypes.entrySet()) {
// Get the intersection of the provide columns and the actual columns
Integer currentColumnIndex = currentColumnIds.get(columnType.getKey());
if (currentColumnIndex != null) {
readerColumnIndexBuilder.add(currentColumnIndex);
writerColumnTypesBuilder.add(columnType.getValue());
writerColumnIdsBuilder.add(columnType.getKey());
}
}
List<Type> writerColumnTypes = writerColumnTypesBuilder.build();
List<String> writerColumnIds = writerColumnIdsBuilder.build();
List<Integer> readerColumnIndex = readerColumnIndexBuilder.build();
Map<Integer, Type> readerColumns = IntStream.range(0, readerColumnIndex.size()).boxed().collect(toMap(readerColumnIndex::get, writerColumnTypes::get));
if (writerColumnTypes.isEmpty()) {
// no intersection; directly return
return new OrcFileInfo(0, 0);
}
StorageTypeConverter converter = new StorageTypeConverter(typeManager);
List<Type> writerStorageTypes = writerColumnTypes.stream().map(converter::toStorageType).collect(toImmutableList());
long start = System.nanoTime();
Map<String, String> userMetadata = ImmutableMap.of();
if (reader.getFooter().getUserMetadata().containsKey(OrcFileMetadata.KEY)) {
// build metadata if the original file has it
ImmutableMap.Builder<Long, TypeSignature> metadataBuilder = ImmutableMap.builder();
for (int i = 0; i < writerColumnIds.size(); i++) {
metadataBuilder.put(Long.parseLong(writerColumnIds.get(i)), writerColumnTypes.get(i).getTypeSignature());
}
userMetadata = ImmutableMap.of(OrcFileMetadata.KEY, METADATA_CODEC.toJson(new OrcFileMetadata(metadataBuilder.build())));
}
StorageTypeConverter storageTypeConverter = new StorageTypeConverter(typeManager);
try (Closer<OrcBatchRecordReader, IOException> recordReader = closer(reader.createBatchRecordReader(storageTypeConverter.toStorageTypes(readerColumns), TRUE, DEFAULT_STORAGE_TIMEZONE, new RaptorOrcAggregatedMemoryContext(), INITIAL_BATCH_SIZE), OrcBatchRecordReader::close);
Closer<OrcWriter, IOException> writer = closer(new OrcWriter(orcDataEnvironment.createOrcDataSink(fileSystem, output), writerColumnIds, writerStorageTypes, ORC, compression, Optional.empty(), NO_ENCRYPTION, getDefaultOrcWriterOptions(), userMetadata, DEFAULT_STORAGE_TIMEZONE, validate, HASHED, stats), OrcWriter::close)) {
OrcFileInfo fileInfo = rewrite(recordReader.get(), writer.get(), rowsToDelete, writerColumnTypes, readerColumnIndexBuilder.build());
log.debug("Rewrote file %s in %s (input rows: %s, output rows: %s)", input.getName(), nanosSince(start), inputRowCount, inputRowCount - deleteRowCount);
return fileInfo;
}
} catch (NotSupportedException e) {
throw new PrestoException(NOT_SUPPORTED, e.getMessage(), e);
}
}
Aggregations