Search in sources :

Example 11 with ArrayType

use of io.prestosql.spi.type.ArrayType in project hetu-core by openlookeng.

the class TestArrayOperators method testStackRepresentation.

@Test
public void testStackRepresentation() {
    Block actualBlock = arrayBlockOf(new ArrayType(BIGINT), arrayBlockOf(BIGINT, 1L, 2L), arrayBlockOf(BIGINT, 3L));
    DynamicSliceOutput actualSliceOutput = new DynamicSliceOutput(100);
    writeBlock(functionAssertions.getMetadata().getFunctionAndTypeManager().getBlockEncodingSerde(), actualSliceOutput, actualBlock);
    Block expectedBlock = new ArrayType(BIGINT).createBlockBuilder(null, 3).appendStructure(BIGINT.createBlockBuilder(null, 2).writeLong(1).closeEntry().writeLong(2).closeEntry().build()).appendStructure(BIGINT.createBlockBuilder(null, 1).writeLong(3).closeEntry().build()).build();
    DynamicSliceOutput expectedSliceOutput = new DynamicSliceOutput(100);
    writeBlock(functionAssertions.getMetadata().getFunctionAndTypeManager().getBlockEncodingSerde(), expectedSliceOutput, expectedBlock);
    assertEquals(actualSliceOutput.slice(), expectedSliceOutput.slice());
}
Also used : ArrayType(io.prestosql.spi.type.ArrayType) BlockSerdeUtil.writeBlock(io.hetu.core.transport.block.BlockSerdeUtil.writeBlock) Block(io.prestosql.spi.block.Block) DynamicSliceOutput(io.airlift.slice.DynamicSliceOutput) Test(org.testng.annotations.Test)

Example 12 with ArrayType

use of io.prestosql.spi.type.ArrayType in project hetu-core by openlookeng.

the class TestArrayOperators method testConstructor.

