Search in sources :

Example 16 with SqlVarbinary

use of io.trino.spi.type.SqlVarbinary in project trino by trinodb.

the class TestQuantileDigestAggregationFunction method testAggregationBigints.

private void testAggregationBigints(List<TypeSignatureProvider> parameterTypes, Page page, double maxError, long... inputs) {
    // aggregate level
    assertAggregation(FUNCTION_RESOLUTION, NAME, parameterTypes, QDIGEST_EQUALITY, "test multiple positions", page, getExpectedValueLongs(maxError, inputs));
    // test scalars
    List<Long> rows = Arrays.stream(inputs).sorted().boxed().collect(Collectors.toList());
    SqlVarbinary returned = (SqlVarbinary) AggregationTestUtils.aggregation(FUNCTION_RESOLUTION.getAggregateFunction(NAME, parameterTypes), page);
    assertPercentileWithinError(StandardTypes.BIGINT, returned, maxError, rows, 0.1, 0.5, 0.9, 0.99);
}
Also used : FloatingPointBitsConverterUtil.doubleToSortableLong(io.trino.operator.aggregation.FloatingPointBitsConverterUtil.doubleToSortableLong) SqlVarbinary(io.trino.spi.type.SqlVarbinary)

Example 17 with SqlVarbinary

use of io.trino.spi.type.SqlVarbinary in project trino by trinodb.

the class TestQuantileDigestAggregationFunction method getExpectedValuesFloats.

private Object getExpectedValuesFloats(double maxError, float... values) {
    if (values.length == 0) {
        return null;
    }
    QuantileDigest qdigest = new QuantileDigest(maxError);
    Floats.asList(values).forEach(value -> qdigest.add(floatToSortableInt(value)));
    return new SqlVarbinary(qdigest.serialize().getBytes());
}
Also used : QuantileDigest(io.airlift.stats.QuantileDigest) SqlVarbinary(io.trino.spi.type.SqlVarbinary)

Example 18 with SqlVarbinary

use of io.trino.spi.type.SqlVarbinary in project trino by trinodb.

the class TestMergeHyperLogLogAggregation method getExpectedValue.

@Override
protected Object getExpectedValue(int start, int length) {
    if (length == 0) {
        return null;
    }
    HyperLogLog hll = HyperLogLog.newInstance(NUMBER_OF_BUCKETS);
    for (int i = start; i < start + length; i++) {
        hll.add(i);
    }
    hll.makeDense();
    return new SqlVarbinary(hll.serialize().getBytes());
}
Also used : SqlVarbinary(io.trino.spi.type.SqlVarbinary) HyperLogLog(io.airlift.stats.cardinality.HyperLogLog)

Example 19 with SqlVarbinary

use of io.trino.spi.type.SqlVarbinary in project trino by trinodb.

the class AbstractTestHiveFileFormats method checkPageSource.

