use of com.facebook.presto.common.type.SqlVarbinary in project presto by prestodb.
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 com.facebook.presto.common.type.SqlVarbinary in project presto by prestodb.
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(QDIGEST, StandardTypes.BIGINT, returned, maxError, rows, 0.1, 0.5, 0.9, 0.99);
}
use of com.facebook.presto.common.type.SqlVarbinary in project presto by prestodb.
the class TestQuantileDigestAggregationFunction method getExpectedValueLongs.
private Object getExpectedValueLongs(double maxError, long... values) {
if (values.length == 0) {
return null;
}
QuantileDigest qdigest = new QuantileDigest(maxError);
Arrays.stream(values).forEach(qdigest::add);
return new SqlVarbinary(qdigest.serialize().getBytes());
}
use of com.facebook.presto.common.type.SqlVarbinary in project presto by prestodb.
the class TestTDigestFunctions method testDestructureTDigestLarge.
@Test
public void testDestructureTDigestLarge() {
TDigest tDigest = createTDigest(STANDARD_COMPRESSION_FACTOR);
List<Double> values = new ArrayList<>();
for (int i = 0; i < NUMBER_OF_ENTRIES; i++) {
values.add((double) i);
}
values.stream().forEach(tDigest::add);
double compression = Double.valueOf(STANDARD_COMPRESSION_FACTOR);
double min = values.stream().reduce(Double.POSITIVE_INFINITY, Double::min);
double max = values.stream().reduce(Double.NEGATIVE_INFINITY, Double::max);
double sum = values.stream().reduce(0.0d, Double::sum);
long count = values.size();
String sql = format("destructure_tdigest(CAST(X'%s' AS tdigest(%s)))", new SqlVarbinary(tDigest.serialize().getBytes()).toString().replaceAll("\\s+", " "), DOUBLE);
functionAssertions.assertFunction(format("%s.compression", sql), DOUBLE, compression);
functionAssertions.assertFunction(format("%s.min", sql), DOUBLE, min);
functionAssertions.assertFunction(format("%s.max", sql), DOUBLE, max);
functionAssertions.assertFunction(format("%s.sum", sql), DOUBLE, sum);
functionAssertions.assertFunction(format("%s.count", sql), BIGINT, count);
}
use of com.facebook.presto.common.type.SqlVarbinary in project presto by prestodb.
the class TestStringFunctions method testReplace.
@Test
public void testReplace() {
assertFunction("REPLACE('aaa', 'a', 'aa')", createVarcharType(11), "aaaaaa");
assertFunction("REPLACE('abcdefabcdef', 'cd', 'XX')", createVarcharType(38), "abXXefabXXef");
assertFunction("REPLACE('abcdefabcdef', 'cd')", createVarcharType(12), "abefabef");
assertFunction("REPLACE('123123tech', '123')", createVarcharType(10), "tech");
assertFunction("REPLACE('123tech123', '123')", createVarcharType(10), "tech");
assertFunction("REPLACE('222tech', '2', '3')", createVarcharType(15), "333tech");
assertFunction("REPLACE('0000123', '0')", createVarcharType(7), "123");
assertFunction("REPLACE('0000123', '0', ' ')", createVarcharType(15), " 123");
assertFunction("REPLACE('foo', '')", createVarcharType(3), "foo");
assertFunction("REPLACE('foo', '', '')", createVarcharType(3), "foo");
assertFunction("REPLACE('foo', 'foo', '')", createVarcharType(3), "");
assertFunction("REPLACE('abc', '', 'xx')", createVarcharType(11), "xxaxxbxxcxx");
assertFunction("REPLACE('', '', 'xx')", createVarcharType(2), "xx");
assertFunction("REPLACE('', '')", createVarcharType(0), "");
assertFunction("REPLACE('', '', '')", createVarcharType(0), "");
assertFunction("REPLACE('\u4FE1\u5FF5,\u7231,\u5E0C\u671B', ',', '\u2014')", createVarcharType(15), "\u4FE1\u5FF5\u2014\u7231\u2014\u5E0C\u671B");
// \uD801\uDC2D is one character
assertFunction("REPLACE('::\uD801\uDC2D::', ':', '')", createVarcharType(5), "\uD801\uDC2D");
assertFunction("REPLACE('\u00D6sterreich', '\u00D6', 'Oe')", createVarcharType(32), "Oesterreich");
assertFunction("CAST(REPLACE(utf8(from_hex('CE')), '', 'X') AS VARBINARY)", VARBINARY, new SqlVarbinary(new byte[] { 'X', (byte) 0xCE, 'X' }));
assertFunction("CAST(REPLACE('abc' || utf8(from_hex('CE')), '', 'X') AS VARBINARY)", VARBINARY, new SqlVarbinary(new byte[] { 'X', 'a', 'X', 'b', 'X', 'c', 'X', (byte) 0xCE, 'X' }));
assertFunction("CAST(REPLACE(utf8(from_hex('CE')) || 'xyz', '', 'X') AS VARBINARY)", VARBINARY, new SqlVarbinary(new byte[] { 'X', (byte) 0xCE, 'X', 'x', 'X', 'y', 'X', 'z', 'X' }));
assertFunction("CAST(REPLACE('abc' || utf8(from_hex('CE')) || 'xyz', '', 'X') AS VARBINARY)", VARBINARY, new SqlVarbinary(new byte[] { 'X', 'a', 'X', 'b', 'X', 'c', 'X', (byte) 0xCE, 'X', 'x', 'X', 'y', 'X', 'z', 'X' }));
String longString = new String(new char[1_000_000]);
assertInvalidFunction(String.format("replace('%s', '', '%s')", longString, longString), "inputs to \"replace\" function are too large: when \"search\" parameter is empty, length of \"string\" times length of \"replace\" must not exceed 2147483647");
}
Aggregations