use of io.prestosql.spi.type.SqlVarbinary in project hetu-core by openlookeng.
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.prestosql.spi.type.SqlVarbinary in project hetu-core by openlookeng.
the class TestQuantileDigestAggregationFunction method testAggregationReal.
private void testAggregationReal(InternalAggregationFunction function, Page page, double maxError, float... inputs) {
assertAggregation(function, QDIGEST_EQUALITY, "test multiple positions", page, getExpectedValuesFloats(maxError, inputs));
// test scalars
List<Double> rows = Floats.asList(inputs).stream().sorted().map(Float::doubleValue).collect(Collectors.toList());
SqlVarbinary returned = (SqlVarbinary) AggregationTestUtils.aggregation(function, page);
assertPercentileWithinError(StandardTypes.REAL, returned, maxError, rows, 0.1, 0.5, 0.9, 0.99);
}
use of io.prestosql.spi.type.SqlVarbinary in project hetu-core by openlookeng.
the class TestQuantileDigestAggregationFunction method testAggregationBigints.
private void testAggregationBigints(InternalAggregationFunction function, Page page, double maxError, long... inputs) {
// aggregate level
assertAggregation(function, 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, page);
assertPercentileWithinError(StandardTypes.BIGINT, returned, maxError, rows, 0.1, 0.5, 0.9, 0.99);
}
use of io.prestosql.spi.type.SqlVarbinary in project hetu-core by openlookeng.
the class TestQuantileDigestAggregationFunction method testAggregationDoubles.
private void testAggregationDoubles(InternalAggregationFunction function, Page page, double maxError, double... inputs) {
assertAggregation(function, QDIGEST_EQUALITY, "test multiple positions", page, getExpectedValueDoubles(maxError, inputs));
// test scalars
List<Double> rows = Arrays.stream(inputs).sorted().boxed().collect(Collectors.toList());
SqlVarbinary returned = (SqlVarbinary) AggregationTestUtils.aggregation(function, page);
assertPercentileWithinError(StandardTypes.DOUBLE, returned, maxError, rows, 0.1, 0.5, 0.9, 0.99);
}
use of io.prestosql.spi.type.SqlVarbinary in project hetu-core by openlookeng.
the class TestStringFunctions method testReverse.
@Test
public void testReverse() {
assertFunction("REVERSE('')", createVarcharType(0), "");
assertFunction("REVERSE('hello')", createVarcharType(5), "olleh");
assertFunction("REVERSE('Quadratically')", createVarcharType(13), "yllacitardauQ");
assertFunction("REVERSE('racecar')", createVarcharType(7), "racecar");
// Test REVERSE for non-ASCII
assertFunction("REVERSE('\u4FE1\u5FF5,\u7231,\u5E0C\u671B')", createVarcharType(7), "\u671B\u5E0C,\u7231,\u5FF5\u4FE1");
assertFunction("REVERSE('\u00D6sterreich')", createVarcharType(10), "hcierrets\u00D6");
assertFunction("REVERSE('na\u00EFve')", createVarcharType(5), "ev\u00EFan");
assertFunction("REVERSE('\uD801\uDC2Dend')", createVarcharType(4), "dne\uD801\uDC2D");
assertFunction("CAST(REVERSE(utf8(from_hex('CE'))) AS VARBINARY)", VARBINARY, new SqlVarbinary(new byte[] { (byte) 0xCE }));
assertFunction("CAST(REVERSE('hello' || utf8(from_hex('CE'))) AS VARBINARY)", VARBINARY, new SqlVarbinary(new byte[] { (byte) 0xCE, 'o', 'l', 'l', 'e', 'h' }));
}
Aggregations