protected void checkPageSource(ConnectorPageSource pageSource, List<TestColumn> testColumns, List<Type> types, int rowCount) throws IOException {
    try {
        MaterializedResult result = materializeSourceDataStream(SESSION, pageSource, types);
        assertEquals(result.getMaterializedRows().size(), rowCount);
        for (MaterializedRow row : result) {
            for (int i = 0, testColumnsSize = testColumns.size(); i < testColumnsSize; i++) {
                TestColumn testColumn = testColumns.get(i);
                Type type = types.get(i);
                Object actualValue = row.getField(i);
                Object expectedValue = testColumn.getExpectedValue();
                if (expectedValue instanceof Slice) {
                    expectedValue = ((Slice) expectedValue).toStringUtf8();
                }
                if (actualValue == null || expectedValue == null) {
                    assertEquals(actualValue, expectedValue, "Wrong value for column " + testColumn.getName());
                } else if (testColumn.getObjectInspector().getTypeName().equals("float")) {
                    assertEquals((float) actualValue, (float) expectedValue, EPSILON, "Wrong value for column " + testColumn.getName());
                } else if (testColumn.getObjectInspector().getTypeName().equals("double")) {
                    assertEquals((double) actualValue, (double) expectedValue, EPSILON, "Wrong value for column " + testColumn.getName());
                } else if (testColumn.getObjectInspector().getTypeName().equals("date")) {
                    SqlDate expectedDate = new SqlDate(((Long) expectedValue).intValue());
                    assertEquals(actualValue, expectedDate, "Wrong value for column " + testColumn.getName());
                } else if (testColumn.getObjectInspector().getTypeName().equals("int") || testColumn.getObjectInspector().getTypeName().equals("smallint") || testColumn.getObjectInspector().getTypeName().equals("tinyint")) {
                    assertEquals(actualValue, expectedValue);
                } else if (testColumn.getObjectInspector().getTypeName().equals("timestamp")) {
                    SqlTimestamp expectedTimestamp = sqlTimestampOf(floorDiv((Long) expectedValue, MICROSECONDS_PER_MILLISECOND));
                    assertEquals(actualValue, expectedTimestamp, "Wrong value for column " + testColumn.getName());
                } else if (testColumn.getObjectInspector().getTypeName().startsWith("char")) {
                    assertEquals(actualValue, padSpaces((String) expectedValue, (CharType) type), "Wrong value for column " + testColumn.getName());
                } else if (testColumn.getObjectInspector().getCategory() == Category.PRIMITIVE) {
                    if (expectedValue instanceof Slice) {
                        expectedValue = ((Slice) expectedValue).toStringUtf8();
                    }
                    if (actualValue instanceof Slice) {
                        actualValue = ((Slice) actualValue).toStringUtf8();
                    }
                    if (actualValue instanceof SqlVarbinary) {
                        actualValue = new String(((SqlVarbinary) actualValue).getBytes(), UTF_8);
                    }
                    if (actualValue instanceof SqlDecimal) {
                        actualValue = new BigDecimal(actualValue.toString());
                    }
                    assertEquals(actualValue, expectedValue, "Wrong value for column " + testColumn.getName());
                } else {
                    BlockBuilder builder = type.createBlockBuilder(null, 1);
                    type.writeObject(builder, expectedValue);
                    expectedValue = type.getObjectValue(SESSION, builder.build(), 0);
                    assertEquals(actualValue, expectedValue, "Wrong value for column " + testColumn.getName());
                }
            }
        }
    } finally {
        pageSource.close();
    }
}
Also used : SqlVarbinary(io.trino.spi.type.SqlVarbinary) SqlTimestamp(io.trino.spi.type.SqlTimestamp) SqlDecimal(io.trino.spi.type.SqlDecimal) BigDecimal(java.math.BigDecimal) DateType(io.trino.spi.type.DateType) CharType.createCharType(io.trino.spi.type.CharType.createCharType) TimestampType(io.trino.spi.type.TimestampType) HiveTestUtils.mapType(io.trino.plugin.hive.HiveTestUtils.mapType) CharType(io.trino.spi.type.CharType) VarcharType.createVarcharType(io.trino.spi.type.VarcharType.createVarcharType) RowType(io.trino.spi.type.RowType) ArrayType(io.trino.spi.type.ArrayType) DecimalType(io.trino.spi.type.DecimalType) Type(io.trino.spi.type.Type) VarcharType.createUnboundedVarcharType(io.trino.spi.type.VarcharType.createUnboundedVarcharType) VarcharType(io.trino.spi.type.VarcharType) HiveUtil.isStructuralType(io.trino.plugin.hive.util.HiveUtil.isStructuralType) Slice(io.airlift.slice.Slice) SqlDate(io.trino.spi.type.SqlDate) SerDeUtils.serializeObject(io.trino.plugin.hive.util.SerDeUtils.serializeObject) CharType.createCharType(io.trino.spi.type.CharType.createCharType) CharType(io.trino.spi.type.CharType) MaterializedResult(io.trino.testing.MaterializedResult) MaterializedRow(io.trino.testing.MaterializedRow) BlockBuilder(io.trino.spi.block.BlockBuilder)

Example 20 with SqlVarbinary

use of io.trino.spi.type.SqlVarbinary in project trino by trinodb.

the class Validator method convertJdbcResultSet.

private List<List<Object>> convertJdbcResultSet(ResultSet resultSet) throws SQLException, VerifierException {
    int rowCount = 0;
    int columnCount = resultSet.getMetaData().getColumnCount();
    ImmutableList.Builder<List<Object>> rows = ImmutableList.builder();
    while (resultSet.next()) {
        List<Object> row = new ArrayList<>();
        for (int i = 1; i <= columnCount; i++) {
            Object object = resultSet.getObject(i);
            if (object instanceof BigDecimal) {
                if (((BigDecimal) object).scale() <= 0) {
                    object = ((BigDecimal) object).longValueExact();
                } else {
                    object = ((BigDecimal) object).doubleValue();
                }
            }
            if (object instanceof Array) {
                object = ((Array) object).getArray();
            }
            if (object instanceof byte[]) {
                object = new SqlVarbinary((byte[]) object);
            }
            row.add(object);
        }
        rows.add(unmodifiableList(row));
        rowCount++;
        if (rowCount > maxRowCount) {
            throw new VerifierException("More than '" + maxRowCount + "' rows, failing query");
        }
    }
    return rows.build();
}
Also used : Array(java.sql.Array) ImmutableList(com.google.common.collect.ImmutableList) ArrayList(java.util.ArrayList) SqlVarbinary(io.trino.spi.type.SqlVarbinary) Collections.unmodifiableList(java.util.Collections.unmodifiableList) List(java.util.List) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) BigDecimal(java.math.BigDecimal)

Aggregations

SqlVarbinary (io.trino.spi.type.SqlVarbinary)20 List (java.util.List)10 ImmutableList (com.google.common.collect.ImmutableList)9 DecimalType (io.trino.spi.type.DecimalType)8 SqlDecimal (io.trino.spi.type.SqlDecimal)8 ArrayList (java.util.ArrayList)8 ArrayType (io.trino.spi.type.ArrayType)7 SqlTimestamp (io.trino.spi.type.SqlTimestamp)7 BlockBuilder (io.trino.spi.block.BlockBuilder)6 RowType (io.trino.spi.type.RowType)6 SqlDate (io.trino.spi.type.SqlDate)6 Type (io.trino.spi.type.Type)6 VarcharType (io.trino.spi.type.VarcharType)6 Collectors.toList (java.util.stream.Collectors.toList)6 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)5 ImmutableMap (com.google.common.collect.ImmutableMap)5 Slice (io.airlift.slice.Slice)5 HashMap (java.util.HashMap)5 Map (java.util.Map)5 Lists.newArrayList (com.google.common.collect.Lists.newArrayList)4