Search in sources :

Example 1 with ArrayType

use of com.facebook.presto.type.ArrayType in project presto by prestodb.

the class AbstractTestAccumuloRowSerializer method testArray.

@Test
public void testArray() throws Exception {
    AccumuloRowSerializer serializer = serializerClass.getConstructor().newInstance();
    Type type = new ArrayType(VARCHAR);
    List<Object> expected = ImmutableList.of("a", "b", "c");
    byte[] data = serializer.encode(type, AccumuloRowSerializer.getBlockFromArray(VARCHAR, expected));
    List<Object> actual = serializer.decode(type, data);
    assertEquals(actual, expected);
    deserializeData(serializer, data);
    actual = AccumuloRowSerializer.getArrayFromBlock(VARCHAR, serializer.getArray(COLUMN_NAME, type));
    assertEquals(actual, expected);
}
Also used : ArrayType(com.facebook.presto.type.ArrayType) ArrayType(com.facebook.presto.type.ArrayType) MapType(com.facebook.presto.type.MapType) Type(com.facebook.presto.spi.type.Type) Test(org.testng.annotations.Test)

Example 2 with ArrayType

use of com.facebook.presto.type.ArrayType in project presto by prestodb.

the class TestIndexer method setupClass.

@BeforeClass
public void setupClass() throws Exception {
    AccumuloColumnHandle c1 = new AccumuloColumnHandle("id", Optional.empty(), Optional.empty(), VARCHAR, 0, "", false);
    AccumuloColumnHandle c2 = new AccumuloColumnHandle("age", Optional.of("cf"), Optional.of("age"), BIGINT, 1, "", true);
    AccumuloColumnHandle c3 = new AccumuloColumnHandle("firstname", Optional.of("cf"), Optional.of("firstname"), VARCHAR, 2, "", true);
    AccumuloColumnHandle c4 = new AccumuloColumnHandle("arr", Optional.of("cf"), Optional.of("arr"), new ArrayType(VARCHAR), 3, "", true);
    table = new AccumuloTable("default", "index_test_table", ImmutableList.of(c1, c2, c3, c4), "id", true, LexicoderRowSerializer.class.getCanonicalName(), null);
    m1 = new Mutation(M1_ROWID);
    m1.put(CF, AGE, AGE_VALUE);
    m1.put(CF, FIRSTNAME, M1_FNAME_VALUE);
    m1.put(CF, SENDERS, M1_ARR_VALUE);
    m2 = new Mutation(M2_ROWID);
    m2.put(CF, AGE, AGE_VALUE);
    m2.put(CF, FIRSTNAME, M2_FNAME_VALUE);
    m2.put(CF, SENDERS, M2_ARR_VALUE);
    ColumnVisibility visibility1 = new ColumnVisibility("private");
    ColumnVisibility visibility2 = new ColumnVisibility("moreprivate");
    m1v = new Mutation(M1_ROWID);
    m1v.put(CF, AGE, visibility1, AGE_VALUE);
    m1v.put(CF, FIRSTNAME, visibility1, M1_FNAME_VALUE);
    m1v.put(CF, SENDERS, visibility2, M1_ARR_VALUE);
    m2v = new Mutation(M2_ROWID);
    m2v.put(CF, AGE, visibility1, AGE_VALUE);
    m2v.put(CF, FIRSTNAME, visibility2, M2_FNAME_VALUE);
    m2v.put(CF, SENDERS, visibility2, M2_ARR_VALUE);
}
Also used : ArrayType(com.facebook.presto.type.ArrayType) AccumuloTable(com.facebook.presto.accumulo.metadata.AccumuloTable) AccumuloColumnHandle(com.facebook.presto.accumulo.model.AccumuloColumnHandle) Mutation(org.apache.accumulo.core.data.Mutation) ColumnVisibility(org.apache.accumulo.core.security.ColumnVisibility) BeforeClass(org.testng.annotations.BeforeClass)

Example 3 with ArrayType