@Test
public void testConstructor() {
    assertFunction("ARRAY []", new ArrayType(UNKNOWN), ImmutableList.of());
    assertFunction("ARRAY [NULL]", new ArrayType(UNKNOWN), Lists.newArrayList((Object) null));
    assertFunction("ARRAY [1, 2, 3]", new ArrayType(INTEGER), ImmutableList.of(1, 2, 3));
    assertFunction("ARRAY [1, NULL, 3]", new ArrayType(INTEGER), Lists.newArrayList(1, null, 3));
    assertFunction("ARRAY [NULL, 2, 3]", new ArrayType(INTEGER), Lists.newArrayList(null, 2, 3));
    assertFunction("ARRAY [1, 2.0E0, 3]", new ArrayType(DOUBLE), ImmutableList.of(1.0, 2.0, 3.0));
    assertFunction("ARRAY [ARRAY[1, 2], ARRAY[3]]", new ArrayType(new ArrayType(INTEGER)), ImmutableList.of(ImmutableList.of(1, 2), ImmutableList.of(3)));
    assertFunction("ARRAY [ARRAY[1, 2], NULL, ARRAY[3]]", new ArrayType(new ArrayType(INTEGER)), Lists.newArrayList(ImmutableList.of(1, 2), null, ImmutableList.of(3)));
    assertFunction("ARRAY [BIGINT '1', 2, 3]", new ArrayType(BIGINT), ImmutableList.of(1L, 2L, 3L));
    assertFunction("ARRAY [1, CAST (NULL AS BIGINT), 3]", new ArrayType(BIGINT), Lists.newArrayList(1L, null, 3L));
    assertFunction("ARRAY [NULL, 20000000000, 30000000000]", new ArrayType(BIGINT), Lists.newArrayList(null, 20000000000L, 30000000000L));
    assertFunction("ARRAY [1, 2.0E0, 3]", new ArrayType(DOUBLE), ImmutableList.of(1.0, 2.0, 3.0));
    assertFunction("ARRAY [ARRAY[1, 2], ARRAY[3]]", new ArrayType(new ArrayType(INTEGER)), ImmutableList.of(ImmutableList.of(1, 2), ImmutableList.of(3)));
    assertFunction("ARRAY [ARRAY[1, 2], NULL, ARRAY[3]]", new ArrayType(new ArrayType(INTEGER)), Lists.newArrayList(ImmutableList.of(1, 2), null, ImmutableList.of(3)));
    assertFunction("ARRAY [ARRAY[1, 2], NULL, ARRAY[BIGINT '3']]", new ArrayType(new ArrayType(BIGINT)), Lists.newArrayList(ImmutableList.of(1L, 2L), null, ImmutableList.of(3L)));
    assertFunction("ARRAY [1.0E0, 2.5E0, 3.0E0]", new ArrayType(DOUBLE), ImmutableList.of(1.0, 2.5, 3.0));
    assertFunction("ARRAY [1, 2.5E0, 3]", new ArrayType(DOUBLE), ImmutableList.of(1.0, 2.5, 3.0));
    assertFunction("ARRAY ['puppies', 'kittens']", new ArrayType(createVarcharType(7)), ImmutableList.of("puppies", "kittens"));
    assertFunction("ARRAY [TRUE, FALSE]", new ArrayType(BOOLEAN), ImmutableList.of(true, false));
    assertFunction("ARRAY [TIMESTAMP '1970-01-01 00:00:01', TIMESTAMP '1973-07-08 22:00:01']", new ArrayType(TIMESTAMP), ImmutableList.of(sqlTimestampOf(1970, 1, 1, 0, 0, 1, 0), sqlTimestampOf(1973, 7, 8, 22, 0, 1, 0)));
    assertFunction("ARRAY [sqrt(-1)]", new ArrayType(DOUBLE), ImmutableList.of(NaN));
    assertFunction("ARRAY [pow(infinity(), 2)]", new ArrayType(DOUBLE), ImmutableList.of(POSITIVE_INFINITY));
    assertFunction("ARRAY [pow(-infinity(), 1)]", new ArrayType(DOUBLE), ImmutableList.of(NEGATIVE_INFINITY));
    assertFunction("ARRAY [ARRAY [], NULL]", new ArrayType(new ArrayType(UNKNOWN)), asList(ImmutableList.of(), null));
    assertFunction("ARRAY [ARRAY[1.0], ARRAY[2.0, 3.0]]", new ArrayType(new ArrayType(createDecimalType(2, 1))), asList(asList(decimal("1.0")), asList(decimal("2.0"), decimal("3.0"))));
    assertFunction("ARRAY[1.0, 2.0, 3.11]", new ArrayType(createDecimalType(3, 2)), asList(decimal("1.00"), decimal("2.00"), decimal("3.11")));
    assertFunction("ARRAY[1, 2.0, 3.11]", new ArrayType(createDecimalType(12, 2)), asList(decimal("0000000001.00"), decimal("0000000002.00"), decimal("0000000003.11")));
    assertFunction("ARRAY [ARRAY[1.0], ARRAY[2.0, 123456789123456.789]]", new ArrayType(new ArrayType(createDecimalType(18, 3))), asList(asList(decimal("000000000000001.000")), asList(decimal("000000000000002.000"), decimal("123456789123456.789"))));
}
Also used : ArrayType(io.prestosql.spi.type.ArrayType) Test(org.testng.annotations.Test)

Example 13 with ArrayType

use of io.prestosql.spi.type.ArrayType in project hetu-core by openlookeng.

the class TestArrayOperators method testReverse.

