io.prestosql.spi.type.BigintType Java Examples

The following examples show how to use io.prestosql.spi.type.BigintType. 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: TestTypeConversions.java    From presto with Apache License 2.0 6 votes vote down vote up
@Test
public void testConvertTwoLevelsRecordField()
{
    Field field = Field.of(
            "rec",
            LegacySQLTypeName.RECORD,
            Field.of("sub_rec", LegacySQLTypeName.RECORD,
                    Field.of("sub_sub_s", LegacySQLTypeName.STRING),
                    Field.of("sub_sub_i", LegacySQLTypeName.INTEGER)),
            Field.of("sub_s", LegacySQLTypeName.STRING),
            Field.of("sub_i", LegacySQLTypeName.INTEGER));
    ColumnMetadata metadata = Conversions.toColumnMetadata(field);
    RowType targetType = RowType.rowType(
            RowType.field("sub_rec", RowType.rowType(
                    RowType.field("sub_sub_s", VarcharType.VARCHAR),
                    RowType.field("sub_sub_i", BigintType.BIGINT))),
            RowType.field("sub_s", VarcharType.VARCHAR),
            RowType.field("sub_i", BigintType.BIGINT));
    assertThat(metadata.getType()).isEqualTo(targetType);
}
 
Example #2
Source File: TestCsvDecoder.java    From presto with Apache License 2.0 6 votes vote down vote up
@Test
public void testWrongMappingDefined()
{
    assertThatThrownBy(() -> singleColumnDecoder(BigintType.BIGINT, null, null, null, false, false, false))
            .isInstanceOf(PrestoException.class)
            .hasMessageMatching("mapping not defined for column 'column'");

    assertThatThrownBy(() -> singleColumnDecoder(BigintType.BIGINT, "x", null, null, false, false, false))
            .isInstanceOf(PrestoException.class)
            .hasMessageMatching("invalid mapping 'x' for column 'column'");

    assertThatThrownBy(() -> singleColumnDecoder(BigintType.BIGINT, "-1", null, null, false, false, false))
            .isInstanceOf(PrestoException.class)
            .hasMessageMatching("invalid mapping '-1' for column 'column'");

    assertThatThrownBy(() -> singleColumnDecoder(BigintType.BIGINT, "1:1", null, null, false, false, false))
            .isInstanceOf(PrestoException.class)
            .hasMessageMatching("invalid mapping '1:1' for column 'column'");
}
 
Example #3
Source File: TestRecordAccess.java    From presto with Apache License 2.0 6 votes vote down vote up
@Test
public void testStreamHasData()
{
    MaterializedResult result = queryRunner.execute("Select count(1) from " + dummyStreamName);
    MaterializedResult expected = MaterializedResult.resultBuilder(SESSION, BigintType.BIGINT)
            .row(0)
            .build();

    assertEquals(result.getRowCount(), expected.getRowCount());

    int count = 500;
    createDummyMessages(dummyStreamName, count);

    result = queryRunner.execute("SELECT count(1) from " + dummyStreamName);

    expected = MaterializedResult.resultBuilder(SESSION, BigintType.BIGINT)
            .row(count)
            .build();

    assertEquals(result.getRowCount(), expected.getRowCount());
    log.info("Completed second test (select counts)");
}
 
Example #4
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 #5
Source File: TestAvroDecoder.java    From presto with Apache License 2.0 6 votes vote down vote up
@Test
public void testSupportedDataTypeValidation()
{
    // supported types
    singleColumnDecoder(BigintType.BIGINT);
    singleColumnDecoder(VarbinaryType.VARBINARY);
    singleColumnDecoder(BooleanType.BOOLEAN);
    singleColumnDecoder(DoubleType.DOUBLE);
    singleColumnDecoder(createUnboundedVarcharType());
    singleColumnDecoder(createVarcharType(100));
    singleColumnDecoder(new ArrayType(BigintType.BIGINT));
    singleColumnDecoder(VARCHAR_MAP_TYPE);
    singleColumnDecoder(DOUBLE_MAP_TYPE);

    // some unsupported types
    assertUnsupportedColumnTypeException(() -> singleColumnDecoder(DecimalType.createDecimalType(10, 4)));
}
 
