Search in sources :

Example 61 with Type

use of com.facebook.presto.spi.type.Type in project presto by prestodb.

the class AccumuloRecordCursor method getObject.

@Override
public Object getObject(int field) {
    Type type = getType(field);
    checkArgument(Types.isArrayType(type) || Types.isMapType(type), "Expected field %s to be a type of array or map but is %s", field, type);
    if (Types.isArrayType(type)) {
        return serializer.getArray(fieldToColumnName[field], type);
    }
    return serializer.getMap(fieldToColumnName[field], type);
}
Also used : Type(com.facebook.presto.spi.type.Type) VarbinaryType(com.facebook.presto.spi.type.VarbinaryType) VarcharType(com.facebook.presto.spi.type.VarcharType)

Example 62 with Type

use of com.facebook.presto.spi.type.Type in project presto by prestodb.

the class TestField method testDouble.

@Test
public void testDouble() throws Exception {
    Type type = DOUBLE;
    Double expected = 123.45678;
    Field f1 = new Field(expected, type);
    assertEquals(f1.getDouble(), expected);
    assertEquals(f1.getObject(), expected);
    assertEquals(f1.getType(), type);
    assertEquals(f1.toString(), "123.45678");
    Field f2 = new Field(f1);
    assertEquals(f2, f1);
}
Also used : 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 63 with Type

use of com.facebook.presto.spi.type.Type in project presto by prestodb.

the class TestField method testTime.

@Test
public void testTime() throws Exception {
    Type type = TIME;
    Time expected = new Time(new GregorianCalendar(1999, 0, 1, 12, 30, 0).getTime().getTime());
    Field f1 = new Field(expected, type);
    assertEquals(f1.getTime(), expected);
    assertEquals(f1.getObject(), expected);
    assertEquals(f1.getType(), type);
    assertEquals(f1.toString(), "TIME '12:30:00'");
    Field f2 = new Field(f1);
    assertEquals(f2, f1);
}
Also used : ArrayType(com.facebook.presto.type.ArrayType) MapType(com.facebook.presto.type.MapType) Type(com.facebook.presto.spi.type.Type) GregorianCalendar(java.util.GregorianCalendar) Time(java.sql.Time) Test(org.testng.annotations.Test)

Example 64 with Type

use of com.facebook.presto.spi.type.Type in project presto by prestodb.

the class TestField method testInt.

@Test
public void testInt() throws Exception {
    Type type = INTEGER;
    Integer expected = 12345678;
    Field f1 = new Field(expected, type);
    assertEquals(f1.getInt(), expected);
    assertEquals(f1.getObject(), expected);
    assertEquals(f1.getType(), type);
    assertEquals(f1.toString(), "12345678");
    Field f2 = new Field(f1);
    assertEquals(f2, f1);
}
Also used : 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 65 with Type

use of com.facebook.presto.spi.type.Type in project presto by prestodb.

the class TestField method testVarbinary.

@Test
public void testVarbinary() throws Exception {
    Type type = VARBINARY;
    byte[] expected = "O'Leary".getBytes(UTF_8);
    Field f1 = new Field(expected, type);
    assertEquals(f1.getVarbinary(), expected);
    assertEquals(f1.getObject(), expected);
    assertEquals(f1.getType(), type);
    assertEquals(f1.toString(), "CAST('O''Leary' AS VARBINARY)");
    Field f2 = new Field(f1);
    assertEquals(f2, f1);
}
Also used : ArrayType(com.facebook.presto.type.ArrayType) MapType(com.facebook.presto.type.MapType) Type(com.facebook.presto.spi.type.Type) Test(org.testng.annotations.Test)

Aggregations

Type (com.facebook.presto.spi.type.Type)392 Test (org.testng.annotations.Test)103 Block (com.facebook.presto.spi.block.Block)83 ImmutableList (com.google.common.collect.ImmutableList)79 ArrayType (com.facebook.presto.type.ArrayType)78 MapType (com.facebook.presto.type.MapType)72 Page (com.facebook.presto.spi.Page)68 PrestoException (com.facebook.presto.spi.PrestoException)51 List (java.util.List)50 VarcharType (com.facebook.presto.spi.type.VarcharType)48 DecimalType (com.facebook.presto.spi.type.DecimalType)44 BlockBuilder (com.facebook.presto.spi.block.BlockBuilder)40 MaterializedResult (com.facebook.presto.testing.MaterializedResult)40 ArrayList (java.util.ArrayList)40 MethodHandle (java.lang.invoke.MethodHandle)39 PlanNodeId (com.facebook.presto.sql.planner.plan.PlanNodeId)37 ImmutableMap (com.google.common.collect.ImmutableMap)36 Map (java.util.Map)36 Slice (io.airlift.slice.Slice)35 BlockBuilderStatus (com.facebook.presto.spi.block.BlockBuilderStatus)30