Java Code Examples for io.prestosql.spi.type.BooleanType

The following examples show how to use io.prestosql.spi.type.BooleanType. These examples are extracted from open source projects. 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 Project: presto   Source File: SessionPropertyManager.java    License: 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 2
Source Project: presto   Source File: SessionPropertyManager.java    License: 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 3
Source Project: presto   Source File: SessionPropertyManager.java    License: 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 4
Source Project: presto   Source File: ScalarAggregationToJoinRewriter.java    License: Apache License 2.0 6 votes vote down vote up
public PlanNode rewriteScalarAggregation(CorrelatedJoinNode correlatedJoinNode, AggregationNode aggregation)
{
    List<Symbol> correlation = correlatedJoinNode.getCorrelation();
    Optional<DecorrelatedNode> source = planNodeDecorrelator.decorrelateFilters(aggregation.getSource(), correlation);
    if (source.isEmpty()) {
        return correlatedJoinNode;
    }

    Symbol nonNull = symbolAllocator.newSymbol("non_null", BooleanType.BOOLEAN);
    Assignments scalarAggregationSourceAssignments = Assignments.builder()
            .putIdentities(source.get().getNode().getOutputSymbols())
            .put(nonNull, TRUE_LITERAL)
            .build();
    ProjectNode scalarAggregationSourceWithNonNullableSymbol = new ProjectNode(
            idAllocator.getNextId(),
            source.get().getNode(),
            scalarAggregationSourceAssignments);

    return rewriteScalarAggregation(
            correlatedJoinNode,
            aggregation,
            scalarAggregationSourceWithNonNullableSymbol,
            source.get().getCorrelatedPredicates(),
            nonNull);
}
 
Example 5
Source Project: presto   Source File: JsonUtil.java    License: 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 6
Source Project: presto   Source File: PinotColumn.java    License: 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 7
Source Project: presto   Source File: TestAvroDecoder.java    License: 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 8
Source Project: presto   Source File: TestRawDecoder.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testSupportedDataTypeValidation()
{
    // supported types
    singleColumnDecoder(BigintType.BIGINT, "0", "LONG");
    singleColumnDecoder(IntegerType.INTEGER, "0", "INT");
    singleColumnDecoder(SmallintType.SMALLINT, "0", "SHORT");
    singleColumnDecoder(TinyintType.TINYINT, "0", "BYTE");
    singleColumnDecoder(BooleanType.BOOLEAN, "0", "LONG");
    singleColumnDecoder(DoubleType.DOUBLE, "0", "DOUBLE");
    singleColumnDecoder(createUnboundedVarcharType(), "0", "BYTE");
    singleColumnDecoder(createVarcharType(100), "0", "BYTE");

    // some unsupported types
    assertUnsupportedColumnTypeException(() -> singleColumnDecoder(RealType.REAL, "0", "BYTE"));
    assertUnsupportedColumnTypeException(() -> singleColumnDecoder(DecimalType.createDecimalType(10, 4), "0", "BYTE"));
    assertUnsupportedColumnTypeException(() -> singleColumnDecoder(VarbinaryType.VARBINARY, "0", "BYTE"));
}
 
Example 9
Source Project: presto   Source File: TestRawDecoder.java    License: 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 10
Source Project: presto   Source File: TestCsvDecoder.java    License: 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 11
Source Project: presto   Source File: TestCsvDecoder.java    License: 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 12
Source Project: presto   Source File: BlackHolePageSourceProvider.java    License: Apache License 2.0 5 votes vote down vote up
private static boolean isSupportedType(Type type)
{
    return isNumericType(type) ||
            type instanceof BooleanType ||
            type instanceof DateType ||
            type instanceof TimestampType ||
            type instanceof VarcharType ||
            type instanceof VarbinaryType;
}
 
Example 13
Source Project: presto   Source File: BooleanColumnReader.java    License: Apache License 2.0 5 votes vote down vote up
public BooleanColumnReader(Type type, OrcColumn column, LocalMemoryContext systemMemoryContext)
        throws OrcCorruptionException
{
    requireNonNull(type, "type is null");
    verifyStreamType(column, type, BooleanType.class::isInstance);

    this.column = requireNonNull(column, "column is null");
    this.systemMemoryContext = requireNonNull(systemMemoryContext, "systemMemoryContext is null");
}
 