Example #6
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 #7
Source File: PrestoThriftBlock.java    From presto with Apache License 2.0 6 votes vote down vote up
public static PrestoThriftBlock fromRecordSetColumn(RecordSet recordSet, int columnIndex, int totalRecords)
{
    Type type = recordSet.getColumnTypes().get(columnIndex);
    // use more efficient implementations for numeric types which are likely to be used in index join
    if (type instanceof IntegerType) {
        return PrestoThriftInteger.fromRecordSetColumn(recordSet, columnIndex, totalRecords);
    }
    if (type instanceof BigintType) {
        return PrestoThriftBigint.fromRecordSetColumn(recordSet, columnIndex, totalRecords);
    }
    if (type instanceof DateType) {
        return PrestoThriftDate.fromRecordSetColumn(recordSet, columnIndex, totalRecords);
    }
    if (type instanceof TimestampType) {
        return PrestoThriftTimestamp.fromRecordSetColumn(recordSet, columnIndex, totalRecords);
    }
    // less efficient implementation which converts to a block first
    return fromBlock(convertColumnToBlock(recordSet, columnIndex, totalRecords), type);
}
 
Example #8
Source File: TestKafkaIntegrationSmokeTest.java    From presto with Apache License 2.0 6 votes vote down vote up
@Override
protected QueryRunner createQueryRunner()
        throws Exception
{
    testingKafka = new TestingKafka();
    topicName = "test_raw_" + UUID.randomUUID().toString().replaceAll("-", "_");

    Map<SchemaTableName, KafkaTopicDescription> extraTopicDescriptions = ImmutableMap.<SchemaTableName, KafkaTopicDescription>builder()
            .put(new SchemaTableName("default", topicName),
                    createDescription(topicName, "default", topicName,
                            createFieldGroup("raw", ImmutableList.of(
                                    createOneFieldDescription("id", BigintType.BIGINT, "0", "LONG")))))
            .build();

    QueryRunner queryRunner = KafkaQueryRunner.builder(testingKafka)
            .setTables(TpchTable.getTables())
            .setExtraTopicDescription(ImmutableMap.<SchemaTableName, KafkaTopicDescription>builder()
                    .putAll(extraTopicDescriptions)
                    .build())
            .build();

    testingKafka.createTopics(topicName);
    return queryRunner;
}
 
Example #9
Source File: SessionPropertyManager.java    From presto with Apache License 2.0 6 votes vote down vote up
public static String serializeSessionProperty(Type type, Object value)
{
    if (value == null) {
        throw new PrestoException(INVALID_SESSION_PROPERTY, "Session property cannot be null");
    }
    if (BooleanType.BOOLEAN.equals(type)) {
        return value.toString();
    }
    if (BigintType.BIGINT.equals(type)) {
        return value.toString();
    }
    if (IntegerType.INTEGER.equals(type)) {
        return value.toString();
    }
    if (DoubleType.DOUBLE.equals(type)) {
        return value.toString();
    }
    if (VarcharType.VARCHAR.equals(type)) {
        return value.toString();
    }
    if (type instanceof ArrayType || type instanceof MapType) {
        return getJsonCodecForType(type).toJson(value);
    }
    throw new PrestoException(INVALID_SESSION_PROPERTY, format("Session property type %s is not supported", type));
}
 
Example #10
Source File: SessionPropertyManager.java    From presto with Apache License 2.0 6 votes vote down vote up
private static Object deserializeSessionProperty(Type type, String value)
{
    if (value == null) {
        throw new PrestoException(INVALID_SESSION_PROPERTY, "Session property cannot be null");
    }
    if (VarcharType.VARCHAR.equals(type)) {
        return value;
    }
    if (BooleanType.BOOLEAN.equals(type)) {
        return Boolean.valueOf(value);
    }
    if (BigintType.BIGINT.equals(type)) {
        return Long.valueOf(value);
    }
    if (IntegerType.INTEGER.equals(type)) {
        return Integer.valueOf(value);
    }
    if (DoubleType.DOUBLE.equals(type)) {
        return Double.valueOf(value);
    }
    if (type instanceof ArrayType || type instanceof MapType) {
        return getJsonCodecForType(type).fromJson(value);
    }
    throw new PrestoException(INVALID_SESSION_PROPERTY, format("Session property type %s is not supported", type));
}
 
