use of com.facebook.presto.common.type.SqlVarbinary in project presto by prestodb.
the class TestStringFunctions method testUpper.
@Test
public void testUpper() {
assertFunction("UPPER('')", createVarcharType(0), "");
assertFunction("UPPER('Hello World')", createVarcharType(11), "HELLO WORLD");
assertFunction("UPPER('what!!')", createVarcharType(6), "WHAT!!");
assertFunction("UPPER('\u00D6sterreich')", createVarcharType(10), upperByCodePoint("\u00D6") + "STERREICH");
assertFunction("UPPER('From\uD801\uDC2DTo')", createVarcharType(7), "FROM" + upperByCodePoint("\uD801\uDC2D") + "TO");
assertFunction("CAST(UPPER(utf8(from_hex('CE'))) AS VARBINARY)", VARBINARY, new SqlVarbinary(new byte[] { (byte) 0xCE }));
assertFunction("CAST(UPPER('hello' || utf8(from_hex('CE'))) AS VARBINARY)", VARBINARY, new SqlVarbinary(new byte[] { 'H', 'E', 'L', 'L', 'O', (byte) 0xCE }));
assertFunction("CAST(UPPER(utf8(from_hex('CE')) || 'hello') AS VARBINARY)", VARBINARY, new SqlVarbinary(new byte[] { (byte) 0xCE, 'H', 'E', 'L', 'L', 'O' }));
}
use of com.facebook.presto.common.type.SqlVarbinary in project presto by prestodb.
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' }));
}
use of com.facebook.presto.common.type.SqlVarbinary in project presto by prestodb.
the class TestTDigestFunctions method testScale.
@Test
public void testScale() {
TDigest tDigest = createTDigest(STANDARD_COMPRESSION_FACTOR);
addAll(tDigest, 0.0d, 1.0d, 2.0d, 3.0d, 4.0d, 5.0d, 6.0d, 7.0d, 8.0d, 9.0d);
// Before scaling.
List<Double> unscaledFrequencies = getFrequencies(tDigest, asList(2.0d, 4.0d, 6.0d, 8.0d));
// Scale up.
SqlVarbinary sqlVarbinary = functionAssertions.selectSingleValue(format("scale_tdigest(CAST(X'%s' AS tdigest(double)), 2)", new SqlVarbinary(tDigest.serialize().getBytes()).toString().replaceAll("\\s+", " ")), TDIGEST_DOUBLE, SqlVarbinary.class);
TDigest scaledTdigest = createTDigest(wrappedBuffer(sqlVarbinary.getBytes()));
List<Double> scaledDigestFrequencies = getFrequencies(scaledTdigest, asList(2.0d, 4.0d, 6.0d, 8.0d));
List<Double> scaledUpFrequencies = new ArrayList<>();
unscaledFrequencies.forEach(frequency -> scaledUpFrequencies.add(frequency * 2));
assertEquals(scaledDigestFrequencies, scaledUpFrequencies);
// Scale down.
sqlVarbinary = functionAssertions.selectSingleValue(format("scale_tdigest(CAST(X'%s' AS tdigest(double)), 0.5)", new SqlVarbinary(tDigest.serialize().getBytes()).toString().replaceAll("\\s+", " ")), TDIGEST_DOUBLE, SqlVarbinary.class);
scaledTdigest = createTDigest(wrappedBuffer(sqlVarbinary.getBytes()));
scaledDigestFrequencies = getFrequencies(scaledTdigest, asList(2.0d, 4.0d, 6.0d, 8.0d));
List<Double> scaledDownFrequencies = new ArrayList<>();
unscaledFrequencies.forEach(frequency -> scaledDownFrequencies.add(frequency * 0.5));
assertEquals(scaledDigestFrequencies, scaledDownFrequencies);
}
use of com.facebook.presto.common.type.SqlVarbinary in project presto by prestodb.
the class TestTDigestFunctions method testGetQuantileAtValueOutsideRange.
@Test
public void testGetQuantileAtValueOutsideRange() {
TDigest tDigest = createTDigest(STANDARD_COMPRESSION_FACTOR);
for (int i = 0; i < NUMBER_OF_ENTRIES; i++) {
double value = Math.random() * NUMBER_OF_ENTRIES;
tDigest.add(value);
}
functionAssertions.assertFunction(format("quantile_at_value(CAST(X'%s' AS tdigest(%s)), %s) = 1", new SqlVarbinary(tDigest.serialize().getBytes()).toString().replaceAll("\\s+", " "), DOUBLE, 1_000_000_000d), BOOLEAN, true);
functionAssertions.assertFunction(format("quantile_at_value(CAST(X'%s' AS tdigest(%s)), %s) = 0", new SqlVarbinary(tDigest.serialize().getBytes()).toString().replaceAll("\\s+", " "), DOUBLE, -500d), BOOLEAN, true);
}
use of com.facebook.presto.common.type.SqlVarbinary in project presto by prestodb.
the class TestKHyperLogLogAggregationFunction method testAggregation.
private void testAggregation(Type valueType, List<?> values, Type uiiType, List<?> uiis) {
InternalAggregationFunction aggregationFunction = getAggregation(valueType, uiiType);
KHyperLogLog khll = null;
long value;
long uii;
for (int i = 0; i < values.size(); i++) {
if (values.get(i) == null || uiis.get(i) == null) {
continue;
}
if (khll == null) {
khll = new KHyperLogLog();
}
value = toLong(values.get(i), valueType);
uii = toLong(uiis.get(i), uiiType);
if (valueType == VARCHAR) {
khll.add((Slice) values.get(i), uii);
} else {
khll.add(value, uii);
}
}
assertAggregation(aggregationFunction, (khll == null) ? null : new SqlVarbinary(khll.serialize().getBytes()), buildBlock(values, valueType), buildBlock(uiis, uiiType));
}
Aggregations