Search in sources :

Example 26 with Type

use of com.facebook.presto.spi.type.Type in project presto by prestodb.

the class ExampleRecordCursor method checkFieldType.

private void checkFieldType(int field, Type expected) {
    Type actual = getType(field);
    checkArgument(actual.equals(expected), "Expected field %s to be type %s but is %s", field, expected, actual);
}
Also used : VarcharType.createUnboundedVarcharType(com.facebook.presto.spi.type.VarcharType.createUnboundedVarcharType) Type(com.facebook.presto.spi.type.Type)

Example 27 with Type

use of com.facebook.presto.spi.type.Type in project presto by prestodb.

the class ColumnarBinaryHiveRecordCursor method parseCharColumn.

private void parseCharColumn(int column, byte[] bytes, int start, int length) {
    if (length == 0) {
        nulls[column] = true;
    } else {
        nulls[column] = false;
        Slice value = Slices.wrappedBuffer(Arrays.copyOfRange(bytes, start, start + length));
        Type type = types[column];
        slices[column] = trimSpacesAndTruncateToLength(value, type);
    }
}
Also used : DecimalType(com.facebook.presto.spi.type.DecimalType) Varchars.isVarcharType(com.facebook.presto.spi.type.Varchars.isVarcharType) HiveUtil.isStructuralType(com.facebook.presto.hive.HiveUtil.isStructuralType) Type(com.facebook.presto.spi.type.Type) Chars.isCharType(com.facebook.presto.spi.type.Chars.isCharType) Slice(io.airlift.slice.Slice)

Example 28 with Type

use of com.facebook.presto.spi.type.Type in project presto by prestodb.

the class BlackHolePageSourceProvider method createPageSource.

@Override
public ConnectorPageSource createPageSource(ConnectorTransactionHandle transactionHandle, ConnectorSession session, ConnectorSplit split, List<ColumnHandle> columns) {
    BlackHoleSplit blackHoleSplit = (BlackHoleSplit) split;
    ImmutableList.Builder<Type> builder = ImmutableList.builder();
    for (ColumnHandle column : columns) {
        builder.add(((BlackHoleColumnHandle) column).getColumnType());
    }
    List<Type> types = builder.build();
    Page page = generateZeroPage(types, blackHoleSplit.getRowsPerPage(), blackHoleSplit.getFieldsLength());
    return new BlackHolePageSource(page, blackHoleSplit.getPagesCount(), executorService, blackHoleSplit.getPageProcessingDelay());
}
Also used : ColumnHandle(com.facebook.presto.spi.ColumnHandle) Type(com.facebook.presto.spi.type.Type) FixedWidthType(com.facebook.presto.spi.type.FixedWidthType) VarcharType(com.facebook.presto.spi.type.VarcharType) Varchars.isVarcharType(com.facebook.presto.spi.type.Varchars.isVarcharType) ImmutableList(com.google.common.collect.ImmutableList) Page(com.facebook.presto.spi.Page)

Example 29 with Type

use of com.facebook.presto.spi.type.Type in project presto by prestodb.

the class HiveWriteUtils method getJavaObjectInspector.