Example #11
Source File: SessionPropertyManager.java    From presto with Apache License 2.0 6 votes vote down vote up
private static Class<?> getMapKeyType(Type type)
{
    if (VarcharType.VARCHAR.equals(type)) {
        return String.class;
    }
    if (BooleanType.BOOLEAN.equals(type)) {
        return Boolean.class;
    }
    if (BigintType.BIGINT.equals(type)) {
        return Long.class;
    }
    if (IntegerType.INTEGER.equals(type)) {
        return Integer.class;
    }
    if (DoubleType.DOUBLE.equals(type)) {
        return Double.class;
    }
    throw new PrestoException(INVALID_SESSION_PROPERTY, format("Session property map key type %s is not supported", type));
}
 
Example #12
Source File: ShowStatsRewrite.java    From presto with Apache License 2.0 6 votes vote down vote up
private static Expression toStringLiteral(Type type, double value)
{
    if (type.equals(BigintType.BIGINT) || type.equals(IntegerType.INTEGER) || type.equals(SmallintType.SMALLINT) || type.equals(TinyintType.TINYINT)) {
        return new StringLiteral(Long.toString(round(value)));
    }
    if (type.equals(DOUBLE) || type instanceof DecimalType) {
        return new StringLiteral(Double.toString(value));
    }
    if (type.equals(RealType.REAL)) {
        return new StringLiteral(Float.toString((float) value));
    }
    if (type.equals(DATE)) {
        return new StringLiteral(LocalDate.ofEpochDay(round(value)).toString());
    }
    throw new IllegalArgumentException("Unexpected type: " + type);
}
 
Example #13
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 #14
Source File: JsonUtil.java    From presto with Apache License 2.0 6 votes vote down vote up
public static boolean canCastFromJson(Type type)
{
    if (type instanceof BooleanType ||
            type instanceof TinyintType ||
            type instanceof SmallintType ||
            type instanceof IntegerType ||
            type instanceof BigintType ||
            type instanceof RealType ||
            type instanceof DoubleType ||
            type instanceof DecimalType ||
            type instanceof VarcharType ||
            type instanceof JsonType) {
        return true;
    }
    if (type instanceof ArrayType) {
        return canCastFromJson(((ArrayType) type).getElementType());
    }
    if (type instanceof MapType) {
        return isValidJsonObjectKeyType(((MapType) type).getKeyType()) && canCastFromJson(((MapType) type).getValueType());
    }
    if (type instanceof RowType) {
        return type.getTypeParameters().stream().allMatch(JsonUtil::canCastFromJson);
    }
    return false;
}
 
Example #15
Source File: TestCsvDecoder.java    From presto with Apache License 2.0 6 votes vote down vote up
@Test
public void testSupportedDataTypeValidation()
{
    // supported types
    singleColumnDecoder(BigintType.BIGINT);
    singleColumnDecoder(IntegerType.INTEGER);
    singleColumnDecoder(SmallintType.SMALLINT);
    singleColumnDecoder(TinyintType.TINYINT);
    singleColumnDecoder(BooleanType.BOOLEAN);
    singleColumnDecoder(DoubleType.DOUBLE);
    singleColumnDecoder(createUnboundedVarcharType());
    singleColumnDecoder(createVarcharType(100));

    // some unsupported types
    assertUnsupportedColumnTypeException(() -> singleColumnDecoder(RealType.REAL));
    assertUnsupportedColumnTypeException(() -> singleColumnDecoder(DecimalType.createDecimalType(10, 4)));
    assertUnsupportedColumnTypeException(() -> singleColumnDecoder(VarbinaryType.VARBINARY));
}
 
Example #16
Source File: MLFeaturesFunctions.java    From presto with Apache License 2.0 6 votes vote down vote up
private static Block featuresHelper(PageBuilder pageBuilder, double... features)
{
    if (pageBuilder.isFull()) {
        pageBuilder.reset();
    }

    BlockBuilder mapBlockBuilder = pageBuilder.getBlockBuilder(0);
    BlockBuilder blockBuilder = mapBlockBuilder.beginBlockEntry();

    for (int i = 0; i < features.length; i++) {
        BigintType.BIGINT.writeLong(blockBuilder, i);
        DoubleType.DOUBLE.writeDouble(blockBuilder, features[i]);
    }

    mapBlockBuilder.closeEntry();
    pageBuilder.declarePosition();
    return mapBlockBuilder.getObject(mapBlockBuilder.getPositionCount() - 1, Block.class);
}
 
