Java Code Examples for io.prestosql.spi.type.BigintType#BIGINT

The following examples show how to use io.prestosql.spi.type.BigintType#BIGINT . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TpcdsMetadata.java    From presto with Apache License 2.0 6 votes vote down vote up
public static Type getPrestoType(ColumnType tpcdsType)
{
    switch (tpcdsType.getBase()) {
        case IDENTIFIER:
            return BigintType.BIGINT;
        case INTEGER:
            return IntegerType.INTEGER;
        case DATE:
            return DateType.DATE;
        case DECIMAL:
            return createDecimalType(tpcdsType.getPrecision().get(), tpcdsType.getScale().get());
        case CHAR:
            return createCharType(tpcdsType.getPrecision().get());
        case VARCHAR:
            return createVarcharType(tpcdsType.getPrecision().get());
        case TIME:
            return TimeType.TIME;
    }
    throw new IllegalArgumentException("Unsupported TPC-DS type " + tpcdsType);
}
 
Example 2
Source File: PinotColumn.java    From presto with Apache License 2.0 6 votes vote down vote up
public static Type getPrestoTypeFromPinotType(DataType dataType)
{
    switch (dataType) {
        case BOOLEAN:
            return BooleanType.BOOLEAN;
        case FLOAT:
        case DOUBLE:
            return DoubleType.DOUBLE;
        case INT:
            return IntegerType.INTEGER;
        case LONG:
            return BigintType.BIGINT;
        case STRING:
            return VarcharType.VARCHAR;
        case BYTES:
            return VarbinaryType.VARBINARY;
        default:
            break;
    }
    throw new PinotException(PINOT_UNSUPPORTED_COLUMN_TYPE, Optional.empty(), "Not support type conversion for pinot data type: " + dataType);
}
 
Example 3
Source File: TestCsvDecoder.java    From presto with Apache License 2.0 6 votes vote down vote up
@Test
public void testNulls()
{
    String csv = ",,,";

    DecoderTestColumnHandle row1 = new DecoderTestColumnHandle(0, "row1", createVarcharType(10), "0", null, null, false, false, false);
    DecoderTestColumnHandle row2 = new DecoderTestColumnHandle(1, "row2", BigintType.BIGINT, "1", null, null, false, false, false);
    DecoderTestColumnHandle row3 = new DecoderTestColumnHandle(2, "row3", DoubleType.DOUBLE, "2", null, null, false, false, false);
    DecoderTestColumnHandle row4 = new DecoderTestColumnHandle(3, "row4", BooleanType.BOOLEAN, "3", null, null, false, false, false);

    Set<DecoderColumnHandle> columns = ImmutableSet.of(row1, row2, row3, row4);
    RowDecoder rowDecoder = DECODER_FACTORY.create(emptyMap(), columns);

    Map<DecoderColumnHandle, FieldValueProvider> decodedRow = rowDecoder.decodeRow(csv.getBytes(StandardCharsets.UTF_8), null)
            .orElseThrow(AssertionError::new);

    assertEquals(decodedRow.size(), columns.size());

    checkIsNull(decodedRow, row1);
    checkIsNull(decodedRow, row2);
    checkIsNull(decodedRow, row3);
    checkIsNull(decodedRow, row4);
}
 
Example 4
Source File: TestRawDecoder.java    From presto with Apache License 2.0 6 votes vote down vote up
private void checkTwice(Map<DecoderColumnHandle, FieldValueProvider> decodedRow, DecoderColumnHandle handle)
{
    FieldValueProvider provider = decodedRow.get(handle);
    assertNotNull(provider);
    Type type = handle.getType();
    if (type == BigintType.BIGINT) {
        assertEquals(provider.getLong(), provider.getLong());
    }
    else if (type == BooleanType.BOOLEAN) {
        assertEquals(provider.getBoolean(), provider.getBoolean());
    }
    else if (type == DoubleType.DOUBLE) {
        assertEquals(provider.getDouble(), provider.getDouble());
    }
    else if (type == VarcharType.VARCHAR) {
        assertEquals(provider.getSlice(), provider.getSlice());
    }
}
 