Example 14
Source Project: presto   Source File: StatsNormalizer.java    License: Apache License 2.0 5 votes vote down vote up
private static boolean isDiscrete(Type type)
{
    return type.equals(IntegerType.INTEGER) ||
            type.equals(BigintType.BIGINT) ||
            type.equals(SmallintType.SMALLINT) ||
            type.equals(TinyintType.TINYINT) ||
            type.equals(BooleanType.BOOLEAN) ||
            type.equals(DateType.DATE) ||
            type instanceof DecimalType;
}
 
Example 15
Source Project: presto   Source File: StatsUtil.java    License: Apache License 2.0 5 votes vote down vote up
private static boolean convertibleToDoubleWithCast(Type type)
{
    return type instanceof DecimalType
            || type instanceof DoubleType
            || type instanceof RealType
            || type instanceof BigintType
            || type instanceof IntegerType
            || type instanceof SmallintType
            || type instanceof TinyintType
            || type instanceof BooleanType;
}
 
Example 16
Source Project: presto   Source File: SessionPropertyManager.java    License: Apache License 2.0 5 votes vote down vote up
private static <T> JsonCodec<T> getJsonCodecForType(Type type)
{
    if (VarcharType.VARCHAR.equals(type)) {
        return (JsonCodec<T>) JSON_CODEC_FACTORY.jsonCodec(String.class);
    }
    if (BooleanType.BOOLEAN.equals(type)) {
        return (JsonCodec<T>) JSON_CODEC_FACTORY.jsonCodec(Boolean.class);
    }
    if (BigintType.BIGINT.equals(type)) {
        return (JsonCodec<T>) JSON_CODEC_FACTORY.jsonCodec(Long.class);
    }
    if (IntegerType.INTEGER.equals(type)) {
        return (JsonCodec<T>) JSON_CODEC_FACTORY.jsonCodec(Integer.class);
    }
    if (DoubleType.DOUBLE.equals(type)) {
        return (JsonCodec<T>) JSON_CODEC_FACTORY.jsonCodec(Double.class);
    }
    if (type instanceof ArrayType) {
        Type elementType = ((ArrayType) type).getElementType();
        return (JsonCodec<T>) JSON_CODEC_FACTORY.listJsonCodec(getJsonCodecForType(elementType));
    }
    if (type instanceof MapType) {
        Type keyType = ((MapType) type).getKeyType();
        Type valueType = ((MapType) type).getValueType();
        return (JsonCodec<T>) JSON_CODEC_FACTORY.mapJsonCodec(getMapKeyType(keyType), getJsonCodecForType(valueType));
    }
    throw new PrestoException(INVALID_SESSION_PROPERTY, format("Session property type %s is not supported", type));
}
 
Example 17
Source Project: presto   Source File: Query.java    License: Apache License 2.0 5 votes vote down vote up
private synchronized QueryResultRows removePagesFromExchange(QueryInfo queryInfo, long targetResultBytes)
{
    // For queries with no output, return a fake boolean result for clients that require it.
    if ((queryInfo.getState() == QueryState.FINISHED) && queryInfo.getOutputStage().isEmpty()) {
        return queryResultRowsBuilder(session)
                .withSingleBooleanValue(createColumn("result", BooleanType.BOOLEAN), true)
                .build();
    }

    // Remove as many pages as possible from the exchange until just greater than DESIRED_RESULT_BYTES
    // NOTE: it is critical that query results are created for the pages removed from the exchange
    // client while holding the lock because the query may transition to the finished state when the
    // last page is removed.  If another thread observes this state before the response is cached
    // the pages will be lost.
    QueryResultRows.Builder resultBuilder = queryResultRowsBuilder(session)
            // Intercept serialization exceptions and fail query if it's still possible.
            // Put serialization exception aside to return failed query result.
            .withExceptionConsumer(this::handleSerializationException)
            .withColumnsAndTypes(columns, types);

    try {
        long bytes = 0;
        while (bytes < targetResultBytes) {
            SerializedPage serializedPage = exchangeClient.pollPage();
            if (serializedPage == null) {
                break;
            }

            Page page = serde.deserialize(serializedPage);
            bytes += page.getLogicalSizeInBytes();
            resultBuilder.addPage(page);
        }
    }
    catch (Throwable cause) {
        queryManager.failQuery(queryId, cause);
    }

    return resultBuilder.build();
}
 