Example #17
Source File: TestPruneCountAggregationOverScalar.java    From presto with Apache License 2.0 6 votes vote down vote up
@Test
public void testDoesNotFireOnNestedCountAggregateWithNonEmptyGroupBy()
{
    tester().assertThat(new PruneCountAggregationOverScalar(tester().getMetadata()))
            .on(p ->
                    p.aggregation((a) -> a
                            .addAggregation(
                                    p.symbol("count_1", BigintType.BIGINT),
                                    new FunctionCallBuilder(tester().getMetadata())
                                            .setName(QualifiedName.of("count"))
                                            .build(),
                                    ImmutableList.of())
                            .step(AggregationNode.Step.SINGLE)
                            .globalGrouping()
                            .source(
                                    p.aggregation(aggregationBuilder -> {
                                        aggregationBuilder
                                                .source(p.tableScan(ImmutableList.of(), ImmutableMap.of()))
                                                .groupingSets(singleGroupingSet(ImmutableList.of(p.symbol("orderkey"))));
                                    }))))
            .doesNotFire();
}
 
Example #18
Source File: TestPruneCountAggregationOverScalar.java    From presto with Apache License 2.0 6 votes vote down vote up
@Test
public void testFiresOnCountAggregateOverEnforceSingleRow()
{
    tester().assertThat(new PruneCountAggregationOverScalar(tester().getMetadata()))
            .on(p ->
                    p.aggregation((a) -> a
                            .addAggregation(
                                    p.symbol("count_1", BigintType.BIGINT),
                                    new FunctionCallBuilder(tester().getMetadata())
                                            .setName(QualifiedName.of("count"))
                                            .build(),
                                    ImmutableList.of())
                            .step(AggregationNode.Step.SINGLE)
                            .globalGrouping()
                            .source(p.enforceSingleRow(p.tableScan(ImmutableList.of(), ImmutableMap.of())))))
            .matches(values(ImmutableMap.of("count_1", 0)));
}
 
Example #19
Source File: TestPruneCountAggregationOverScalar.java    From presto with Apache License 2.0 6 votes vote down vote up
@Test
public void testFiresOnNestedCountAggregate()
{
    tester().assertThat(new PruneCountAggregationOverScalar(tester().getMetadata()))
            .on(p ->
                    p.aggregation((a) -> a
                            .addAggregation(
                                    p.symbol("count_1", BigintType.BIGINT),
                                    new FunctionCallBuilder(tester().getMetadata())
                                            .setName(QualifiedName.of("count"))
                                            .build(),
                                    ImmutableList.of())
                            .globalGrouping()
                            .step(AggregationNode.Step.SINGLE)
                            .source(
                                    p.aggregation((aggregationBuilder) -> aggregationBuilder
                                            .source(p.tableScan(ImmutableList.of(), ImmutableMap.of()))
                                            .globalGrouping()
                                            .step(AggregationNode.Step.SINGLE)))))
            .matches(values(ImmutableMap.of("count_1", 0)));
}
 
Example #20
Source File: TestPruneCountAggregationOverScalar.java    From presto with Apache License 2.0 6 votes vote down vote up
@Test
public void testDoesNotFireOnNonNestedAggregate()
{
    tester().assertThat(new PruneCountAggregationOverScalar(tester().getMetadata()))
            .on(p ->
                    p.aggregation((a) -> a
                            .globalGrouping()
                            .addAggregation(
                                    p.symbol("count_1", BigintType.BIGINT),
                                    new FunctionCallBuilder(tester().getMetadata())
                                            .setName(QualifiedName.of("count"))
                                            .build(),
                                    ImmutableList.of())
                            .source(
                                    p.tableScan(ImmutableList.of(), ImmutableMap.of())))
            ).doesNotFire();
}
 
Example #21
Source File: TestLambdaCaptureDesugaringRewriter.java    From presto with Apache License 2.0 6 votes vote down vote up
@Test
public void testRewriteBasicLambda()
{
    final Map<Symbol, Type> symbols = ImmutableMap.of(new Symbol("a"), BigintType.BIGINT);
    final SymbolAllocator allocator = new SymbolAllocator(symbols);

    assertEquals(rewrite(expression("x -> a + x"), allocator.getTypes(), allocator),
            new BindExpression(
                    ImmutableList.of(expression("a")),
                    new LambdaExpression(
                            Stream.of("a_0", "x")
                                    .map(Identifier::new)
                                    .map(LambdaArgumentDeclaration::new)
                                    .collect(toList()),
                            expression("a_0 + x"))));
}
 