Example 5
Source File: PulsarMetadata.java    From pulsar with Apache License 2.0 5 votes vote down vote up
@VisibleForTesting
static Type convertType(Schema.Type avroType, LogicalType logicalType) {
    switch (avroType) {
        case BOOLEAN:
            return BooleanType.BOOLEAN;
        case INT:
            if (logicalType == LogicalTypes.timeMillis()) {
                return TIME;
            } else if (logicalType == LogicalTypes.date()) {
                return DATE;
            }
            return IntegerType.INTEGER;
        case LONG:
            if (logicalType == LogicalTypes.timestampMillis()) {
                return TIMESTAMP;
            }
            return BigintType.BIGINT;
        case FLOAT:
            return RealType.REAL;
        case DOUBLE:
            return DoubleType.DOUBLE;
        case BYTES:
            return VarbinaryType.VARBINARY;
        case STRING:
            return VarcharType.VARCHAR;
        case ENUM:
            return VarcharType.VARCHAR;
        default:
            log.error("Cannot convert type: %s", avroType);
            return null;
    }
}
 
Example 6
Source File: PulsarMetadata.java    From pulsar with Apache License 2.0 5 votes vote down vote up
@VisibleForTesting
static Type convertPulsarType(SchemaType pulsarType) {
    switch (pulsarType) {
        case BOOLEAN:
            return BooleanType.BOOLEAN;
        case INT8:
            return TinyintType.TINYINT;
        case INT16:
            return SmallintType.SMALLINT;
        case INT32:
            return IntegerType.INTEGER;
        case INT64:
            return BigintType.BIGINT;
        case FLOAT:
            return RealType.REAL;
        case DOUBLE:
            return DoubleType.DOUBLE;
        case NONE:
        case BYTES:
            return VarbinaryType.VARBINARY;
        case STRING:
            return VarcharType.VARCHAR;
        case DATE:
            return DateType.DATE;
        case TIME:
            return TimeType.TIME;
        case TIMESTAMP:
            return TimestampType.TIMESTAMP;
        default:
            log.error("Cannot convert type: %s", pulsarType);
            return null;
    }
}
 
Example 7
Source File: TypeHelper.java    From presto with Apache License 2.0 5 votes vote down vote up
private static Type fromKuduClientType(org.apache.kudu.Type ktype, ColumnTypeAttributes attributes)
{
    switch (ktype) {
        case STRING:
            return VarcharType.VARCHAR;
        case UNIXTIME_MICROS:
            return TimestampType.TIMESTAMP;
        case INT64:
            return BigintType.BIGINT;
        case INT32:
            return IntegerType.INTEGER;
        case INT16:
            return SmallintType.SMALLINT;
        case INT8:
            return TinyintType.TINYINT;
        case FLOAT:
            return RealType.REAL;
        case DOUBLE:
            return DoubleType.DOUBLE;
        case BOOL:
            return BooleanType.BOOLEAN;
        case BINARY:
            return VarbinaryType.VARBINARY;
        case DECIMAL:
            return DecimalType.createDecimalType(attributes.getPrecision(), attributes.getScale());
        default:
            throw new IllegalStateException("Kudu type not implemented for " + ktype);
    }
}
 
Example 8
Source File: TestCsvDecoder.java    From presto with Apache License 2.0 5 votes vote down vote up
@Test
public void testLessTokensThanColumns()
{
    String csv = "ala,10";

    DecoderTestColumnHandle column1 = new DecoderTestColumnHandle(0, "column1", createVarcharType(10), "0", null, null, false, false, false);
    DecoderTestColumnHandle column2 = new DecoderTestColumnHandle(1, "column2", BigintType.BIGINT, "1", null, null, false, false, false);
    DecoderTestColumnHandle column3 = new DecoderTestColumnHandle(2, "column3", createVarcharType(10), "2", null, null, false, false, false);
    DecoderTestColumnHandle column4 = new DecoderTestColumnHandle(0, "column4", BigintType.BIGINT, "3", null, null, false, false, false);
    DecoderTestColumnHandle column5 = new DecoderTestColumnHandle(0, "column5", DoubleType.DOUBLE, "4", null, null, false, false, false);
    DecoderTestColumnHandle column6 = new DecoderTestColumnHandle(0, "column6", BooleanType.BOOLEAN, "5", null, null, false, false, false);

    Set<DecoderColumnHandle> columns = ImmutableSet.of(column1, column2, column3, column4, column5, column6);
    RowDecoder rowDecoder = DECODER_FACTORY.create(emptyMap(), columns);

    Map<DecoderColumnHandle, FieldValueProvider> decodedRow = rowDecoder.decodeRow(csv.getBytes(StandardCharsets.UTF_8), null)
            .orElseThrow(AssertionError::new);

    assertEquals(decodedRow.size(), columns.size());

    checkValue(decodedRow, column1, "ala");
    checkValue(decodedRow, column2, 10);
    checkIsNull(decodedRow, column3);
    checkIsNull(decodedRow, column4);
    checkIsNull(decodedRow, column5);
    checkIsNull(decodedRow, column6);
}
 
