use of com.facebook.presto.common.type.ArrayType in project presto by prestodb.
the class TestAvroDecoder method testSupportedDataTypeValidation.
@Test
public void testSupportedDataTypeValidation() {
// supported types
singleColumnDecoder(BigintType.BIGINT);
singleColumnDecoder(VarbinaryType.VARBINARY);
singleColumnDecoder(BooleanType.BOOLEAN);
singleColumnDecoder(DoubleType.DOUBLE);
singleColumnDecoder(createUnboundedVarcharType());
singleColumnDecoder(createVarcharType(100));
singleColumnDecoder(new ArrayType(BigintType.BIGINT));
singleColumnDecoder(VACHAR_MAP_TYPE);
singleColumnDecoder(DOUBLE_MAP_TYPE);
// some unsupported types
assertUnsupportedColumnTypeException(() -> singleColumnDecoder(DecimalType.createDecimalType(10, 4)));
}
use of com.facebook.presto.common.type.ArrayType in project presto by prestodb.
the class TestObjectInputDecoders method testBlockObjectDecoders.
@Test
public void testBlockObjectDecoders() {
ObjectInputDecoder decoder;
decoder = createDecoder(new ArrayType(BIGINT), typeManager);
assertTrue(decoder instanceof ObjectInputDecoders.ArrayObjectInputDecoder);
assertEquals(((ArrayList) decoder.decode(createLongArrayBlock())).get(0), 2L);
decoder = createDecoder(new MapType(BIGINT, BIGINT, methodHandle(TestRowType.class, "throwUnsupportedOperation"), methodHandle(TestRowType.class, "throwUnsupportedOperation")), typeManager);
assertTrue(decoder instanceof ObjectInputDecoders.MapObjectInputDecoder);
HashMap map = (HashMap) decoder.decode(createLongArrayBlock());
assertEquals(map.get(2L), 1L);
}
use of com.facebook.presto.common.type.ArrayType in project presto by prestodb.
the class AbstractTestHiveClient method assertValueTypes.
private static void assertValueTypes(MaterializedRow row, List<ColumnMetadata> schema) {
for (int columnIndex = 0; columnIndex < schema.size(); columnIndex++) {
ColumnMetadata column = schema.get(columnIndex);
Object value = row.getField(columnIndex);
if (value != null) {
if (BOOLEAN.equals(column.getType())) {
assertInstanceOf(value, Boolean.class);
} else if (TINYINT.equals(column.getType())) {
assertInstanceOf(value, Byte.class);
} else if (SMALLINT.equals(column.getType())) {
assertInstanceOf(value, Short.class);
} else if (INTEGER.equals(column.getType())) {
assertInstanceOf(value, Integer.class);
} else if (BIGINT.equals(column.getType())) {
assertInstanceOf(value, Long.class);
} else if (DOUBLE.equals(column.getType())) {
assertInstanceOf(value, Double.class);
} else if (REAL.equals(column.getType())) {
assertInstanceOf(value, Float.class);
} else if (isVarcharType(column.getType())) {
assertInstanceOf(value, String.class);
} else if (isCharType(column.getType())) {
assertInstanceOf(value, String.class);
} else if (VARBINARY.equals(column.getType())) {
assertInstanceOf(value, SqlVarbinary.class);
} else if (TIMESTAMP.equals(column.getType())) {
assertInstanceOf(value, SqlTimestamp.class);
} else if (DATE.equals(column.getType())) {
assertInstanceOf(value, SqlDate.class);
} else if (column.getType() instanceof ArrayType || column.getType() instanceof RowType) {
assertInstanceOf(value, List.class);
} else if (column.getType() instanceof MapType) {
assertInstanceOf(value, Map.class);
} else {
fail("Unknown primitive type " + columnIndex);
}
}
}
}
use of com.facebook.presto.common.type.ArrayType in project presto by prestodb.
the class AbstractMinMaxNAggregationFunction method generateAggregation.
protected InternalAggregationFunction generateAggregation(Type type) {
DynamicClassLoader classLoader = new DynamicClassLoader(AbstractMinMaxNAggregationFunction.class.getClassLoader());
BlockComparator comparator = typeToComparator.apply(type);
List<Type> inputTypes = ImmutableList.of(type, BIGINT);
MinMaxNStateSerializer stateSerializer = new MinMaxNStateSerializer(comparator, type);
Type intermediateType = stateSerializer.getSerializedType();
ArrayType outputType = new ArrayType(type);
List<ParameterMetadata> inputParameterMetadata = ImmutableList.of(new ParameterMetadata(STATE), new ParameterMetadata(BLOCK_INPUT_CHANNEL, type), new ParameterMetadata(INPUT_CHANNEL, BIGINT), new ParameterMetadata(BLOCK_INDEX));
AggregationMetadata metadata = new AggregationMetadata(generateAggregationName(getSignature().getNameSuffix(), type.getTypeSignature(), inputTypes.stream().map(Type::getTypeSignature).collect(toImmutableList())), inputParameterMetadata, INPUT_FUNCTION.bindTo(comparator).bindTo(type), COMBINE_FUNCTION, OUTPUT_FUNCTION.bindTo(outputType), ImmutableList.of(new AccumulatorStateDescriptor(MinMaxNState.class, stateSerializer, new MinMaxNStateFactory())), outputType);
GenericAccumulatorFactoryBinder factory = AccumulatorCompiler.generateAccumulatorFactoryBinder(metadata, classLoader);
return new InternalAggregationFunction(getSignature().getNameSuffix(), inputTypes, ImmutableList.of(intermediateType), outputType, true, false, factory);
}
use of com.facebook.presto.common.type.ArrayType in project presto by prestodb.
the class TestExpressionCompiler method testNullif.
@Test
public void testNullif() throws Exception {
assertExecute("nullif(NULL, NULL)", UNKNOWN, null);
assertExecute("nullif(NULL, 2)", UNKNOWN, null);
assertExecute("nullif(2, NULL)", INTEGER, 2);
assertExecute("nullif(BIGINT '2', NULL)", BIGINT, 2L);
assertExecute("nullif(ARRAY[CAST(1 AS BIGINT)], ARRAY[CAST(1 AS BIGINT)])", new ArrayType(BIGINT), null);
assertExecute("nullif(ARRAY[CAST(1 AS BIGINT)], ARRAY[CAST(NULL AS BIGINT)])", new ArrayType(BIGINT), ImmutableList.of(1L));
assertExecute("nullif(ARRAY[CAST(NULL AS BIGINT)], ARRAY[CAST(NULL AS BIGINT)])", new ArrayType(BIGINT), singletonList(null));
// Test coercion in which the CAST function takes ConnectorSession (e.g. MapToMapCast)
assertExecute("nullif(" + "map(array[1], array[smallint '1']), " + "map(array[1], array[integer '1']))", mapType(INTEGER, SMALLINT), null);
Futures.allAsList(futures).get();
}
Aggregations