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);
}
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());
}
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());
}
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();
}
}
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();
}
Aggregations