Example #22
Source File: TestQueryResultRows.java    From presto with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldReturnUpdateCount()
{
    Column column = BIGINT_COLUMN.apply("_col0");
    long value = 10123;

    QueryResultRows rows = queryResultRowsBuilder(getSession())
            .withColumnsAndTypes(ImmutableList.of(column), ImmutableList.of(BigintType.BIGINT))
            .addPages(rowPagesBuilder(BigintType.BIGINT).row(value).build())
            .build();

    assertThat((Iterable<? extends List<Object>>) rows).as("rows").isNotEmpty();
    assertThat(rows.getUpdateCount()).isPresent();
    assertThat(rows.getUpdateCount().get()).isEqualTo(value);

    assertThat(getAllValues(rows)).containsExactly(ImmutableList.of(value));
    assertThat(rows.getColumns().orElseThrow()).containsOnly(column);
    assertThat(rows.iterator()).isExhausted();
}
 
Example #23
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 #24
Source File: TestRemoveEmptyDelete.java    From presto with Apache License 2.0 5 votes vote down vote up
@Test
public void test()
{
    tester().assertThat(new RemoveEmptyDelete())
            .on(p -> p.tableDelete(
                    new SchemaTableName("sch", "tab"),
                    p.values(),
                    p.symbol("a", BigintType.BIGINT)))
            .matches(
                    PlanMatchPattern.values(ImmutableMap.of("a", 0)));
}
 
Example #25
Source File: TestAvroDecoder.java    From presto with Apache License 2.0 5 votes vote down vote up
@Test
public void testInvalidExtraneousParameters()
{
    assertThatThrownBy(() -> singleColumnDecoder(BigintType.BIGINT, "mapping", null, "hint", false, false, false))
            .isInstanceOf(PrestoException.class)
            .hasMessageMatching("unexpected format hint 'hint' defined for column 'some_column'");

    assertThatThrownBy(() -> singleColumnDecoder(BigintType.BIGINT, "mapping", null, null, false, false, true))
            .isInstanceOf(PrestoException.class)
            .hasMessageMatching("unexpected internal column 'some_column'");
}
 
Example #26
Source File: TestCsvDecoder.java    From presto with Apache License 2.0 5 votes vote down vote up
@Test
public void testInvalidExtraneousParameters()
{
    assertThatThrownBy(() -> singleColumnDecoder(BigintType.BIGINT, "0", "format", null, false, false, false))
            .isInstanceOf(PrestoException.class)
            .hasMessageMatching("unexpected data format 'format' defined for column 'column'");

    assertThatThrownBy(() -> singleColumnDecoder(BigintType.BIGINT, "0", null, "hint", false, false, false))
            .isInstanceOf(PrestoException.class)
            .hasMessageMatching("unexpected format hint 'hint' defined for column 'column'");

    assertThatThrownBy(() -> singleColumnDecoder(BigintType.BIGINT, "0", null, null, false, false, true))
            .isInstanceOf(PrestoException.class)
            .hasMessageMatching("unexpected internal column 'column'");
}
 
Example #27
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 #28
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 #29
Source File: TestRowFilter.java    From presto with Apache License 2.0 5 votes vote down vote up
@BeforeClass
public void init()
{
    LocalQueryRunner runner = LocalQueryRunner.builder(SESSION).build();

    runner.createCatalog(CATALOG, new TpchConnectorFactory(1), ImmutableMap.of());

    ConnectorViewDefinition view = new ConnectorViewDefinition(
            "SELECT nationkey, name FROM local.tiny.nation",
            Optional.empty(),
            Optional.empty(),
            ImmutableList.of(new ConnectorViewDefinition.ViewColumn("nationkey", BigintType.BIGINT.getTypeId()), new ConnectorViewDefinition.ViewColumn("name", VarcharType.createVarcharType(25).getTypeId())),
            Optional.empty(),
            Optional.of(VIEW_OWNER),
            false);

    MockConnectorFactory mock = MockConnectorFactory.builder()
            .withGetViews((s, prefix) -> ImmutableMap.<SchemaTableName, ConnectorViewDefinition>builder()
                    .put(new SchemaTableName("default", "nation_view"), view)
                    .build())
            .build();

    runner.createCatalog(MOCK_CATALOG, mock, ImmutableMap.of());

    assertions = new QueryAssertions(runner);
    accessControl = assertions.getQueryRunner().getAccessControl();
}
 
Example #30
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;
    }
}