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

The following examples show how to use io.prestosql.spi.type.BigintType. 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: TestKafkaIntegrationSmokeTest.java    License: 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 2
Source Project: presto   Source File: PrestoThriftBlock.java    License: 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 3
Source Project: presto   Source File: TpcdsMetadata.java    License: 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 4
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 5
Source Project: presto   Source File: TestCsvDecoder.java    License: 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 6
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 7
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 8
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 9
Source Project: presto   Source File: ShowStatsRewrite.java    License: 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 10
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 11
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 12
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 13
Source Project: presto   Source File: TestQueryResultRows.java    License: 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 14
@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 15
@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 16
@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 17
@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 18
@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 19
Source Project: presto   Source File: MLFeaturesFunctions.java    License: 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 20
Source Project: presto   Source File: TestTypeConversions.java    License: 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 21
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 22
Source Project: presto   Source File: TestRecordAccess.java    License: 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 23
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 24
Source Project: presto   Source File: BlackHolePageSourceProvider.java    License: Apache License 2.0 5 votes vote down vote up
public static boolean isNumericType(Type type)
{
    return type instanceof TinyintType ||
            type instanceof SmallintType ||
            type instanceof IntegerType ||
            type instanceof BigintType ||
            type instanceof RealType ||
            type instanceof DoubleType ||
            type instanceof DecimalType;
}
 
Example 25
Source Project: presto   Source File: LongColumnReader.java    License: Apache License 2.0 5 votes vote down vote up
private Block readNullBlock(boolean[] isNull, int nonNullCount)
        throws IOException
{
    if (type instanceof BigintType) {
        return longReadNullBlock(isNull, nonNullCount);
    }
    if (type instanceof IntegerType || type instanceof DateType) {
        return intReadNullBlock(isNull, nonNullCount);
    }
    if (type instanceof SmallintType) {
        return shortReadNullBlock(isNull, nonNullCount);
    }
    throw new VerifyError("Unsupported type " + type);
}
 
Example 26
Source Project: pulsar   Source File: PulsarMetadata.java    License: 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 27
Source Project: presto   Source File: AvroColumnDecoder.java    License: Apache License 2.0 5 votes vote down vote up
private static void serializePrimitive(BlockBuilder blockBuilder, Object value, Type type, String columnName)
{
    requireNonNull(blockBuilder, "parent blockBuilder is null");

    if (value == null) {
        blockBuilder.appendNull();
        return;
    }

    if (type instanceof BooleanType) {
        type.writeBoolean(blockBuilder, (Boolean) value);
        return;
    }

    if ((value instanceof Integer || value instanceof Long) && (type instanceof BigintType || type instanceof IntegerType || type instanceof SmallintType || type instanceof TinyintType)) {
        type.writeLong(blockBuilder, ((Number) value).longValue());
        return;
    }

    if (type instanceof DoubleType) {
        type.writeDouble(blockBuilder, (Double) value);
        return;
    }

    if (type instanceof RealType) {
        type.writeLong(blockBuilder, floatToIntBits((Float) value));
        return;
    }

    if (type instanceof VarcharType || type instanceof VarbinaryType) {
        type.writeSlice(blockBuilder, getSlice(value, type, columnName));
        return;
    }

    throw new PrestoException(DECODER_CONVERSION_NOT_SUPPORTED, format("cannot decode object of '%s' as '%s' for column '%s'", value.getClass(), type, columnName));
}
 
Example 28
Source Project: presto   Source File: HashAggregationOperator.java    License: Apache License 2.0 5 votes vote down vote up
private static long calculateDefaultOutputHash(List<Type> groupByChannels, int groupIdChannel, int groupId)
{
    // Default output has NULLs on all columns except of groupIdChannel
    long result = INITIAL_HASH_VALUE;
    for (int channel = 0; channel < groupByChannels.size(); channel++) {
        if (channel != groupIdChannel) {
            result = CombineHashFunction.getHash(result, NULL_HASH_CODE);
        }
        else {
            result = CombineHashFunction.getHash(result, BigintType.hash(groupId));
        }
    }
    return result;
}
 
Example 29
Source Project: presto   Source File: ScalarStatsCalculator.java    License: Apache License 2.0 5 votes vote down vote up
private boolean isIntegralType(Type type)
{
    if (type instanceof BigintType || type instanceof IntegerType || type instanceof SmallintType || type instanceof TinyintType) {
        return true;
    }

    if (type instanceof DecimalType) {
        return ((DecimalType) type).getScale() == 0;
    }

    return false;
}
 
Example 30
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;
}