use of com.facebook.presto.type.ArrayType in project presto by prestodb.

the class TestRow method testRowFromString.

@Test
public void testRowFromString() throws Exception {
    Row expected = new Row();
    expected.addField(new Field(AccumuloRowSerializer.getBlockFromArray(VARCHAR, ImmutableList.of("a", "b", "c")), new ArrayType(VARCHAR)));
    expected.addField(true, BOOLEAN);
    expected.addField(new Field(new Date(TimeUnit.MILLISECONDS.toDays(new GregorianCalendar(1999, 0, 1).getTime().getTime())), DATE));
    expected.addField(123.45678, DOUBLE);
    expected.addField(new Field(123.45678f, REAL));
    expected.addField(12345678, INTEGER);
    expected.addField(new Field(12345678L, BIGINT));
    expected.addField(new Field((short) 12345, SMALLINT));
    expected.addField(new GregorianCalendar(1999, 0, 1, 12, 30, 0).getTime().getTime(), TIME);
    expected.addField(new Field(new Timestamp(new GregorianCalendar(1999, 0, 1, 12, 30, 0).getTime().getTime()), TIMESTAMP));
    expected.addField((byte) 123, TINYINT);
    expected.addField(new Field("O'Leary".getBytes(UTF_8), VARBINARY));
    expected.addField("O'Leary", VARCHAR);
    expected.addField(null, VARCHAR);
    RowSchema schema = new RowSchema();
    schema.addRowId("a", new ArrayType(VARCHAR));
    schema.addColumn("b", Optional.of("b"), Optional.of("b"), BOOLEAN);
    schema.addColumn("c", Optional.of("c"), Optional.of("c"), DATE);
    schema.addColumn("d", Optional.of("d"), Optional.of("d"), DOUBLE);
    schema.addColumn("e", Optional.of("e"), Optional.of("e"), REAL);
    schema.addColumn("f", Optional.of("f"), Optional.of("f"), INTEGER);
    schema.addColumn("g", Optional.of("g"), Optional.of("g"), BIGINT);
    schema.addColumn("h", Optional.of("h"), Optional.of("h"), SMALLINT);
    schema.addColumn("i", Optional.of("i"), Optional.of("i"), TIME);
    schema.addColumn("j", Optional.of("j"), Optional.of("j"), TIMESTAMP);
    schema.addColumn("k", Optional.of("k"), Optional.of("k"), TINYINT);
    schema.addColumn("l", Optional.of("l"), Optional.of("l"), VARBINARY);
    schema.addColumn("m", Optional.of("m"), Optional.of("m"), VARCHAR);
    schema.addColumn("n", Optional.of("n"), Optional.of("n"), VARCHAR);
    Row actual = Row.fromString(schema, "a,b,c|true|1999-01-01|123.45678|123.45678|12345678|12345678|12345|12:30:00|1999-01-01 12:30:00.0|123|O'Leary|O'Leary|", '|');
    assertEquals(actual, expected);
}
Also used : ArrayType(com.facebook.presto.type.ArrayType) GregorianCalendar(java.util.GregorianCalendar) Timestamp(java.sql.Timestamp) Date(java.sql.Date) Test(org.testng.annotations.Test)

Example 4 with ArrayType

use of com.facebook.presto.type.ArrayType in project presto by prestodb.

the class TestRow method testRow.