Example 9
Source File: TypeHelper.java    From presto with Apache License 2.0 5 votes vote down vote up
public static Object getObject(Type type, RowResult row, int field)
{
    if (row.isNull(field)) {
        return null;
    }
    if (type instanceof VarcharType) {
        return row.getString(field);
    }
    if (type.equals(TimestampType.TIMESTAMP)) {
        return row.getLong(field) / 1000;
    }
    if (type == BigintType.BIGINT) {
        return row.getLong(field);
    }
    if (type == IntegerType.INTEGER) {
        return row.getInt(field);
    }
    if (type == SmallintType.SMALLINT) {
        return row.getShort(field);
    }
    if (type == TinyintType.TINYINT) {
        return row.getByte(field);
    }
    if (type == DoubleType.DOUBLE) {
        return row.getDouble(field);
    }
    if (type == RealType.REAL) {
        return row.getFloat(field);
    }
    if (type == BooleanType.BOOLEAN) {
        return row.getBoolean(field);
    }
    if (type instanceof VarbinaryType) {
        return Slices.wrappedBuffer(row.getBinary(field));
    }
    if (type instanceof DecimalType) {
        return row.getDecimal(field);
    }
    throw new IllegalStateException("getObject not implemented for " + type);
}
 
Example 10
Source File: TypeHelper.java    From presto with Apache License 2.0 5 votes vote down vote up
public static long getLong(Type type, RowResult row, int field)
{
    if (type.equals(TimestampType.TIMESTAMP)) {
        return row.getLong(field) / 1000;
    }
    if (type == BigintType.BIGINT) {
        return row.getLong(field);
    }
    if (type == IntegerType.INTEGER) {
        return row.getInt(field);
    }
    if (type == SmallintType.SMALLINT) {
        return row.getShort(field);
    }
    if (type == TinyintType.TINYINT) {
        return row.getByte(field);
    }
    if (type == RealType.REAL) {
        return floatToRawIntBits(row.getFloat(field));
    }
    if (type instanceof DecimalType) {
        DecimalType dtype = (DecimalType) type;
        if (dtype.isShort()) {
            return row.getDecimal(field).unscaledValue().longValue();
        }
        throw new IllegalStateException("getLong not supported for long decimal: " + type);
    }
    throw new IllegalStateException("getLong not implemented for " + type);
}
 