public static ObjectInspector getJavaObjectInspector(Type type) {
    if (type.equals(BooleanType.BOOLEAN)) {
        return javaBooleanObjectInspector;
    } else if (type.equals(BigintType.BIGINT)) {
        return javaLongObjectInspector;
    } else if (type.equals(IntegerType.INTEGER)) {
        return javaIntObjectInspector;
    } else if (type.equals(SmallintType.SMALLINT)) {
        return javaShortObjectInspector;
    } else if (type.equals(TinyintType.TINYINT)) {
        return javaByteObjectInspector;
    } else if (type.equals(RealType.REAL)) {
        return javaFloatObjectInspector;
    } else if (type.equals(DoubleType.DOUBLE)) {
        return javaDoubleObjectInspector;
    } else if (type instanceof VarcharType) {
        return writableStringObjectInspector;
    } else if (type instanceof CharType) {
        return writableHiveCharObjectInspector;
    } else if (type.equals(VarbinaryType.VARBINARY)) {
        return javaByteArrayObjectInspector;
    } else if (type.equals(DateType.DATE)) {
        return javaDateObjectInspector;
    } else if (type.equals(TimestampType.TIMESTAMP)) {
        return javaTimestampObjectInspector;
    } else if (type instanceof DecimalType) {
        DecimalType decimalType = (DecimalType) type;
        return getPrimitiveJavaObjectInspector(new DecimalTypeInfo(decimalType.getPrecision(), decimalType.getScale()));
    } else if (isArrayType(type)) {
        return ObjectInspectorFactory.getStandardListObjectInspector(getJavaObjectInspector(type.getTypeParameters().get(0)));
    } else if (isMapType(type)) {
        ObjectInspector keyObjectInspector = getJavaObjectInspector(type.getTypeParameters().get(0));
        ObjectInspector valueObjectInspector = getJavaObjectInspector(type.getTypeParameters().get(1));
        return ObjectInspectorFactory.getStandardMapObjectInspector(keyObjectInspector, valueObjectInspector);
    } else if (isRowType(type)) {
        return ObjectInspectorFactory.getStandardStructObjectInspector(type.getTypeSignature().getParameters().stream().map(parameter -> parameter.getNamedTypeSignature().getName()).collect(toList()), type.getTypeParameters().stream().map(HiveWriteUtils::getJavaObjectInspector).collect(toList()));
    }
    throw new IllegalArgumentException("unsupported type: " + type);
}
Also used : DecimalTypeInfo(org.apache.hadoop.hive.serde2.typeinfo.DecimalTypeInfo) DateTimeZone(org.joda.time.DateTimeZone) IntegerType(com.facebook.presto.spi.type.IntegerType) PrimitiveObjectInspectorFactory.javaByteObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory.javaByteObjectInspector) Text(org.apache.hadoop.io.Text) PrimitiveObjectInspectorFactory.javaLongObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory.javaLongObjectInspector) DateWritable(org.apache.hadoop.hive.serde2.io.DateWritable) PrimitiveObjectInspectorFactory.javaTimestampObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory.javaTimestampObjectInspector) PrimitiveObjectInspectorFactory.javaDateObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory.javaDateObjectInspector) PrimitiveObjectInspectorFactory.writableTimestampObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory.writableTimestampObjectInspector) DoubleType(com.facebook.presto.spi.type.DoubleType) Configuration(org.apache.hadoop.conf.Configuration) Map(java.util.Map) StructTypeInfo(org.apache.hadoop.hive.serde2.typeinfo.StructTypeInfo) BigInteger(java.math.BigInteger) ObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector) IntWritable(org.apache.hadoop.io.IntWritable) PrimitiveObjectInspectorFactory.javaByteArrayObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory.javaByteArrayObjectInspector) VarbinaryType(com.facebook.presto.spi.type.VarbinaryType) Decimals(com.facebook.presto.spi.type.Decimals) PrimitiveObjectInspectorFactory.javaFloatObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory.javaFloatObjectInspector) PrimitiveObjectInspectorFactory.javaDoubleObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory.javaDoubleObjectInspector) SemiTransactionalHiveMetastore(com.facebook.presto.hive.metastore.SemiTransactionalHiveMetastore) MANAGED_TABLE(org.apache.hadoop.hive.metastore.TableType.MANAGED_TABLE) HiveUtil.checkCondition(com.facebook.presto.hive.HiveUtil.checkCondition) BooleanWritable(org.apache.hadoop.io.BooleanWritable) HIVE_DATABASE_LOCATION_ERROR(com.facebook.presto.hive.HiveErrorCode.HIVE_DATABASE_LOCATION_ERROR) HiveUtil.isMapType(com.facebook.presto.hive.HiveUtil.isMapType) PrimitiveObjectInspectorFactory.javaIntObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory.javaIntObjectInspector) StructField(org.apache.hadoop.hive.serde2.objectinspector.StructField) HiveUtil.isRowType(com.facebook.presto.hive.HiveUtil.isRowType) Table(com.facebook.presto.hive.metastore.Table) PrimitiveCategory(org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector.PrimitiveCategory) Database(com.facebook.presto.hive.metastore.Database) PrimitiveObjectInspectorFactory.writableFloatObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory.writableFloatObjectInspector) PRESTO_OFFLINE(com.facebook.presto.hive.HiveSplitManager.PRESTO_OFFLINE) Strings.isNullOrEmpty(com.google.common.base.Strings.isNullOrEmpty) ArrayList(java.util.ArrayList) COMPRESSRESULT(org.apache.hadoop.hive.conf.HiveConf.ConfVars.COMPRESSRESULT) PrimitiveObjectInspectorFactory.javaShortObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory.javaShortObjectInspector) Type(com.facebook.presto.spi.type.Type) DoubleWritable(org.apache.hadoop.hive.serde2.io.DoubleWritable) BigintType(com.facebook.presto.spi.type.BigintType) PrimitiveObjectInspectorFactory.writableBooleanObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory.writableBooleanObjectInspector) Properties(java.util.Properties) Reporter(org.apache.hadoop.mapred.Reporter) Throwables(com.google.common.base.Throwables) IOException(java.io.IOException) UTC(org.joda.time.DateTimeZone.UTC) DecimalTypeInfo(org.apache.hadoop.hive.serde2.typeinfo.DecimalTypeInfo) SettableStructObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.SettableStructObjectInspector) HIVE_FILESYSTEM_ERROR(com.facebook.presto.hive.HiveErrorCode.HIVE_FILESYSTEM_ERROR) PrimitiveObjectInspectorFactory.writableBinaryObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory.writableBinaryObjectInspector) PrimitiveObjectInspectorFactory.writableDoubleObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory.writableDoubleObjectInspector) BooleanType(com.facebook.presto.spi.type.BooleanType) PrimitiveObjectInspectorFactory.writableLongObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory.writableLongObjectInspector) RealType(com.facebook.presto.spi.type.RealType) VarcharType(com.facebook.presto.spi.type.VarcharType) SerDeException(org.apache.hadoop.hive.serde2.SerDeException) FloatWritable(org.apache.hadoop.io.FloatWritable) RecordWriter(org.apache.hadoop.hive.ql.exec.FileSinkOperator.RecordWriter) Block(com.facebook.presto.spi.block.Block) PrimitiveObjectInspectorFactory.writableByteObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory.writableByteObjectInspector) DateType(com.facebook.presto.spi.type.DateType) LongWritable(org.apache.hadoop.io.LongWritable) TinyintType(com.facebook.presto.spi.type.TinyintType) FsPermission(org.apache.hadoop.fs.permission.FsPermission) MapTypeInfo(org.apache.hadoop.hive.serde2.typeinfo.MapTypeInfo) PrimitiveObjectInspectorFactory.writableDateObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory.writableDateObjectInspector) SchemaTableName(com.facebook.presto.spi.SchemaTableName) DecimalType(com.facebook.presto.spi.type.DecimalType) SchemaNotFoundException(com.facebook.presto.spi.SchemaNotFoundException) TimestampType(com.facebook.presto.spi.type.TimestampType) Path(org.apache.hadoop.fs.Path) SmallintType(com.facebook.presto.spi.type.SmallintType) PrimitiveObjectInspectorFactory.getPrimitiveWritableObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory.getPrimitiveWritableObjectInspector) PrimitiveTypeInfo(org.apache.hadoop.hive.serde2.typeinfo.PrimitiveTypeInfo) ShortWritable(org.apache.hadoop.hive.serde2.io.ShortWritable) HIVE_WRITER_DATA_ERROR(com.facebook.presto.hive.HiveErrorCode.HIVE_WRITER_DATA_ERROR) Timestamp(java.sql.Timestamp) HiveOutputFormat(org.apache.hadoop.hive.ql.io.HiveOutputFormat) String.format(java.lang.String.format) List(java.util.List) NOT_SUPPORTED(com.facebook.presto.spi.StandardErrorCode.NOT_SUPPORTED) HiveUtil.isArrayType(com.facebook.presto.hive.HiveUtil.isArrayType) PrimitiveObjectInspectorFactory.writableHiveCharObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory.writableHiveCharObjectInspector) StandardErrorCode(com.facebook.presto.spi.StandardErrorCode) Optional(java.util.Optional) PrimitiveObjectInspectorFactory.writableShortObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory.writableShortObjectInspector) TypeInfoFactory.getCharTypeInfo(org.apache.hadoop.hive.serde2.typeinfo.TypeInfoFactory.getCharTypeInfo) TypeInfoFactory.getVarcharTypeInfo(org.apache.hadoop.hive.serde2.typeinfo.TypeInfoFactory.getVarcharTypeInfo) MetastoreUtil.getProtectMode(com.facebook.presto.hive.metastore.MetastoreUtil.getProtectMode) Strings.padEnd(com.google.common.base.Strings.padEnd) PrimitiveObjectInspectorFactory.javaBooleanObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory.javaBooleanObjectInspector) Shorts(com.google.common.primitives.Shorts) HashMap(java.util.HashMap) ProtectMode(org.apache.hadoop.hive.metastore.ProtectMode) PrestoException(com.facebook.presto.spi.PrestoException) Float.intBitsToFloat(java.lang.Float.intBitsToFloat) PrimitiveObjectInspectorFactory.getPrimitiveJavaObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory.getPrimitiveJavaObjectInspector) Partition(com.facebook.presto.hive.metastore.Partition) PrimitiveObjectInspectorFactory.writableStringObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory.writableStringObjectInspector) HiveVarchar(org.apache.hadoop.hive.common.type.HiveVarchar) ImmutableList(com.google.common.collect.ImmutableList) ByteWritable(org.apache.hadoop.io.ByteWritable) Objects.requireNonNull(java.util.Objects.requireNonNull) ListTypeInfo(org.apache.hadoop.hive.serde2.typeinfo.ListTypeInfo) BytesWritable(org.apache.hadoop.io.BytesWritable) TimestampWritable(org.apache.hadoop.hive.serde2.io.TimestampWritable) Math.toIntExact(java.lang.Math.toIntExact) Storage(com.facebook.presto.hive.metastore.Storage) HiveConf(org.apache.hadoop.hive.conf.HiveConf) SignedBytes(com.google.common.primitives.SignedBytes) Date(java.sql.Date) CharType(com.facebook.presto.spi.type.CharType) TypeInfo(org.apache.hadoop.hive.serde2.typeinfo.TypeInfo) JobConf(org.apache.hadoop.mapred.JobConf) TimeUnit(java.util.concurrent.TimeUnit) UUID.randomUUID(java.util.UUID.randomUUID) Collectors.toList(java.util.stream.Collectors.toList) PrimitiveObjectInspectorFactory.writableIntObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory.writableIntObjectInspector) ObjectInspectorFactory(org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorFactory) Serializer(org.apache.hadoop.hive.serde2.Serializer) HiveDecimal(org.apache.hadoop.hive.common.type.HiveDecimal) HiveDecimalWritable(org.apache.hadoop.hive.serde2.io.HiveDecimalWritable) Collections(java.util.Collections) Chars.isCharType(com.facebook.presto.spi.type.Chars.isCharType) PrimitiveObjectInspectorFactory.javaByteObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory.javaByteObjectInspector) PrimitiveObjectInspectorFactory.javaLongObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory.javaLongObjectInspector) PrimitiveObjectInspectorFactory.javaTimestampObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory.javaTimestampObjectInspector) PrimitiveObjectInspectorFactory.javaDateObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory.javaDateObjectInspector) PrimitiveObjectInspectorFactory.writableTimestampObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory.writableTimestampObjectInspector) ObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector) PrimitiveObjectInspectorFactory.javaByteArrayObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory.javaByteArrayObjectInspector) PrimitiveObjectInspectorFactory.javaFloatObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory.javaFloatObjectInspector) PrimitiveObjectInspectorFactory.javaDoubleObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory.javaDoubleObjectInspector) PrimitiveObjectInspectorFactory.javaIntObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory.javaIntObjectInspector) PrimitiveObjectInspectorFactory.writableFloatObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory.writableFloatObjectInspector) PrimitiveObjectInspectorFactory.javaShortObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory.javaShortObjectInspector) PrimitiveObjectInspectorFactory.writableBooleanObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory.writableBooleanObjectInspector) SettableStructObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.SettableStructObjectInspector) PrimitiveObjectInspectorFactory.writableBinaryObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory.writableBinaryObjectInspector) PrimitiveObjectInspectorFactory.writableDoubleObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory.writableDoubleObjectInspector) PrimitiveObjectInspectorFactory.writableLongObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory.writableLongObjectInspector) PrimitiveObjectInspectorFactory.writableByteObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory.writableByteObjectInspector) PrimitiveObjectInspectorFactory.writableDateObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory.writableDateObjectInspector) PrimitiveObjectInspectorFactory.getPrimitiveWritableObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory.getPrimitiveWritableObjectInspector) PrimitiveObjectInspectorFactory.writableHiveCharObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory.writableHiveCharObjectInspector) PrimitiveObjectInspectorFactory.writableShortObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory.writableShortObjectInspector) PrimitiveObjectInspectorFactory.javaBooleanObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory.javaBooleanObjectInspector) PrimitiveObjectInspectorFactory.getPrimitiveJavaObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory.getPrimitiveJavaObjectInspector) PrimitiveObjectInspectorFactory.writableStringObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory.writableStringObjectInspector) PrimitiveObjectInspectorFactory.writableIntObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory.writableIntObjectInspector) VarcharType(com.facebook.presto.spi.type.VarcharType) DecimalType(com.facebook.presto.spi.type.DecimalType) CharType(com.facebook.presto.spi.type.CharType) Chars.isCharType(com.facebook.presto.spi.type.Chars.isCharType)

