use of io.trino.spi.type.TypeSignature in project trino by trinodb.
the class TestMergeQuantileDigestFunction method getSequenceBlocks.
@Override
protected Block[] getSequenceBlocks(int start, int length) {
Type type = functionResolution.getPlannerContext().getTypeManager().getType(new TypeSignature(QDIGEST.getName(), TypeSignatureParameter.typeParameter(DOUBLE.getTypeSignature())));
BlockBuilder blockBuilder = type.createBlockBuilder(null, length);
for (int i = start; i < start + length; i++) {
QuantileDigest qdigest = new QuantileDigest(0.0);
qdigest.add(i);
type.writeSlice(blockBuilder, qdigest.serialize());
}
return new Block[] { blockBuilder.build() };
}
use of io.trino.spi.type.TypeSignature in project trino by trinodb.
the class TestOrcReaderMemoryUsage method testMapTypeWithNulls.
@Test
public void testMapTypeWithNulls() throws Exception {
Type mapType = TESTING_TYPE_MANAGER.getType(new TypeSignature(StandardTypes.MAP, TypeSignatureParameter.typeParameter(BIGINT.getTypeSignature()), TypeSignatureParameter.typeParameter(BIGINT.getTypeSignature())));
int rows = 10000;
OrcRecordReader reader = null;
try (TempFile tempFile = createSingleColumnMapFileWithNullValues(mapType, rows)) {
reader = createCustomOrcRecordReader(tempFile, OrcPredicate.TRUE, mapType, INITIAL_BATCH_SIZE);
assertInitialRetainedSizes(reader, rows);
long stripeReaderRetainedSize = reader.getCurrentStripeRetainedSizeInBytes();
long streamReaderRetainedSize = reader.getStreamReaderRetainedSizeInBytes();
long readerRetainedSize = reader.getRetainedSizeInBytes();
long readerMemoryUsage = reader.getMemoryUsage();
while (true) {
Page page = reader.nextPage();
if (page == null) {
break;
}
page = page.getLoadedPage();
// increasing during the test, which will cause the StreamReader buffer sizes to increase too.
if (page.getPositionCount() < MAX_BATCH_SIZE) {
continue;
}
// StripeReader memory should increase after reading a block.
assertGreaterThan(reader.getCurrentStripeRetainedSizeInBytes(), stripeReaderRetainedSize);
// There are no local buffers needed.
assertEquals(reader.getStreamReaderRetainedSizeInBytes() - streamReaderRetainedSize, 0L);
// The total retained size and memory usage should be strictly larger than 0L because of the instance sizes.
assertGreaterThan(reader.getRetainedSizeInBytes() - readerRetainedSize, 0L);
assertGreaterThan(reader.getMemoryUsage() - readerMemoryUsage, 0L);
}
} finally {
if (reader != null) {
reader.close();
}
}
assertClosedRetainedSizes(reader);
}
use of io.trino.spi.type.TypeSignature in project trino by trinodb.
the class TestTypeSignature method testIsCalculated.
@Test
public void testIsCalculated() {
assertFalse(BIGINT.getTypeSignature().isCalculated());
assertTrue(new TypeSignature("decimal", typeVariable("p"), typeVariable("s")).isCalculated());
assertFalse(createDecimalType(2, 1).getTypeSignature().isCalculated());
assertTrue(arrayType(new TypeSignature("decimal", typeVariable("p"), typeVariable("s"))).isCalculated());
assertFalse(arrayType(createDecimalType(2, 1).getTypeSignature()).isCalculated());
assertTrue(mapType(new TypeSignature("decimal", typeVariable("p1"), typeVariable("s1")), new TypeSignature("decimal", typeVariable("p2"), typeVariable("s2"))).isCalculated());
assertFalse(mapType(createDecimalType(2, 1).getTypeSignature(), createDecimalType(3, 1).getTypeSignature()).isCalculated());
assertTrue(rowType(namedField("a", new TypeSignature("decimal", typeVariable("p1"), typeVariable("s1"))), namedField("b", new TypeSignature("decimal", typeVariable("p2"), typeVariable("s2")))).isCalculated());
}
use of io.trino.spi.type.TypeSignature in project trino by trinodb.
the class TestTypeSignature method assertSignature.
private static void assertSignature(String typeName, String base, List<String> parameters, String expectedTypeName) {
TypeSignature signature = parseTypeSignature(typeName, ImmutableSet.of());
assertEquals(signature.getBase(), base);
assertEquals(signature.getParameters().size(), parameters.size());
for (int i = 0; i < signature.getParameters().size(); i++) {
assertEquals(signature.getParameters().get(i).toString(), parameters.get(i));
}
assertEquals(signature.toString(), expectedTypeName);
}
use of io.trino.spi.type.TypeSignature in project trino by trinodb.
the class TypeConverter method toTrinoType.
public static Type toTrinoType(org.apache.iceberg.types.Type type, TypeManager typeManager) {
switch(type.typeId()) {
case BOOLEAN:
return BooleanType.BOOLEAN;
case BINARY:
case FIXED:
return VarbinaryType.VARBINARY;
case DATE:
return DateType.DATE;
case DECIMAL:
Types.DecimalType decimalType = (Types.DecimalType) type;
return DecimalType.createDecimalType(decimalType.precision(), decimalType.scale());
case DOUBLE:
return DoubleType.DOUBLE;
case LONG:
return BigintType.BIGINT;
case FLOAT:
return RealType.REAL;
case INTEGER:
return IntegerType.INTEGER;
case TIME:
return TIME_MICROS;
case TIMESTAMP:
return ((Types.TimestampType) type).shouldAdjustToUTC() ? TIMESTAMP_TZ_MICROS : TIMESTAMP_MICROS;
case STRING:
return VarcharType.createUnboundedVarcharType();
case UUID:
return UuidType.UUID;
case LIST:
Types.ListType listType = (Types.ListType) type;
return new ArrayType(toTrinoType(listType.elementType(), typeManager));
case MAP:
Types.MapType mapType = (Types.MapType) type;
TypeSignature keyType = toTrinoType(mapType.keyType(), typeManager).getTypeSignature();
TypeSignature valueType = toTrinoType(mapType.valueType(), typeManager).getTypeSignature();
return typeManager.getParameterizedType(StandardTypes.MAP, ImmutableList.of(TypeSignatureParameter.typeParameter(keyType), TypeSignatureParameter.typeParameter(valueType)));
case STRUCT:
List<Types.NestedField> fields = ((Types.StructType) type).fields();
return RowType.from(fields.stream().map(field -> new RowType.Field(Optional.of(field.name()), toTrinoType(field.type(), typeManager))).collect(toImmutableList()));
}
throw new UnsupportedOperationException(format("Cannot convert from Iceberg type '%s' (%s) to Trino type", type, type.typeId()));
}
Aggregations