Example 11
Source File: TestRawDecoder.java    From presto with Apache License 2.0 5 votes vote down vote up
@Test
public void testSimple()
{
    ByteBuffer buf = ByteBuffer.allocate(36);
    buf.putLong(4815162342L); // 0 - 7
    buf.putInt(12345678); // 8 - 11
    buf.putShort((short) 4567); // 12 - 13
    buf.put((byte) 123); // 14
    buf.put("Ich bin zwei Oeltanks".getBytes(StandardCharsets.UTF_8)); // 15+

    byte[] row = new byte[buf.position()];
    System.arraycopy(buf.array(), 0, row, 0, buf.position());

    DecoderTestColumnHandle row1 = new DecoderTestColumnHandle(0, "row1", BigintType.BIGINT, "0", "LONG", null, false, false, false);
    DecoderTestColumnHandle row2 = new DecoderTestColumnHandle(1, "row2", BigintType.BIGINT, "8", "INT", null, false, false, false);
    DecoderTestColumnHandle row3 = new DecoderTestColumnHandle(2, "row3", BigintType.BIGINT, "12", "SHORT", null, false, false, false);
    DecoderTestColumnHandle row4 = new DecoderTestColumnHandle(3, "row4", BigintType.BIGINT, "14", "BYTE", null, false, false, false);
    DecoderTestColumnHandle row5 = new DecoderTestColumnHandle(4, "row5", createVarcharType(10), "15", null, null, false, false, false);

    Set<DecoderColumnHandle> columns = ImmutableSet.of(row1, row2, row3, row4, row5);
    RowDecoder rowDecoder = DECODER_FACTORY.create(emptyMap(), columns);

    Map<DecoderColumnHandle, FieldValueProvider> decodedRow = rowDecoder.decodeRow(row, null)
            .orElseThrow(AssertionError::new);

    assertEquals(decodedRow.size(), columns.size());

    checkValue(decodedRow, row1, 4815162342L);
    checkValue(decodedRow, row2, 12345678);
    checkValue(decodedRow, row3, 4567);
    checkValue(decodedRow, row4, 123);
    checkValue(decodedRow, row5, "Ich bin zw");
}
 
Example 12
Source File: TestCsvDecoder.java    From presto with Apache License 2.0 5 votes vote down vote up
@Test
public void testSimple()
{
    String csv = "\"row 1\",row2,\"row3\",100,\"200\",300,4.5";

    DecoderTestColumnHandle row1 = new DecoderTestColumnHandle(0, "row1", createVarcharType(2), "0", null, null, false, false, false);
    DecoderTestColumnHandle row2 = new DecoderTestColumnHandle(1, "row2", createVarcharType(10), "1", null, null, false, false, false);
    DecoderTestColumnHandle row3 = new DecoderTestColumnHandle(2, "row3", createVarcharType(10), "2", null, null, false, false, false);
    DecoderTestColumnHandle row4 = new DecoderTestColumnHandle(3, "row4", BigintType.BIGINT, "3", null, null, false, false, false);
    DecoderTestColumnHandle row5 = new DecoderTestColumnHandle(4, "row5", BigintType.BIGINT, "4", null, null, false, false, false);
    DecoderTestColumnHandle row6 = new DecoderTestColumnHandle(5, "row6", BigintType.BIGINT, "5", null, null, false, false, false);
    DecoderTestColumnHandle row7 = new DecoderTestColumnHandle(6, "row7", DoubleType.DOUBLE, "6", null, null, false, false, false);

    Set<DecoderColumnHandle> columns = ImmutableSet.of(row1, row2, row3, row4, row5, row6, row7);
    RowDecoder rowDecoder = DECODER_FACTORY.create(emptyMap(), columns);

    Map<DecoderColumnHandle, FieldValueProvider> decodedRow = rowDecoder.decodeRow(csv.getBytes(StandardCharsets.UTF_8), null)
            .orElseThrow(AssertionError::new);

    assertEquals(decodedRow.size(), columns.size());

    checkValue(decodedRow, row1, "ro");
    checkValue(decodedRow, row2, "row2");
    checkValue(decodedRow, row3, "row3");
    checkValue(decodedRow, row4, 100);
    checkValue(decodedRow, row5, 200);
    checkValue(decodedRow, row6, 300);
    checkValue(decodedRow, row7, 4.5d);
}
 
