Java Code Examples for io.prestosql.spi.type.VarcharType#VARCHAR

The following examples show how to use io.prestosql.spi.type.VarcharType#VARCHAR . 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: 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 2
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 3
Source File: HBaseMetadata.java    From presto-hbase-connector with Apache License 2.0 6 votes vote down vote up
@Override
public ColumnHandle getUpdateRowIdColumnHandle(ConnectorSession session, ConnectorTableHandle tableHandle) {
    HBaseTableHandle hth = (HBaseTableHandle) tableHandle;
    String schemaName = hth.getSchemaTableName().getSchemaName();
    String tableName = hth.getSchemaTableName().getTableName();

    TableMetaInfo tableMetaInfo = Utils.getTableMetaInfoFromJson(schemaName, tableName,
            this.hbaseClientManager.getConfig().getMetaDir());
    requireNonNull(tableMetaInfo, String.format("Table %s.%s has no metadata, please check .json file under %s",
            schemaName, tableName, hbaseClientManager.getConfig().getMetaDir() + "/" + schemaName));

    Optional<ColumnMetaInfo> rowKeyOpt = tableMetaInfo.getColumns().stream().filter(ColumnMetaInfo::isRowKey).findFirst();
    checkArgument(rowKeyOpt.isPresent(),
            String.format("Table %s.%s has no rowKey! Please check .json file under %s",
                    schemaName, tableName, hbaseClientManager.getConfig().getMetaDir() + "/" + schemaName));

    ColumnMetaInfo rowKeyInfo = rowKeyOpt.get();
    // HBaseColumnHandle's attributes cannot be all the same with the REAL rowKey column,
    // Or there will be a java.lang.IllegalArgumentException: Multiple entries with same value Exception.
    return new HBaseColumnHandle(CONNECTOR_NAME, "",
            rowKeyInfo.getColumnName(), VarcharType.VARCHAR,
            tableMetaInfo.getColumns().indexOf(rowKeyOpt.get()),
            rowKeyInfo.isRowKey());
}
 
Example 4
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 5
Source File: PulsarRecordCursor.java    From pulsar with Apache License 2.0 5 votes vote down vote up
@Override
public Slice getSlice(int field) {
    checkFieldType(field, Slice.class);

    Object record = getRecord(field);
    Type type = getType(field);
    if (type == VarcharType.VARCHAR) {
        return Slices.utf8Slice(record.toString());
    } else if (type == VarbinaryType.VARBINARY) {
        return Slices.wrappedBuffer(toBytes(record));
    } else {
        throw new PrestoException(NOT_SUPPORTED, "Unsupported type " + type);
    }
}
 
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: 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 8
Source File: AccumuloTableProperties.java    From presto with Apache License 2.0 4 votes vote down vote up
public AccumuloTableProperties()
{
    PropertyMetadata<String> s1 = stringProperty(
            COLUMN_MAPPING,
            "Comma-delimited list of column metadata: col_name:col_family:col_qualifier,[...]. Required for external tables. Not setting this property results in auto-generated column names.",
            null,
            false);

    PropertyMetadata<String> s2 = stringProperty(
            INDEX_COLUMNS,
            "A comma-delimited list of Presto columns that are indexed in this table's corresponding index table. Default is no indexed columns.",
            "",
            false);

    PropertyMetadata<Boolean> s3 = booleanProperty(
            EXTERNAL,
            "If true, Presto will only do metadata operations for the table. Else, Presto will create and drop Accumulo tables where appropriate. Default false.",
            false,
            false);

    PropertyMetadata<String> s4 = stringProperty(
            LOCALITY_GROUPS,
            "List of locality groups to set on the Accumulo table. Only valid on internal tables. String format is locality group name, colon, comma delimited list of Presto column names in the group. Groups are delimited by pipes. Example: group1:colA,colB,colC|group2:colD,colE,colF|etc.... Default is no locality groups.",
            null,
            false);

    PropertyMetadata<String> s5 = stringProperty(
            ROW_ID,
            "Presto column name that maps to the Accumulo row ID. Default is the first column.",
            null,
            false);

    PropertyMetadata<String> s6 = new PropertyMetadata<>(
            SERIALIZER,
            "Serializer for Accumulo data encodings. Can either be 'default', 'string', 'lexicoder', or a Java class name. Default is 'default', i.e. the value from AccumuloRowSerializer.getDefault(), i.e. 'lexicoder'.",
            VarcharType.VARCHAR, String.class,
            AccumuloRowSerializer.getDefault().getClass().getName(),
            false,
            x -> x.equals("default")
                    ? AccumuloRowSerializer.getDefault().getClass().getName()
                    : (x.equals("string") ? StringRowSerializer.class.getName()
                    : (x.equals("lexicoder")
                    ? LexicoderRowSerializer.class.getName()
                    : (String) x)),
            object -> object);

    PropertyMetadata<String> s7 = stringProperty(
            SCAN_AUTHS,
            "Scan-time authorizations set on the batch scanner. Default is all scan authorizations for the user",
            null,
            false);

    tableProperties = ImmutableList.of(s1, s2, s3, s4, s5, s6, s7);
}
 
Example 9
Source File: TestFileBasedSystemAccessControl.java    From presto with Apache License 2.0 4 votes vote down vote up
private static ColumnMetadata column(String columnName)
{
    return new ColumnMetadata(columnName, VarcharType.VARCHAR);
}
 
Example 10
Source File: TestFileBasedAccessControl.java    From presto with Apache License 2.0 4 votes vote down vote up
private static ColumnMetadata column(String columnName)
{
    return new ColumnMetadata(columnName, VarcharType.VARCHAR);
}
 
Example 11
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);
    }
}