use of com.facebook.presto.common.type.RowType in project presto by prestodb.
the class TestBlockEncodingBuffers method buildBlockStatusWithType.
private BlockStatus buildBlockStatusWithType(Type type, int positionCount, boolean isView, float primitiveNullRate, float nestedNullRate, List<Encoding> wrappings) {
BlockStatus blockStatus = null;
if (isView) {
positionCount *= 2;
}
if (type == BIGINT) {
blockStatus = buildBigintBlockStatus(positionCount, primitiveNullRate);
} else if (type instanceof DecimalType) {
if (!((DecimalType) type).isShort()) {
blockStatus = buildLongDecimalBlockStatus(positionCount, primitiveNullRate);
} else {
blockStatus = buildShortDecimalBlockStatus(positionCount, primitiveNullRate);
}
} else if (type == INTEGER) {
blockStatus = buildIntegerBlockStatus(positionCount, primitiveNullRate);
} else if (type == SMALLINT) {
blockStatus = buildSmallintBlockStatus(positionCount, primitiveNullRate);
} else if (type == BOOLEAN) {
blockStatus = buildBooleanBlockStatus(positionCount, primitiveNullRate);
} else if (type == VARCHAR) {
blockStatus = buildVarcharBlockStatus(positionCount, primitiveNullRate, 10);
} else {
// Nested types
// Build isNull and offsets of size positionCount
boolean[] isNull = null;
if (nestedNullRate > 0) {
isNull = new boolean[positionCount];
}
int[] offsets = new int[positionCount + 1];
for (int position = 0; position < positionCount; position++) {
if (nestedNullRate > 0 && ThreadLocalRandom.current().nextDouble(1) < nestedNullRate) {
isNull[position] = true;
offsets[position + 1] = offsets[position];
} else {
offsets[position + 1] = offsets[position] + (type instanceof RowType ? 1 : ThreadLocalRandom.current().nextInt(10) + 1);
}
}
// Build the nested block of size offsets[positionCount].
if (type instanceof ArrayType) {
blockStatus = buildArrayBlockStatus((ArrayType) type, positionCount, isView, Optional.ofNullable(isNull), offsets, primitiveNullRate, nestedNullRate, wrappings);
} else if (type instanceof MapType) {
blockStatus = buildMapBlockStatus((MapType) type, positionCount, isView, Optional.ofNullable(isNull), offsets, primitiveNullRate, nestedNullRate, wrappings);
} else if (type instanceof RowType) {
blockStatus = buildRowBlockStatus((RowType) type, positionCount, isView, Optional.ofNullable(isNull), offsets, primitiveNullRate, nestedNullRate, wrappings);
} else {
throw new UnsupportedOperationException(format("type %s is not supported.", type));
}
}
if (isView) {
positionCount /= 2;
int offset = positionCount / 2;
Block blockView = blockStatus.block.getRegion(offset, positionCount);
int[] expectedRowSizesView = Arrays.stream(blockStatus.expectedRowSizes, offset, offset + positionCount).toArray();
blockStatus = new BlockStatus(blockView, expectedRowSizesView);
}
blockStatus = buildDictRleBlockStatus(blockStatus, positionCount, wrappings);
return blockStatus;
}
use of com.facebook.presto.common.type.RowType in project presto by prestodb.
the class ParquetTestUtils method getHiveType.
private static String getHiveType(Type type) {
if (type.equals(BOOLEAN) || type.equals(BIGINT) || type.equals(SmallintType.SMALLINT) || type.equals(TinyintType.TINYINT) || type.equals(DOUBLE)) {
return type.getTypeSignature().toString();
}
if (type.equals(INTEGER)) {
return "int";
}
if (type.equals(REAL)) {
return "float";
}
if (type.equals(TIMESTAMP)) {
return "timestamp";
}
if (type instanceof VarcharType) {
VarcharType varcharType = (VarcharType) type;
int varcharLength = varcharType.getLength();
return "varchar(" + varcharLength + ")";
}
if (type instanceof DecimalType) {
DecimalType decimalType = (DecimalType) type;
return format("decimal(%d,%d)", decimalType.getPrecision(), decimalType.getScale());
}
if (type instanceof ArrayType) {
return "array<" + getHiveType(((ArrayType) type).getElementType()) + ">";
}
if (type instanceof RowType) {
return "struct<" + Joiner.on(",").join(((RowType) type).getFields().stream().map(t -> t.getName().get() + ":" + getHiveType(t.getType())).collect(toList())) + ">";
}
throw new IllegalArgumentException("unsupported type: " + type);
}
use of com.facebook.presto.common.type.RowType in project presto by prestodb.
the class ParquetTestUtils method getObjectInspector.
private static ObjectInspector getObjectInspector(Type type) {
if (type.equals(BOOLEAN)) {
return writableBooleanObjectInspector;
}
if (type.equals(BIGINT)) {
return writableLongObjectInspector;
}
if (type.equals(INTEGER)) {
return writableIntObjectInspector;
}
if (type.equals(SmallintType.SMALLINT)) {
return writableShortObjectInspector;
}
if (type.equals(TinyintType.TINYINT)) {
return writableByteObjectInspector;
}
if (type.equals(DOUBLE)) {
return writableDoubleObjectInspector;
}
if (type.equals(REAL)) {
return writableFloatObjectInspector;
}
if (type.equals(TIMESTAMP)) {
return writableTimestampObjectInspector;
}
if (type instanceof VarcharType) {
VarcharType varcharType = (VarcharType) type;
int varcharLength = varcharType.getLength();
return getPrimitiveWritableObjectInspector(getVarcharTypeInfo(varcharLength));
}
if (type instanceof DecimalType) {
DecimalType decimalType = (DecimalType) type;
return getPrimitiveWritableObjectInspector(new DecimalTypeInfo(decimalType.getPrecision(), decimalType.getScale()));
}
if (type instanceof ArrayType || type instanceof RowType) {
return getJavaObjectInspector(type);
}
throw new IllegalArgumentException("unsupported type: " + type);
}
use of com.facebook.presto.common.type.RowType in project presto by prestodb.
the class TestTypeConversions method testConvertOneLevelRecordField.
@Test
public void testConvertOneLevelRecordField() {
Field field = Field.of("rec", RECORD, Field.of("sub_s", STRING), Field.of("sub_i", INTEGER));
ColumnMetadata metadata = Conversions.toColumnMetadata(field);
RowType targetType = RowType.from(ImmutableList.of(RowType.field("sub_s", VarcharType.VARCHAR), RowType.field("sub_i", BigintType.BIGINT)));
assertThat(metadata.getType()).isEqualTo(targetType);
}
use of com.facebook.presto.common.type.RowType in project presto by prestodb.
the class TestTypeConversions method testConvertTwoLevelsRecordColumn.
@Test
public void testConvertTwoLevelsRecordColumn() {
BigQueryColumnHandle column = new BigQueryColumnHandle("rec", BigQueryType.RECORD, NULLABLE, ImmutableList.of(new BigQueryColumnHandle("sub_rec", BigQueryType.RECORD, NULLABLE, ImmutableList.of(new BigQueryColumnHandle("sub_sub_s", BigQueryType.STRING, NULLABLE, ImmutableList.of(), null), new BigQueryColumnHandle("sub_sub_i", BigQueryType.INTEGER, NULLABLE, ImmutableList.of(), null)), null), new BigQueryColumnHandle("sub_s", BigQueryType.STRING, NULLABLE, ImmutableList.of(), null), new BigQueryColumnHandle("sub_i", BigQueryType.INTEGER, NULLABLE, ImmutableList.of(), null)), null);
ColumnMetadata metadata = column.getColumnMetadata();
RowType targetType = RowType.from(ImmutableList.of(RowType.field("sub_rec", RowType.from(ImmutableList.of(RowType.field("sub_sub_s", VarcharType.VARCHAR), RowType.field("sub_sub_i", BigintType.BIGINT)))), RowType.field("sub_s", VarcharType.VARCHAR), RowType.field("sub_i", BigintType.BIGINT)));
assertThat(metadata.getType()).isEqualTo(targetType);
}
Aggregations