Example 13
Source File: TestAvroSchemaHandler.java    From pulsar with Apache License 2.0 4 votes vote down vote up
@Test
public void testAvroSchemaHandler() throws IOException {
    List<PulsarColumnHandle> columnHandles = new ArrayList();
    RawMessage message = mock(RawMessage.class);
    Schema schema1 = ReflectData.AllowNull.get().getSchema(Foo1.class);
    PulsarSqlSchemaInfoProvider pulsarSqlSchemaInfoProvider = mock(PulsarSqlSchemaInfoProvider.class);
    AvroSchemaHandler avroSchemaHandler = new AvroSchemaHandler(pulsarSqlSchemaInfoProvider,
            StructSchema.parseSchemaInfo(SchemaDefinition.builder().withPojo(Foo2.class).build(), SchemaType.AVRO), columnHandles);
    byte[] schemaVersion = new byte[8];
    for (int i = 0 ; i<8; i++) {
        schemaVersion[i] = 0;
    }
    ReflectDatumWriter<Foo1> writer;
    BinaryEncoder encoder = null;
    ByteArrayOutputStream byteArrayOutputStream;
    byteArrayOutputStream = new ByteArrayOutputStream();
    encoder = EncoderFactory.get().binaryEncoder(byteArrayOutputStream, encoder);
    writer = new ReflectDatumWriter<>(schema1);
    Foo1 foo1 = new Foo1();
    foo1.setField1("value1");
    foo1.setBar(new Bar());
    foo1.getBar().setField1("value1");
    writer.write(foo1, encoder);
    encoder.flush();
    when(message.getSchemaVersion()).thenReturn(schemaVersion);
    byte[] bytes =byteArrayOutputStream.toByteArray();

    when(message.getData()).thenReturn(ByteBufAllocator.DEFAULT
            .buffer(bytes.length, bytes.length).writeBytes(byteArrayOutputStream.toByteArray()));
    when(pulsarSqlSchemaInfoProvider.getSchemaByVersion(any()))
            .thenReturn(completedFuture(StructSchema.parseSchemaInfo(SchemaDefinition.builder()
                    .withPojo(Foo1.class).build(), SchemaType.AVRO)));

    Object object  = ((GenericAvroRecord)avroSchemaHandler.deserialize(message.getData(),
            message.getSchemaVersion())).getField("field1");
    Assert.assertEquals(foo1.field1, (String)object);
    String[] fields = new String[2];
    fields[0] = "bar";
    fields[1] = "field1";
    PulsarColumnHandle pulsarColumnHandle = new PulsarColumnHandle("test",
            "bar.field1",
            BigintType.BIGINT,
            true,
            true,
            fields,
            new Integer[5],
            null);
    columnHandles.add(pulsarColumnHandle);
    when(message.getData()).thenReturn(ByteBufAllocator.DEFAULT
            .buffer(bytes.length, bytes.length).writeBytes(byteArrayOutputStream.toByteArray()));
    object = avroSchemaHandler.extractField(0, avroSchemaHandler.deserialize(message.getData(),
            message.getSchemaVersion()));
    Assert.assertEquals(foo1.bar.field1, (String)object);
}
 
Example 14
Source File: TestRawDecoder.java    From presto with Apache License 2.0 4 votes vote down vote up
@Test
public void testGetValueTwice()
{
    ByteBuffer buf = ByteBuffer.allocate(50);
    buf.putLong(0, 4815162342L);
    buf.putInt(8, 2147483647);
    buf.putShort(12, (short) 32767);
    buf.put(14, (byte) 128);
    buf.putLong(15, 1);
    buf.putInt(23, 1);
    buf.putShort(27, (short) 1);
    buf.put(29, (byte) 1);
    buf.putDouble(30, 12345.6789d);
    buf.putFloat(38, 123.345f);
    buf.put("test val".getBytes(StandardCharsets.UTF_8)); // offset 42

    byte[] row = new byte[buf.capacity()];
    System.arraycopy(buf.array(), 0, row, 0, buf.limit());

    DecoderColumnHandle col1 = new DecoderTestColumnHandle(0, "col1", BigintType.BIGINT, "0", "LONG", null, false, false, false);
    DecoderColumnHandle col2 = new DecoderTestColumnHandle(1, "col2", BigintType.BIGINT, "8", "INT", null, false, false, false);
    DecoderColumnHandle col3 = new DecoderTestColumnHandle(2, "col3", BigintType.BIGINT, "12", "SHORT", null, false, false, false);
    DecoderColumnHandle col4 = new DecoderTestColumnHandle(3, "col4", BigintType.BIGINT, "14", "BYTE", null, false, false, false);
    DecoderColumnHandle col5 = new DecoderTestColumnHandle(4, "col5", BooleanType.BOOLEAN, "15", "LONG", null, false, false, false);
    DecoderColumnHandle col6 = new DecoderTestColumnHandle(5, "col6", BooleanType.BOOLEAN, "23", "INT", null, false, false, false);
    DecoderColumnHandle col7 = new DecoderTestColumnHandle(6, "col7", BooleanType.BOOLEAN, "27", "SHORT", null, false, false, false);
    DecoderColumnHandle col8 = new DecoderTestColumnHandle(7, "col8", BooleanType.BOOLEAN, "29", "BYTE", null, false, false, false);
    DecoderColumnHandle col9 = new DecoderTestColumnHandle(8, "col9", DoubleType.DOUBLE, "30", "DOUBLE", null, false, false, false);
    DecoderColumnHandle col10 = new DecoderTestColumnHandle(9, "col10", DoubleType.DOUBLE, "38", "FLOAT", null, false, false, false);
    DecoderColumnHandle col11 = new DecoderTestColumnHandle(10, "col11", VarcharType.VARCHAR, "42", "BYTE", null, false, false, false);

    Set<DecoderColumnHandle> columns = ImmutableSet.of(
            col1, col2, col3, col4, col5, col6, col7, col8, col9, col10, col11);

    RowDecoder rowDecoder = DECODER_FACTORY.create(emptyMap(), columns);

    Map<DecoderColumnHandle, FieldValueProvider> decodedRow = rowDecoder.decodeRow(row, null)
            .orElseThrow(AssertionError::new);

    assertEquals(decodedRow.size(), columns.size());

    for (DecoderColumnHandle handle : columns) {
        checkTwice(decodedRow, handle);
    }
}
 