Example 30 with Type

use of com.facebook.presto.spi.type.Type in project presto by prestodb.

the class OrcPageSourceFactory method createOrcPageSource.

public static OrcPageSource createOrcPageSource(MetadataReader metadataReader, HdfsEnvironment hdfsEnvironment, String sessionUser, Configuration configuration, Path path, long start, long length, List<HiveColumnHandle> columns, boolean useOrcColumnNames, TupleDomain<HiveColumnHandle> effectivePredicate, DateTimeZone hiveStorageTimeZone, TypeManager typeManager, DataSize maxMergeDistance, DataSize maxBufferSize, DataSize streamBufferSize, boolean orcBloomFiltersEnabled) {
    OrcDataSource orcDataSource;
    try {
        FileSystem fileSystem = hdfsEnvironment.getFileSystem(sessionUser, path, configuration);
        long size = fileSystem.getFileStatus(path).getLen();
        FSDataInputStream inputStream = fileSystem.open(path);
        orcDataSource = new HdfsOrcDataSource(path.toString(), size, maxMergeDistance, maxBufferSize, streamBufferSize, inputStream);
    } catch (Exception e) {
        if (nullToEmpty(e.getMessage()).trim().equals("Filesystem closed") || e instanceof FileNotFoundException) {
            throw new PrestoException(HIVE_CANNOT_OPEN_SPLIT, e);
        }
        throw new PrestoException(HIVE_CANNOT_OPEN_SPLIT, splitError(e, path, start, length), e);
    }
    AggregatedMemoryContext systemMemoryUsage = new AggregatedMemoryContext();
    try {
        OrcReader reader = new OrcReader(orcDataSource, metadataReader, maxMergeDistance, maxBufferSize);
        List<HiveColumnHandle> physicalColumns = getPhysicalHiveColumnHandles(columns, useOrcColumnNames, reader, path);
        ImmutableMap.Builder<Integer, Type> includedColumns = ImmutableMap.builder();
        ImmutableList.Builder<ColumnReference<HiveColumnHandle>> columnReferences = ImmutableList.builder();
        for (HiveColumnHandle column : physicalColumns) {
            if (column.getColumnType() == REGULAR) {
                Type type = typeManager.getType(column.getTypeSignature());
                includedColumns.put(column.getHiveColumnIndex(), type);
                columnReferences.add(new ColumnReference<>(column, column.getHiveColumnIndex(), type));
            }
        }
        OrcPredicate predicate = new TupleDomainOrcPredicate<>(effectivePredicate, columnReferences.build(), orcBloomFiltersEnabled);
        OrcRecordReader recordReader = reader.createRecordReader(includedColumns.build(), predicate, start, length, hiveStorageTimeZone, systemMemoryUsage);
        return new OrcPageSource(recordReader, orcDataSource, physicalColumns, typeManager, systemMemoryUsage);
    } catch (Exception e) {
        try {
            orcDataSource.close();
        } catch (IOException ignored) {
        }
        if (e instanceof PrestoException) {
            throw (PrestoException) e;
        }
        String message = splitError(e, path, start, length);
        if (e.getClass().getSimpleName().equals("BlockMissingException")) {
            throw new PrestoException(HIVE_MISSING_DATA, message, e);
        }
        throw new PrestoException(HIVE_CANNOT_OPEN_SPLIT, message, e);
    }
}
Also used : TupleDomainOrcPredicate(com.facebook.presto.orc.TupleDomainOrcPredicate) ImmutableList(com.google.common.collect.ImmutableList) FileNotFoundException(java.io.FileNotFoundException) PrestoException(com.facebook.presto.spi.PrestoException) FileSystem(org.apache.hadoop.fs.FileSystem) HiveColumnHandle(com.facebook.presto.hive.HiveColumnHandle) OrcDataSource(com.facebook.presto.orc.OrcDataSource) IOException(java.io.IOException) OrcRecordReader(com.facebook.presto.orc.OrcRecordReader) AggregatedMemoryContext(com.facebook.presto.orc.memory.AggregatedMemoryContext) PrestoException(com.facebook.presto.spi.PrestoException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) ImmutableMap(com.google.common.collect.ImmutableMap) Type(com.facebook.presto.spi.type.Type) OrcReader(com.facebook.presto.orc.OrcReader) FSDataInputStream(org.apache.hadoop.fs.FSDataInputStream) TupleDomainOrcPredicate(com.facebook.presto.orc.TupleDomainOrcPredicate) OrcPredicate(com.facebook.presto.orc.OrcPredicate) ColumnReference(com.facebook.presto.orc.TupleDomainOrcPredicate.ColumnReference)

Aggregations

Type (com.facebook.presto.spi.type.Type)392 Test (org.testng.annotations.Test)103 Block (com.facebook.presto.spi.block.Block)83 ImmutableList (com.google.common.collect.ImmutableList)79 ArrayType (com.facebook.presto.type.ArrayType)78 MapType (com.facebook.presto.type.MapType)72 Page (com.facebook.presto.spi.Page)68 PrestoException (com.facebook.presto.spi.PrestoException)51 List (java.util.List)50 VarcharType (com.facebook.presto.spi.type.VarcharType)48 DecimalType (com.facebook.presto.spi.type.DecimalType)44 BlockBuilder (com.facebook.presto.spi.block.BlockBuilder)40 MaterializedResult (com.facebook.presto.testing.MaterializedResult)40 ArrayList (java.util.ArrayList)40 MethodHandle (java.lang.invoke.MethodHandle)39 PlanNodeId (com.facebook.presto.sql.planner.plan.PlanNodeId)37 ImmutableMap (com.google.common.collect.ImmutableMap)36 Map (java.util.Map)36 Slice (io.airlift.slice.Slice)35 BlockBuilderStatus (com.facebook.presto.spi.block.BlockBuilderStatus)30