Example 18
Source Project: presto   Source File: JsonUtil.java    License: Apache License 2.0 5 votes vote down vote up
public static boolean canCastToJson(Type type)
{
    if (type instanceof UnknownType ||
            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 ||
            type instanceof TimestampType ||
            type instanceof DateType) {
        return true;
    }
    if (type instanceof ArrayType) {
        return canCastToJson(((ArrayType) type).getElementType());
    }
    if (type instanceof MapType) {
        MapType mapType = (MapType) type;
        return (mapType.getKeyType() instanceof UnknownType ||
                isValidJsonObjectKeyType(mapType.getKeyType())) &&
                canCastToJson(mapType.getValueType());
    }
    if (type instanceof RowType) {
        return type.getTypeParameters().stream().allMatch(JsonUtil::canCastToJson);
    }
    return false;
}
 
Example 19
Source Project: presto   Source File: JsonUtil.java    License: Apache License 2.0 5 votes vote down vote up
private static boolean isValidJsonObjectKeyType(Type type)
{
    return 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;
}
 
Example 20
Source Project: presto   Source File: JsonUtil.java    License: Apache License 2.0 5 votes vote down vote up
static ObjectKeyProvider createObjectKeyProvider(Type type)
{
    if (type instanceof UnknownType) {
        return (block, position) -> null;
    }
    if (type instanceof BooleanType) {
        return (block, position) -> type.getBoolean(block, position) ? "true" : "false";
    }
    if (type instanceof TinyintType || type instanceof SmallintType || type instanceof IntegerType || type instanceof BigintType) {
        return (block, position) -> String.valueOf(type.getLong(block, position));
    }
    if (type instanceof RealType) {
        return (block, position) -> String.valueOf(intBitsToFloat(toIntExact(type.getLong(block, position))));
    }
    if (type instanceof DoubleType) {
        return (block, position) -> String.valueOf(type.getDouble(block, position));
    }
    if (type instanceof DecimalType) {
        DecimalType decimalType = (DecimalType) type;
        if (isShortDecimal(decimalType)) {
            return (block, position) -> Decimals.toString(decimalType.getLong(block, position), decimalType.getScale());
        }
        return (block, position) -> Decimals.toString(
                decodeUnscaledValue(type.getSlice(block, position)),
                decimalType.getScale());
    }
    if (type instanceof VarcharType) {
        return (block, position) -> type.getSlice(block, position).toStringUtf8();
    }

    throw new PrestoException(INVALID_FUNCTION_ARGUMENT, format("Unsupported type: %s", type));
}
 
Example 21
Source Project: presto   Source File: TestArrayMatchFunctions.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testAllMatch()
{
    assertFunction("all_match(ARRAY [5, 7, 9], x -> x % 2 = 1)", BooleanType.BOOLEAN, true);
    assertFunction("all_match(ARRAY [true, false, true], x -> x)", BooleanType.BOOLEAN, false);
    assertFunction("all_match(ARRAY ['abc', 'ade', 'afg'], x -> substr(x, 1, 1) = 'a')", BooleanType.BOOLEAN, true);
    assertFunction("all_match(ARRAY [], x -> true)", BooleanType.BOOLEAN, true);
    assertFunction("all_match(ARRAY [true, true, NULL], x -> x)", BooleanType.BOOLEAN, null);
    assertFunction("all_match(ARRAY [true, false, NULL], x -> x)", BooleanType.BOOLEAN, false);
    assertFunction("all_match(ARRAY [NULL, NULL, NULL], x -> x > 1)", BooleanType.BOOLEAN, null);
    assertFunction("all_match(ARRAY [NULL, NULL, NULL], x -> x IS NULL)", BooleanType.BOOLEAN, true);
    assertFunction("all_match(ARRAY [MAP(ARRAY[1,2], ARRAY[3,4]), MAP(ARRAY[1,2,3], ARRAY[3,4,5])], x -> cardinality(x) > 1)", BooleanType.BOOLEAN, true);
}
 