Example 15
Source File: TestRawDecoder.java    From presto with Apache License 2.0 4 votes vote down vote up
@Test
public void testBooleanStuff()
{
    ByteBuffer buf = ByteBuffer.allocate(38);
    buf.put((byte) 127); // offset 0
    buf.putLong(0); // offset 1
    buf.put((byte) 126); // offset 9
    buf.putLong(1); // offset 10

    buf.put((byte) 125); // offset 18
    buf.putInt(0); // offset 19
    buf.put((byte) 124); // offset 23
    buf.putInt(1); // offset 24

    buf.put((byte) 123); // offset 28
    buf.putShort((short) 0); // offset 29
    buf.put((byte) 122); // offset 31
    buf.putShort((short) 1); // offset 32

    buf.put((byte) 121); // offset 34
    buf.put((byte) 0); // offset 35
    buf.put((byte) 120); // offset 36
    buf.put((byte) 1); // offset 37

    byte[] row = new byte[buf.position()];
    System.arraycopy(buf.array(), 0, row, 0, buf.position());

    DecoderTestColumnHandle row01 = new DecoderTestColumnHandle(0, "row01", BigintType.BIGINT, "0", "BYTE", null, false, false, false);
    DecoderTestColumnHandle row02 = new DecoderTestColumnHandle(1, "row02", BooleanType.BOOLEAN, "1", "LONG", null, false, false, false);
    DecoderTestColumnHandle row03 = new DecoderTestColumnHandle(2, "row03", BigintType.BIGINT, "9", "BYTE", null, false, false, false);
    DecoderTestColumnHandle row04 = new DecoderTestColumnHandle(3, "row04", BooleanType.BOOLEAN, "10", "LONG", null, false, false, false);

    DecoderTestColumnHandle row11 = new DecoderTestColumnHandle(4, "row11", BigintType.BIGINT, "18", "BYTE", null, false, false, false);
    DecoderTestColumnHandle row12 = new DecoderTestColumnHandle(5, "row12", BooleanType.BOOLEAN, "19", "INT", null, false, false, false);
    DecoderTestColumnHandle row13 = new DecoderTestColumnHandle(6, "row13", BigintType.BIGINT, "23", "BYTE", null, false, false, false);
    DecoderTestColumnHandle row14 = new DecoderTestColumnHandle(7, "row14", BooleanType.BOOLEAN, "24", "INT", null, false, false, false);

    DecoderTestColumnHandle row21 = new DecoderTestColumnHandle(8, "row21", BigintType.BIGINT, "28", "BYTE", null, false, false, false);
    DecoderTestColumnHandle row22 = new DecoderTestColumnHandle(9, "row22", BooleanType.BOOLEAN, "29", "SHORT", null, false, false, false);
    DecoderTestColumnHandle row23 = new DecoderTestColumnHandle(10, "row23", BigintType.BIGINT, "31", "BYTE", null, false, false, false);
    DecoderTestColumnHandle row24 = new DecoderTestColumnHandle(11, "row24", BooleanType.BOOLEAN, "32", "SHORT", null, false, false, false);

    DecoderTestColumnHandle row31 = new DecoderTestColumnHandle(12, "row31", BigintType.BIGINT, "34", "BYTE", null, false, false, false);
    DecoderTestColumnHandle row32 = new DecoderTestColumnHandle(13, "row32", BooleanType.BOOLEAN, "35", "BYTE", null, false, false, false);
    DecoderTestColumnHandle row33 = new DecoderTestColumnHandle(14, "row33", BigintType.BIGINT, "36", "BYTE", null, false, false, false);
    DecoderTestColumnHandle row34 = new DecoderTestColumnHandle(15, "row34", BooleanType.BOOLEAN, "37", "BYTE", null, false, false, false);

    Set<DecoderColumnHandle> columns = ImmutableSet.of(row01,
            row02,
            row03,
            row04,
            row11,
            row12,
            row13,
            row14,
            row21,
            row22,
            row23,
            row24,
            row31,
            row32,
            row33,
            row34);
    RowDecoder rowDecoder = DECODER_FACTORY.create(emptyMap(), columns);

    Map<DecoderColumnHandle, FieldValueProvider> decodedRow = rowDecoder.decodeRow(row, null)
            .orElseThrow(AssertionError::new);

    assertEquals(decodedRow.size(), columns.size());

    checkValue(decodedRow, row01, 127);
    checkValue(decodedRow, row02, false);
    checkValue(decodedRow, row03, 126);
    checkValue(decodedRow, row04, true);

    checkValue(decodedRow, row11, 125);
    checkValue(decodedRow, row12, false);
    checkValue(decodedRow, row13, 124);
    checkValue(decodedRow, row14, true);

    checkValue(decodedRow, row21, 123);
    checkValue(decodedRow, row22, false);
    checkValue(decodedRow, row23, 122);
    checkValue(decodedRow, row24, true);

    checkValue(decodedRow, row31, 121);
    checkValue(decodedRow, row32, false);
    checkValue(decodedRow, row33, 120);
    checkValue(decodedRow, row34, true);
}
 