@Test
public void testRow() throws Exception {
    Row r1 = new Row();
    r1.addField(new Field(AccumuloRowSerializer.getBlockFromArray(VARCHAR, ImmutableList.of("a", "b", "c")), new ArrayType(VARCHAR)));
    r1.addField(true, BOOLEAN);
    r1.addField(new Field(new Date(new GregorianCalendar(1999, 0, 1).getTime().getTime()), DATE));
    r1.addField(123.45678, DOUBLE);
    r1.addField(new Field(123.45678f, REAL));
    r1.addField(12345678, INTEGER);
    r1.addField(new Field(12345678L, BIGINT));
    r1.addField(new Field((short) 12345, SMALLINT));
    r1.addField(new GregorianCalendar(1999, 0, 1, 12, 30, 0).getTime().getTime(), TIME);
    r1.addField(new Field(new Timestamp(new GregorianCalendar(1999, 0, 1, 12, 30, 0).getTime().getTime()), TIMESTAMP));
    r1.addField((byte) 123, TINYINT);
    r1.addField(new Field("O'Leary".getBytes(UTF_8), VARBINARY));
    r1.addField("O'Leary", VARCHAR);
    r1.addField(null, VARCHAR);
    assertEquals(r1.length(), 14);
    assertEquals(r1.toString(), "(ARRAY ['a','b','c'],true,DATE '1999-01-01',123.45678,123.45678,12345678,12345678,12345,TIME '12:30:00',TIMESTAMP '1999-01-01 12:30:00.0',123,CAST('O''Leary' AS VARBINARY),'O''Leary',null)");
    Row r2 = new Row(r1);
    assertEquals(r2, r1);
}
Also used : ArrayType(com.facebook.presto.type.ArrayType) GregorianCalendar(java.util.GregorianCalendar) Timestamp(java.sql.Timestamp) Date(java.sql.Date) Test(org.testng.annotations.Test)

Example 5 with ArrayType

use of com.facebook.presto.type.ArrayType in project presto by prestodb.

the class TestSerDeUtils method testStructBlock.

@Test
public void testStructBlock() {
    // test simple structs
    InnerStruct innerStruct = new InnerStruct(13, 14L);
    com.facebook.presto.spi.type.Type rowType = new RowType(ImmutableList.of(INTEGER, BIGINT), Optional.empty());
    Block actual = toBinaryBlock(rowType, innerStruct, getInspector(InnerStruct.class));
    Block expected = rowBlockOf(ImmutableList.of(INTEGER, BIGINT), 13, 14L);
    assertBlockEquals(actual, expected);
    // test complex structs
    OuterStruct outerStruct = new OuterStruct();
    outerStruct.byteVal = (byte) 1;
    outerStruct.shortVal = (short) 2;
    outerStruct.intVal = 3;
    outerStruct.longVal = 4L;
    outerStruct.floatVal = 5.01f;
    outerStruct.doubleVal = 6.001d;
    outerStruct.stringVal = "seven";
    outerStruct.byteArray = new byte[] { '2' };
    InnerStruct is1 = new InnerStruct(2, -5L);
    InnerStruct is2 = new InnerStruct(-10, 0L);
    outerStruct.structArray = new ArrayList<>(2);
    outerStruct.structArray.add(is1);
    outerStruct.structArray.add(is2);
    outerStruct.map = new TreeMap<>();
    outerStruct.map.put("twelve", new InnerStruct(0, 5L));
    outerStruct.map.put("fifteen", new InnerStruct(-5, -10L));
    outerStruct.innerStruct = new InnerStruct(18, 19L);
    com.facebook.presto.spi.type.Type innerRowType = new RowType(ImmutableList.of(INTEGER, BIGINT), Optional.empty());
    com.facebook.presto.spi.type.Type arrayOfInnerRowType = new ArrayType(innerRowType);
    com.facebook.presto.spi.type.Type mapOfInnerRowType = new MapType(createUnboundedVarcharType(), innerRowType);
    List<com.facebook.presto.spi.type.Type> outerRowParameterTypes = ImmutableList.of(TINYINT, SMALLINT, INTEGER, BIGINT, REAL, DOUBLE, createUnboundedVarcharType(), createUnboundedVarcharType(), arrayOfInnerRowType, mapOfInnerRowType, innerRowType);
    com.facebook.presto.spi.type.Type outerRowType = new RowType(outerRowParameterTypes, Optional.empty());
    actual = toBinaryBlock(outerRowType, outerStruct, getInspector(OuterStruct.class));
    ImmutableList.Builder<Object> outerRowValues = ImmutableList.builder();
    outerRowValues.add((byte) 1);
    outerRowValues.add((short) 2);
    outerRowValues.add(3);
    outerRowValues.add(4L);
    outerRowValues.add(5.01f);
    outerRowValues.add(6.001d);
    outerRowValues.add("seven");
    outerRowValues.add(new byte[] { '2' });
    outerRowValues.add(arrayBlockOf(innerRowType, rowBlockOf(ImmutableList.of(INTEGER, BIGINT), 2, -5L), rowBlockOf(ImmutableList.of(INTEGER, BIGINT), -10, 0L)));
    BlockBuilder blockBuilder = new InterleavedBlockBuilder(ImmutableList.of(createUnboundedVarcharType(), innerRowType), new BlockBuilderStatus(), 1024);
    createUnboundedVarcharType().writeString(blockBuilder, "fifteen");
    innerRowType.writeObject(blockBuilder, rowBlockOf(ImmutableList.of(INTEGER, BIGINT), -5, -10L));
    createUnboundedVarcharType().writeString(blockBuilder, "twelve");
    innerRowType.writeObject(blockBuilder, rowBlockOf(ImmutableList.of(INTEGER, BIGINT), 0, 5L));
    outerRowValues.add(blockBuilder.build());
    outerRowValues.add(rowBlockOf(ImmutableList.of(INTEGER, BIGINT), 18, 19L));
    assertBlockEquals(actual, rowBlockOf(outerRowParameterTypes, outerRowValues.build().toArray()));
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) RowType(com.facebook.presto.type.RowType) InterleavedBlockBuilder(com.facebook.presto.spi.block.InterleavedBlockBuilder) MapType(com.facebook.presto.type.MapType) ArrayType(com.facebook.presto.type.ArrayType) ArrayType(com.facebook.presto.type.ArrayType) MapType(com.facebook.presto.type.MapType) RowType(com.facebook.presto.type.RowType) VarcharType.createUnboundedVarcharType(com.facebook.presto.spi.type.VarcharType.createUnboundedVarcharType) Type(java.lang.reflect.Type) Block(com.facebook.presto.spi.block.Block) SerDeUtils.getBlockObject(com.facebook.presto.hive.util.SerDeUtils.getBlockObject) SerDeUtils.serializeObject(com.facebook.presto.hive.util.SerDeUtils.serializeObject) BlockBuilder(com.facebook.presto.spi.block.BlockBuilder) InterleavedBlockBuilder(com.facebook.presto.spi.block.InterleavedBlockBuilder) BlockBuilderStatus(com.facebook.presto.spi.block.BlockBuilderStatus) Test(org.testng.annotations.Test)