Example 22
Source Project: presto   Source File: TestArrayMatchFunctions.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testAnyMatch()
{
    assertFunction("any_match(ARRAY [5, 8, 10], x -> x % 2 = 1)", BooleanType.BOOLEAN, true);
    assertFunction("any_match(ARRAY [false, false, false], x -> x)", BooleanType.BOOLEAN, false);
    assertFunction("any_match(ARRAY ['abc', 'def', 'ghi'], x -> substr(x, 1, 1) = 'a')", BooleanType.BOOLEAN, true);
    assertFunction("any_match(ARRAY [], x -> true)", BooleanType.BOOLEAN, false);
    assertFunction("any_match(ARRAY [false, false, NULL], x -> x)", BooleanType.BOOLEAN, null);
    assertFunction("any_match(ARRAY [true, false, NULL], x -> x)", BooleanType.BOOLEAN, true);
    assertFunction("any_match(ARRAY [NULL, NULL, NULL], x -> x > 1)", BooleanType.BOOLEAN, null);
    assertFunction("any_match(ARRAY [true, false, NULL], x -> x IS NULL)", BooleanType.BOOLEAN, true);
    assertFunction("any_match(ARRAY [MAP(ARRAY[1,2], ARRAY[3,4]), MAP(ARRAY[1,2,3], ARRAY[3,4,5])], x -> cardinality(x) > 4)", BooleanType.BOOLEAN, false);
}
 
Example 23
Source Project: presto   Source File: TestArrayMatchFunctions.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testNoneMatch()
{
    assertFunction("none_match(ARRAY [5, 8, 10], x -> x % 2 = 1)", BooleanType.BOOLEAN, false);
    assertFunction("none_match(ARRAY [false, false, false], x -> x)", BooleanType.BOOLEAN, true);
    assertFunction("none_match(ARRAY ['abc', 'def', 'ghi'], x -> substr(x, 1, 1) = 'a')", BooleanType.BOOLEAN, false);
    assertFunction("none_match(ARRAY [], x -> true)", BooleanType.BOOLEAN, true);
    assertFunction("none_match(ARRAY [false, false, NULL], x -> x)", BooleanType.BOOLEAN, null);
    assertFunction("none_match(ARRAY [true, false, NULL], x -> x)", BooleanType.BOOLEAN, false);
    assertFunction("none_match(ARRAY [NULL, NULL, NULL], x -> x > 1)", BooleanType.BOOLEAN, null);
    assertFunction("none_match(ARRAY [true, false, NULL], x -> x IS NULL)", BooleanType.BOOLEAN, false);
    assertFunction("none_match(ARRAY [MAP(ARRAY[1,2], ARRAY[3,4]), MAP(ARRAY[1,2,3], ARRAY[3,4,5])], x -> cardinality(x) > 4)", BooleanType.BOOLEAN, true);
}
 
Example 24
Source Project: presto   Source File: TestQueryResultRows.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void shouldHandleNullValues()
{
    List<Column> columns = ImmutableList.of(new Column("_col0", INTEGER, new ClientTypeSignature(INTEGER)), new Column("_col1", BOOLEAN, new ClientTypeSignature(BOOLEAN)));
    List<Type> types = ImmutableList.of(IntegerType.INTEGER, BooleanType.BOOLEAN);

    List<Page> pages = rowPagesBuilder(types)
            .row(0, null)
            .pageBreak()
            .row(1, null)
            .pageBreak()
            .row(2, true)
            .build();

    TestExceptionConsumer exceptionConsumer = new TestExceptionConsumer();
    QueryResultRows rows = queryResultRowsBuilder(getSession())
            .withColumnsAndTypes(columns, types)
            .withExceptionConsumer(exceptionConsumer)
            .addPages(pages)
            .build();

    assertFalse(rows.isEmpty(), "rows are empty");
    assertThat(rows.getTotalRowsCount()).isEqualTo(3);

    assertThat(getAllValues(rows))
            .hasSize(3)
            .containsExactly(newArrayList(0, null), newArrayList(1, null), newArrayList(2, true));
}
 
Example 25
Source Project: presto   Source File: TestQueryResultRows.java    License: Apache License 2.0 5 votes vote down vote up
@Test(expectedExceptions = IllegalArgumentException.class, expectedExceptionsMessageRegExp = "columns and types size mismatch")
public void shouldThrowWhenColumnsAndTypesSizeMismatch()
{
    List<Column> columns = ImmutableList.of(INT_COLUMN.apply("_col0"));
    List<Type> types = ImmutableList.of(IntegerType.INTEGER, BooleanType.BOOLEAN);

    List<Page> pages = rowPagesBuilder(types)
            .row(0, null)
            .build();

    queryResultRowsBuilder(getSession())
            .addPages(pages)
            .withColumnsAndTypes(columns, types)
            .build();
}
 
