use of com.facebook.presto.metadata.Signature in project presto by prestodb.
the class TestExpressionOptimizer method testTryOptimization.
@Test
public void testTryOptimization() {
TypeRegistry typeManager = new TypeRegistry();
ExpressionOptimizer optimizer = new ExpressionOptimizer(new FunctionRegistry(typeManager, new BlockEncodingManager(typeManager), new FeaturesConfig()), typeManager, TEST_SESSION);
Signature signature = new Signature("TRY", SCALAR, BIGINT.getTypeSignature());
RowExpression tryExpression = new CallExpression(signature, BIGINT, ImmutableList.of(new ConstantExpression(1L, BIGINT)));
assertEquals(optimizer.optimize(tryExpression), new ConstantExpression(1L, BIGINT));
tryExpression = new CallExpression(signature, BIGINT, ImmutableList.of(new InputReferenceExpression(1, BIGINT)));
assertEquals(optimizer.optimize(tryExpression), new InputReferenceExpression(1, BIGINT));
}
use of com.facebook.presto.metadata.Signature in project presto by prestodb.
the class TestInCodeGenerator method testInteger.
@Test
public void testInteger() {
List<RowExpression> values = new ArrayList<>();
values.add(new ConstantExpression(Integer.MIN_VALUE, INTEGER));
values.add(new ConstantExpression(Integer.MAX_VALUE, INTEGER));
values.add(new ConstantExpression(3, INTEGER));
assertEquals(checkSwitchGenerationCase(INTEGER, values), DIRECT_SWITCH);
values.add(new ConstantExpression(null, INTEGER));
assertEquals(checkSwitchGenerationCase(INTEGER, values), DIRECT_SWITCH);
values.add(new CallExpression(new Signature(CAST, SCALAR, INTEGER.getTypeSignature(), DOUBLE.getTypeSignature()), INTEGER, Collections.singletonList(new ConstantExpression(12345678901234.0, DOUBLE))));
assertEquals(checkSwitchGenerationCase(INTEGER, values), DIRECT_SWITCH);
for (int i = 6; i <= 32; ++i) {
values.add(new ConstantExpression(i, INTEGER));
}
assertEquals(checkSwitchGenerationCase(INTEGER, values), DIRECT_SWITCH);
values.add(new ConstantExpression(33, INTEGER));
assertEquals(checkSwitchGenerationCase(INTEGER, values), SET_CONTAINS);
}
use of com.facebook.presto.metadata.Signature in project presto by prestodb.
the class TestChecksumAggregation method testLong.
@Test
public void testLong() throws Exception {
InternalAggregationFunction longAgg = metadata.getFunctionRegistry().getAggregateFunctionImplementation(new Signature("checksum", AGGREGATE, parseTypeSignature(VARBINARY), parseTypeSignature(BIGINT)));
Block block = createLongsBlock(null, 1L, 2L, 100L, null, Long.MAX_VALUE, Long.MIN_VALUE);
assertAggregation(longAgg, expectedChecksum(BigintType.BIGINT, block), block);
}
use of com.facebook.presto.metadata.Signature in project presto by prestodb.
the class TestChecksumAggregation method testArray.
@Test
public void testArray() throws Exception {
ArrayType arrayType = new ArrayType(BigintType.BIGINT);
InternalAggregationFunction stringAgg = metadata.getFunctionRegistry().getAggregateFunctionImplementation(new Signature("checksum", AGGREGATE, VarbinaryType.VARBINARY.getTypeSignature(), arrayType.getTypeSignature()));
Block block = createArrayBigintBlock(asList(null, asList(1L, 2L), asList(3L, 4L), asList(5L, 6L)));
assertAggregation(stringAgg, expectedChecksum(arrayType, block), block);
}
use of com.facebook.presto.metadata.Signature in project presto by prestodb.
the class TestChecksumAggregation method testString.
@Test
public void testString() throws Exception {
InternalAggregationFunction stringAgg = metadata.getFunctionRegistry().getAggregateFunctionImplementation(new Signature("checksum", AGGREGATE, parseTypeSignature(VARBINARY), parseTypeSignature(VARCHAR)));
Block block = createStringsBlock("a", "a", null, "b", "c");
assertAggregation(stringAgg, expectedChecksum(VarcharType.VARCHAR, block), block);
}
Aggregations