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