Example 26
Source Project: presto   Source File: TestQueryResultRows.java    License: Apache License 2.0 5 votes vote down vote up
@Test(expectedExceptions = IllegalArgumentException.class, expectedExceptionsMessageRegExp = "columns and types must be present at the same time")
public void shouldThrowWhenColumnsAreNull()
{
    List<Type> types = ImmutableList.of(IntegerType.INTEGER, BooleanType.BOOLEAN);

    List<Page> pages = rowPagesBuilder(types)
            .row(0, null)
            .build();

    queryResultRowsBuilder(getSession())
            .addPages(pages)
            .withColumnsAndTypes(null, types)
            .build();
}
 
Example 27
Source Project: presto   Source File: TestQueryResultRows.java    License: Apache License 2.0 5 votes vote down vote up
@Test(expectedExceptions = IllegalArgumentException.class, expectedExceptionsMessageRegExp = "columns and types must be present at the same time")
public void shouldThrowWhenTypesAreNull()
{
    List<Column> columns = ImmutableList.of(INT_COLUMN.apply("_col0"));
    List<Type> types = ImmutableList.of(IntegerType.INTEGER, BooleanType.BOOLEAN);

    List<Page> pages = rowPagesBuilder(types)
            .row(0, null)
            .build();

    queryResultRowsBuilder(getSession())
            .addPages(pages)
            .withColumnsAndTypes(columns, null)
            .build();
}
 
Example 28
Source Project: presto   Source File: TestQueryResultRows.java    License: Apache License 2.0 5 votes vote down vote up
@Test(expectedExceptions = VerifyException.class, expectedExceptionsMessageRegExp = "data present without columns and types")
public void shouldThrowWhenDataIsPresentWithoutColumns()
{
    List<Page> pages = rowPagesBuilder(ImmutableList.of(IntegerType.INTEGER, BooleanType.BOOLEAN))
            .row(0, null)
            .build();

    queryResultRowsBuilder(getSession())
            .addPages(pages)
            .build();
}
 
Example 29
Source Project: presto   Source File: ShardStats.java    License: Apache License 2.0 5 votes vote down vote up
private static ColumnStats doComputeColumnStats(OrcReader orcReader, long columnId, Type type, TypeManager typeManager)
        throws IOException
{
    OrcColumn column = getColumn(orcReader.getRootColumn().getNestedColumns(), columnId);
    Type columnType = toOrcFileType(type, typeManager);
    OrcRecordReader reader = orcReader.createRecordReader(
            ImmutableList.of(column),
            ImmutableList.of(columnType),
            OrcPredicate.TRUE,
            UTC,
            newSimpleAggregatedMemoryContext(),
            INITIAL_BATCH_SIZE,
            exception -> new PrestoException(RAPTOR_ERROR, "Error reading column: " + columnId, exception));

    if (type.equals(BooleanType.BOOLEAN)) {
        return indexBoolean(reader, columnId);
    }
    if (type.equals(BigintType.BIGINT) ||
            type.equals(DateType.DATE) ||
            type.equals(TimestampType.TIMESTAMP)) {
        return indexLong(type, reader, columnId);
    }
    if (type.equals(DoubleType.DOUBLE)) {
        return indexDouble(reader, columnId);
    }
    if (type instanceof VarcharType) {
        return indexString(type, reader, columnId);
    }
    return null;
}
 
Example 30
Source Project: presto   Source File: ShardStats.java    License: Apache License 2.0 5 votes vote down vote up
private static ColumnStats indexBoolean(OrcRecordReader reader, long columnId)
        throws IOException
{
    boolean minSet = false;
    boolean maxSet = false;
    boolean min = false;
    boolean max = false;

    while (true) {
        Page page = reader.nextPage();
        if (page == null) {
            break;
        }
        Block block = page.getBlock(0).getLoadedBlock();

        for (int i = 0; i < page.getPositionCount(); i++) {
            if (block.isNull(i)) {
                continue;
            }
            boolean value = BooleanType.BOOLEAN.getBoolean(block, i);
            if (!minSet || Boolean.compare(value, min) < 0) {
                minSet = true;
                min = value;
            }
            if (!maxSet || Boolean.compare(value, max) > 0) {
                maxSet = true;
                max = value;
            }
        }
    }

    return new ColumnStats(columnId,
            minSet ? min : null,
            maxSet ? max : null);
}