Example 16
Source File: TypeHelper.java    From presto with Apache License 2.0 4 votes vote down vote up
public static Object getJavaValue(Type type, Object nativeValue)
{
    if (type instanceof VarcharType) {
        return ((Slice) nativeValue).toStringUtf8();
    }
    if (type.equals(TimestampType.TIMESTAMP)) {
        return ((Long) nativeValue) * 1000;
    }
    if (type == BigintType.BIGINT) {
        return nativeValue;
    }
    if (type == IntegerType.INTEGER) {
        return ((Long) nativeValue).intValue();
    }
    if (type == SmallintType.SMALLINT) {
        return ((Long) nativeValue).shortValue();
    }
    if (type == TinyintType.TINYINT) {
        return ((Long) nativeValue).byteValue();
    }
    if (type == DoubleType.DOUBLE) {
        return nativeValue;
    }
    if (type == RealType.REAL) {
        // conversion can result in precision lost
        return intBitsToFloat(((Long) nativeValue).intValue());
    }
    if (type == BooleanType.BOOLEAN) {
        return nativeValue;
    }
    if (type instanceof VarbinaryType) {
        return ((Slice) nativeValue).toByteBuffer();
    }
    if (type instanceof DecimalType) {
        DecimalType decimalType = (DecimalType) type;
        if (decimalType.isShort()) {
            return new BigDecimal(BigInteger.valueOf((long) nativeValue), decimalType.getScale());
        }
        return new BigDecimal(decodeUnscaledValue((Slice) nativeValue), decimalType.getScale());
    }
    throw new IllegalStateException("Back conversion not implemented for " + type);
}
 