@Test
public void testReverse() {
    assertFunction("REVERSE(ARRAY[1])", new ArrayType(INTEGER), ImmutableList.of(1));
    assertFunction("REVERSE(ARRAY[1, 2, 3, 4])", new ArrayType(INTEGER), ImmutableList.of(4, 3, 2, 1));
    assertFunction("REVERSE(ARRAY_SORT(ARRAY[2, 3, 4, 1]))", new ArrayType(INTEGER), ImmutableList.of(4, 3, 2, 1));
    assertFunction("REVERSE(ARRAY[2, BIGINT '3', 4, 1])", new ArrayType(BIGINT), ImmutableList.of(1L, 4L, 3L, 2L));
    assertFunction("REVERSE(ARRAY['a', 'b', 'c', 'd'])", new ArrayType(createVarcharType(1)), ImmutableList.of("d", "c", "b", "a"));
    assertFunction("REVERSE(ARRAY[TRUE, FALSE])", new ArrayType(BOOLEAN), ImmutableList.of(false, true));
    assertFunction("REVERSE(ARRAY[1.1E0, 2.2E0, 3.3E0, 4.4E0])", new ArrayType(DOUBLE), ImmutableList.of(4.4, 3.3, 2.2, 1.1));
    assertCachedInstanceHasBoundedRetainedSize("REVERSE(ARRAY[1.1E0, 2.2E0, 3.3E0, 4.4E0])");
}
Also used : ArrayType(io.prestosql.spi.type.ArrayType) Test(org.testng.annotations.Test)

Example 14 with ArrayType

use of io.prestosql.spi.type.ArrayType in project hetu-core by openlookeng.

the class TestArrayOperators method assertArrayHashOperator.

private void assertArrayHashOperator(String inputArray, Type elementType, List<Object> elements) {
    ArrayType arrayType = new ArrayType(elementType);
    BlockBuilder arrayArrayBuilder = arrayType.createBlockBuilder(null, 1);
    BlockBuilder arrayBuilder = elementType.createBlockBuilder(null, elements.size());
    for (Object element : elements) {
        appendToBlockBuilder(elementType, element, arrayBuilder);
    }
    arrayType.writeObject(arrayArrayBuilder, arrayBuilder.build());
    assertOperator(HASH_CODE, inputArray, BIGINT, arrayType.hash(arrayArrayBuilder.build(), 0));
}
Also used : ArrayType(io.prestosql.spi.type.ArrayType) BlockBuilder(io.prestosql.spi.block.BlockBuilder) StructuralTestUtil.appendToBlockBuilder(io.prestosql.util.StructuralTestUtil.appendToBlockBuilder)

Example 15 with ArrayType

use of io.prestosql.spi.type.ArrayType in project hetu-core by openlookeng.

the class TestArrayOperators method testTypeConstructor.

@Test
public void testTypeConstructor() {
    assertFunction("ARRAY[7]", new ArrayType(INTEGER), ImmutableList.of(7));
    assertFunction("ARRAY[12.34E0, 56.78E0]", new ArrayType(DOUBLE), ImmutableList.of(12.34, 56.78));
}
Also used : ArrayType(io.prestosql.spi.type.ArrayType) Test(org.testng.annotations.Test)

Aggregations

ArrayType (io.prestosql.spi.type.ArrayType)250 Test (org.testng.annotations.Test)182 RowType (io.prestosql.spi.type.RowType)100 Type (io.prestosql.spi.type.Type)99 List (java.util.List)86 ImmutableList (com.google.common.collect.ImmutableList)84 ArrayList (java.util.ArrayList)73 Arrays.asList (java.util.Arrays.asList)64 Collections.singletonList (java.util.Collections.singletonList)64 MessageType (org.apache.parquet.schema.MessageType)58 MessageTypeParser.parseMessageType (org.apache.parquet.schema.MessageTypeParser.parseMessageType)54 VarcharType.createUnboundedVarcharType (io.prestosql.spi.type.VarcharType.createUnboundedVarcharType)53 DecimalType.createDecimalType (io.prestosql.spi.type.DecimalType.createDecimalType)49 StructuralTestUtil.mapType (io.prestosql.tests.StructuralTestUtil.mapType)48 MapType (io.prestosql.spi.type.MapType)31 BigInteger (java.math.BigInteger)24 Map (java.util.Map)23 HashMap (java.util.HashMap)21 Block (io.prestosql.spi.block.Block)20 VarcharType (io.prestosql.spi.type.VarcharType)20