use of com.facebook.presto.common.type.SqlVarbinary in project presto by prestodb.
the class TestStringFunctions method testLower.
@Test
public void testLower() {
assertFunction("LOWER('')", createVarcharType(0), "");
assertFunction("LOWER('Hello World')", createVarcharType(11), "hello world");
assertFunction("LOWER('WHAT!!')", createVarcharType(6), "what!!");
assertFunction("LOWER('\u00D6STERREICH')", createVarcharType(10), lowerByCodePoint("\u00D6sterreich"));
assertFunction("LOWER('From\uD801\uDC2DTo')", createVarcharType(7), lowerByCodePoint("from\uD801\uDC2Dto"));
assertFunction("CAST(LOWER(utf8(from_hex('CE'))) AS VARBINARY)", VARBINARY, new SqlVarbinary(new byte[] { (byte) 0xCE }));
assertFunction("CAST(LOWER('HELLO' || utf8(from_hex('CE'))) AS VARBINARY)", VARBINARY, new SqlVarbinary(new byte[] { 'h', 'e', 'l', 'l', 'o', (byte) 0xCE }));
assertFunction("CAST(LOWER(utf8(from_hex('CE')) || 'HELLO') AS VARBINARY)", VARBINARY, new SqlVarbinary(new byte[] { (byte) 0xCE, 'h', 'e', 'l', 'l', 'o' }));
assertFunction("CAST(LOWER(utf8(from_hex('C8BAFF'))) AS VARBINARY)", VARBINARY, new SqlVarbinary(new byte[] { (byte) 0xE2, (byte) 0xB1, (byte) 0xA5, (byte) 0xFF }));
}
use of com.facebook.presto.common.type.SqlVarbinary in project presto by prestodb.
the class TestTDigestFunctions method testDestructureTDigest.
@Test
public void testDestructureTDigest() {
TDigest tDigest = createTDigest(STANDARD_COMPRESSION_FACTOR);
ImmutableList<Double> values = ImmutableList.of(0.0d, 1.0d, 2.0d, 3.0d, 4.0d, 5.0d, 6.0d, 7.0d, 8.0d, 9.0d);
values.stream().forEach(tDigest::add);
List<Integer> weights = Collections.nCopies(values.size(), 1);
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(sql, TDIGEST_CENTROIDS_ROW_TYPE, ImmutableList.of(values, weights, compression, min, max, sum, count));
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);
functionAssertions.assertFunction(format("%s.centroid_means", sql), new ArrayType(DOUBLE), values);
functionAssertions.assertFunction(format("%s.centroid_weights", sql), new ArrayType(INTEGER), weights);
}
use of com.facebook.presto.common.type.SqlVarbinary in project presto by prestodb.
the class TestTDigestFunctions method testScaleNegative.
@Test(expectedExceptions = PrestoException.class, expectedExceptionsMessageRegExp = "Scale factor should be positive\\.")
public void testScaleNegative() {
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);
functionAssertions.selectSingleValue(format("scale_tdigest(CAST(X'%s' AS tdigest(double)), -1)", new SqlVarbinary(tDigest.serialize().getBytes()).toString().replaceAll("\\s+", " ")), TDIGEST_DOUBLE, SqlVarbinary.class);
}
use of com.facebook.presto.common.type.SqlVarbinary in project presto by prestodb.
the class OrcTester method testValue.
private static boolean testValue(Type type, Object value, TupleDomainFilter filter) {
if (value == null) {
return filter.testNull();
}
if (filter == IS_NULL) {
return false;
}
if (filter == IS_NOT_NULL) {
return true;
}
if (type == BOOLEAN) {
return filter.testBoolean((Boolean) value);
}
if (type == TINYINT || type == BIGINT || type == INTEGER || type == SMALLINT) {
return filter.testLong(((Number) value).longValue());
}
if (type == REAL) {
return filter.testFloat(((Number) value).floatValue());
}
if (type == DOUBLE) {
return filter.testDouble((double) value);
}
if (type == DATE) {
return filter.testLong(((SqlDate) value).getDays());
}
if (type == TIMESTAMP) {
return filter.testLong(((SqlTimestamp) value).getMillisUtc());
}
if (type instanceof DecimalType) {
DecimalType decimalType = (DecimalType) type;
BigDecimal bigDecimal = ((SqlDecimal) value).toBigDecimal();
if (decimalType.isShort()) {
return filter.testLong(bigDecimal.unscaledValue().longValue());
} else {
Slice encodedDecimal = Decimals.encodeScaledValue(bigDecimal);
return filter.testDecimal(encodedDecimal.getLong(0), encodedDecimal.getLong(Long.BYTES));
}
}
if (type == VARCHAR) {
return filter.testBytes(((String) value).getBytes(), 0, ((String) value).length());
}
if (type instanceof CharType) {
String charString = String.valueOf(value);
return filter.testBytes(charString.getBytes(), 0, charString.length());
}
if (type == VARBINARY) {
byte[] binary = ((SqlVarbinary) value).getBytes();
return filter.testBytes(binary, 0, binary.length);
}
fail("Unsupported type: " + type);
return false;
}
use of com.facebook.presto.common.type.SqlVarbinary in project presto by prestodb.
the class TestMapOperators method testMapKeys.
@Test
public void testMapKeys() {
assertFunction("MAP_KEYS(MAP(ARRAY['1', '3'], ARRAY['2', '4']))", new ArrayType(createVarcharType(1)), ImmutableList.of("1", "3"));
assertFunction("MAP_KEYS(MAP(ARRAY[1.0E0, 2.0E0], ARRAY[ARRAY[1, 2], ARRAY[3]]))", new ArrayType(DOUBLE), ImmutableList.of(1.0, 2.0));
assertFunction("MAP_KEYS(MAP(ARRAY['puppies'], ARRAY['kittens']))", new ArrayType(createVarcharType(7)), ImmutableList.of("puppies"));
assertFunction("MAP_KEYS(MAP(ARRAY[TRUE], ARRAY[2]))", new ArrayType(BOOLEAN), ImmutableList.of(true));
assertFunction("MAP_KEYS(MAP(ARRAY[TIMESTAMP '1970-01-01 00:00:01'], ARRAY[1.0E0]))", new ArrayType(TIMESTAMP), ImmutableList.of(sqlTimestampOf(1970, 1, 1, 0, 0, 1, 0, TEST_SESSION)));
assertFunction("MAP_KEYS(MAP(ARRAY[CAST('puppies' as varbinary)], ARRAY['kittens']))", new ArrayType(VARBINARY), ImmutableList.of(new SqlVarbinary("puppies".getBytes(UTF_8))));
assertFunction("MAP_KEYS(MAP(ARRAY[1,2], ARRAY[ARRAY[1, 2], ARRAY[3]]))", new ArrayType(INTEGER), ImmutableList.of(1, 2));
assertFunction("MAP_KEYS(MAP(ARRAY[1,4], ARRAY[MAP(ARRAY[2], ARRAY[3]), MAP(ARRAY[5], ARRAY[6])]))", new ArrayType(INTEGER), ImmutableList.of(1, 4));
assertFunction("MAP_KEYS(MAP(ARRAY [ARRAY [1], ARRAY [2, 3]], ARRAY [ARRAY [3, 4], ARRAY [5]]))", new ArrayType(new ArrayType(INTEGER)), ImmutableList.of(ImmutableList.of(1), ImmutableList.of(2, 3)));
assertFunction("MAP_KEYS(MAP(ARRAY [1.0, 383838383838383.12324234234234], ARRAY [2.2, 3.3]))", new ArrayType(createDecimalType(29, 14)), ImmutableList.of(decimal("000000000000001.00000000000000"), decimal("383838383838383.12324234234234")));
assertFunction("MAP_KEYS(MAP(ARRAY [1.0, 2.01], ARRAY [2.2, 3.3]))", new ArrayType(createDecimalType(3, 2)), ImmutableList.of(decimal("1.00"), decimal("2.01")));
}
Aggregations