Example 17
Source File: TypeHelper.java    From presto with Apache License 2.0 4 votes vote down vote up
public static org.apache.kudu.Type toKuduClientType(Type type)
{
    if (type instanceof VarcharType) {
        return org.apache.kudu.Type.STRING;
    }
    if (type.equals(TimestampType.TIMESTAMP)) {
        return org.apache.kudu.Type.UNIXTIME_MICROS;
    }
    if (type == BigintType.BIGINT) {
        return org.apache.kudu.Type.INT64;
    }
    if (type == IntegerType.INTEGER) {
        return org.apache.kudu.Type.INT32;
    }
    if (type == SmallintType.SMALLINT) {
        return org.apache.kudu.Type.INT16;
    }
    if (type == TinyintType.TINYINT) {
        return org.apache.kudu.Type.INT8;
    }
    if (type == RealType.REAL) {
        return org.apache.kudu.Type.FLOAT;
    }
    if (type == DoubleType.DOUBLE) {
        return org.apache.kudu.Type.DOUBLE;
    }
    if (type == BooleanType.BOOLEAN) {
        return org.apache.kudu.Type.BOOL;
    }
    if (type instanceof VarbinaryType) {
        return org.apache.kudu.Type.BINARY;
    }
    if (type instanceof DecimalType) {
        return org.apache.kudu.Type.DECIMAL;
    }
    if (type == DateType.DATE) {
        return org.apache.kudu.Type.STRING;
    }
    if (type instanceof CharType) {
        return org.apache.kudu.Type.STRING;
    }
    throw new PrestoException(NOT_SUPPORTED, "Unsupported type: " + type);
}
 
Example 18
Source File: TypeConverter.java    From presto with Apache License 2.0 4 votes vote down vote up
public static Type toPrestoType(org.apache.iceberg.types.Type type, TypeManager typeManager)
{
    switch (type.typeId()) {
        case BOOLEAN:
            return BooleanType.BOOLEAN;
        case BINARY:
        case FIXED:
            return VarbinaryType.VARBINARY;
        case DATE:
            return DateType.DATE;
        case DECIMAL:
            Types.DecimalType decimalType = (Types.DecimalType) type;
            return DecimalType.createDecimalType(decimalType.precision(), decimalType.scale());
        case DOUBLE:
            return DoubleType.DOUBLE;
        case LONG:
            return BigintType.BIGINT;
        case FLOAT:
            return RealType.REAL;
        case INTEGER:
            return IntegerType.INTEGER;
        case TIME:
            return TimeType.TIME;
        case TIMESTAMP:
            Types.TimestampType timestampType = (Types.TimestampType) type;
            if (timestampType.shouldAdjustToUTC()) {
                return TimestampWithTimeZoneType.TIMESTAMP_WITH_TIME_ZONE;
            }
            return TimestampType.TIMESTAMP;
        case UUID:
        case STRING:
            return VarcharType.createUnboundedVarcharType();
        case LIST:
            Types.ListType listType = (Types.ListType) type;
            return new ArrayType(toPrestoType(listType.elementType(), typeManager));
        case MAP:
            Types.MapType mapType = (Types.MapType) type;
            TypeSignature keyType = toPrestoType(mapType.keyType(), typeManager).getTypeSignature();
            TypeSignature valueType = toPrestoType(mapType.valueType(), typeManager).getTypeSignature();
            return typeManager.getParameterizedType(StandardTypes.MAP, ImmutableList.of(TypeSignatureParameter.typeParameter(keyType), TypeSignatureParameter.typeParameter(valueType)));
        case STRUCT:
            List<Types.NestedField> fields = ((Types.StructType) type).fields();
            return RowType.from(fields.stream()
                    .map(field -> new RowType.Field(Optional.of(field.name()), toPrestoType(field.type(), typeManager)))
                    .collect(toImmutableList()));
        default:
            throw new UnsupportedOperationException(format("Cannot convert from Iceberg type '%s' (%s) to Presto type", type, type.typeId()));
    }
}
 
Example 19
Source File: LearnStateSerializer.java    From presto with Apache License 2.0 4 votes vote down vote up
@Override
public Type getSerializedType()
{
    return BigintType.BIGINT;
}