Aggregations

ArrayType (com.facebook.presto.type.ArrayType)71 Test (org.testng.annotations.Test)45 MapType (com.facebook.presto.type.MapType)27 Type (com.facebook.presto.spi.type.Type)26 BlockBuilder (com.facebook.presto.spi.block.BlockBuilder)15 Block (com.facebook.presto.spi.block.Block)13 BlockBuilderStatus (com.facebook.presto.spi.block.BlockBuilderStatus)13 RowType (com.facebook.presto.type.RowType)12 ImmutableList (com.google.common.collect.ImmutableList)11 Signature (com.facebook.presto.metadata.Signature)7 ArrayList (java.util.ArrayList)7 List (java.util.List)7 DynamicClassLoader (com.facebook.presto.bytecode.DynamicClassLoader)6 MetadataManager (com.facebook.presto.metadata.MetadataManager)6 MetadataManager.createTestMetadataManager (com.facebook.presto.metadata.MetadataManager.createTestMetadataManager)5 Page (com.facebook.presto.spi.Page)5 InterleavedBlockBuilder (com.facebook.presto.spi.block.InterleavedBlockBuilder)5 ImmutableMap (com.google.common.collect.ImmutableMap)5 TypeSignature.parseTypeSignature (com.facebook.presto.spi.type.TypeSignature.parseTypeSignature)4 MaterializedResult (com.facebook.presto.testing.MaterializedResult)4