Search in sources :

Example 41 with ArrayType

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)));
}
Also used : ArrayType(com.facebook.presto.common.type.ArrayType) Test(org.testng.annotations.Test)

Example 42 with ArrayType

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);
}
Also used : ArrayType(com.facebook.presto.common.type.ArrayType) HashMap(java.util.HashMap) TestRowType(com.facebook.presto.common.type.TestRowType) MapType(com.facebook.presto.common.type.MapType) Test(org.testng.annotations.Test)

Example 43 with ArrayType

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);
            }
        }
    }
}
Also used : ColumnMetadata(com.facebook.presto.spi.ColumnMetadata) SqlVarbinary(com.facebook.presto.common.type.SqlVarbinary) RowType(com.facebook.presto.common.type.RowType) OptionalDouble(java.util.OptionalDouble) Constraint(com.facebook.presto.spi.Constraint) MapType(com.facebook.presto.common.type.MapType) ArrayType(com.facebook.presto.common.type.ArrayType) SqlDate(com.facebook.presto.common.type.SqlDate) Map(java.util.Map) ImmutableMap.toImmutableMap(com.google.common.collect.ImmutableMap.toImmutableMap) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap)

Example 44 with ArrayType

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);
}
Also used : DynamicClassLoader(com.facebook.presto.bytecode.DynamicClassLoader) MinMaxNStateSerializer(com.facebook.presto.operator.aggregation.state.MinMaxNStateSerializer) AccumulatorStateDescriptor(com.facebook.presto.operator.aggregation.AggregationMetadata.AccumulatorStateDescriptor) ParameterMetadata(com.facebook.presto.operator.aggregation.AggregationMetadata.ParameterMetadata) ArrayType(com.facebook.presto.common.type.ArrayType) ArrayType(com.facebook.presto.common.type.ArrayType) Type(com.facebook.presto.common.type.Type) MinMaxNStateFactory(com.facebook.presto.operator.aggregation.state.MinMaxNStateFactory)

Example 45 with ArrayType

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();
}
Also used : ArrayType(com.facebook.presto.common.type.ArrayType) Test(org.testng.annotations.Test)

Aggregations

ArrayType (com.facebook.presto.common.type.ArrayType)287 Test (org.testng.annotations.Test)219 Type (com.facebook.presto.common.type.Type)99 RowType (com.facebook.presto.common.type.RowType)79 ArrayList (java.util.ArrayList)58 ImmutableList (com.google.common.collect.ImmutableList)54 List (java.util.List)51 MapType (com.facebook.presto.common.type.MapType)39 DecimalType.createDecimalType (com.facebook.presto.common.type.DecimalType.createDecimalType)36 Arrays.asList (java.util.Arrays.asList)34 Collections.singletonList (java.util.Collections.singletonList)33 MessageType (org.apache.parquet.schema.MessageType)30 BlockBuilder (com.facebook.presto.common.block.BlockBuilder)28 VarcharType.createUnboundedVarcharType (com.facebook.presto.common.type.VarcharType.createUnboundedVarcharType)27 MessageTypeParser.parseMessageType (org.apache.parquet.schema.MessageTypeParser.parseMessageType)27 InternalAggregationFunction (com.facebook.presto.operator.aggregation.InternalAggregationFunction)26 PrimitiveType (org.apache.parquet.schema.PrimitiveType)26 StructuralTestUtil.mapType (com.facebook.presto.tests.StructuralTestUtil.mapType)24 Block (com.facebook.presto.common.block.Block)23 DecimalType (com.facebook.presto.common.type.DecimalType)17