Search in sources :

Example 81 with Signature

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));
}
Also used : FunctionRegistry(com.facebook.presto.metadata.FunctionRegistry) BlockEncodingManager(com.facebook.presto.block.BlockEncodingManager) InputReferenceExpression(com.facebook.presto.sql.relational.InputReferenceExpression) FeaturesConfig(com.facebook.presto.sql.analyzer.FeaturesConfig) ExpressionOptimizer(com.facebook.presto.sql.relational.optimizer.ExpressionOptimizer) Signature(com.facebook.presto.metadata.Signature) TypeSignature.parseTypeSignature(com.facebook.presto.spi.type.TypeSignature.parseTypeSignature) ConstantExpression(com.facebook.presto.sql.relational.ConstantExpression) RowExpression(com.facebook.presto.sql.relational.RowExpression) TypeRegistry(com.facebook.presto.type.TypeRegistry) CallExpression(com.facebook.presto.sql.relational.CallExpression) Test(org.testng.annotations.Test)

Example 82 with Signature

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);
}
Also used : ConstantExpression(com.facebook.presto.sql.relational.ConstantExpression) Signature(com.facebook.presto.metadata.Signature) ArrayList(java.util.ArrayList) RowExpression(com.facebook.presto.sql.relational.RowExpression) CallExpression(com.facebook.presto.sql.relational.CallExpression) Test(org.testng.annotations.Test)

Example 83 with Signature

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);
}
Also used : Signature(com.facebook.presto.metadata.Signature) TypeSignature.parseTypeSignature(com.facebook.presto.spi.type.TypeSignature.parseTypeSignature) Block(com.facebook.presto.spi.block.Block) BlockAssertions.createLongsBlock(com.facebook.presto.block.BlockAssertions.createLongsBlock) BlockAssertions.createShortDecimalsBlock(com.facebook.presto.block.BlockAssertions.createShortDecimalsBlock) BlockAssertions.createLongDecimalsBlock(com.facebook.presto.block.BlockAssertions.createLongDecimalsBlock) BlockAssertions.createStringsBlock(com.facebook.presto.block.BlockAssertions.createStringsBlock) BlockAssertions.createArrayBigintBlock(com.facebook.presto.block.BlockAssertions.createArrayBigintBlock) BlockAssertions.createBooleansBlock(com.facebook.presto.block.BlockAssertions.createBooleansBlock) BlockAssertions.createDoublesBlock(com.facebook.presto.block.BlockAssertions.createDoublesBlock) Test(org.testng.annotations.Test)

Example 84 with Signature

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);
}
Also used : ArrayType(com.facebook.presto.type.ArrayType) Signature(com.facebook.presto.metadata.Signature) TypeSignature.parseTypeSignature(com.facebook.presto.spi.type.TypeSignature.parseTypeSignature) Block(com.facebook.presto.spi.block.Block) BlockAssertions.createLongsBlock(com.facebook.presto.block.BlockAssertions.createLongsBlock) BlockAssertions.createShortDecimalsBlock(com.facebook.presto.block.BlockAssertions.createShortDecimalsBlock) BlockAssertions.createLongDecimalsBlock(com.facebook.presto.block.BlockAssertions.createLongDecimalsBlock) BlockAssertions.createStringsBlock(com.facebook.presto.block.BlockAssertions.createStringsBlock) BlockAssertions.createArrayBigintBlock(com.facebook.presto.block.BlockAssertions.createArrayBigintBlock) BlockAssertions.createBooleansBlock(com.facebook.presto.block.BlockAssertions.createBooleansBlock) BlockAssertions.createDoublesBlock(com.facebook.presto.block.BlockAssertions.createDoublesBlock) Test(org.testng.annotations.Test)

Example 85 with Signature

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);
}
Also used : Signature(com.facebook.presto.metadata.Signature) TypeSignature.parseTypeSignature(com.facebook.presto.spi.type.TypeSignature.parseTypeSignature) Block(com.facebook.presto.spi.block.Block) BlockAssertions.createLongsBlock(com.facebook.presto.block.BlockAssertions.createLongsBlock) BlockAssertions.createShortDecimalsBlock(com.facebook.presto.block.BlockAssertions.createShortDecimalsBlock) BlockAssertions.createLongDecimalsBlock(com.facebook.presto.block.BlockAssertions.createLongDecimalsBlock) BlockAssertions.createStringsBlock(com.facebook.presto.block.BlockAssertions.createStringsBlock) BlockAssertions.createArrayBigintBlock(com.facebook.presto.block.BlockAssertions.createArrayBigintBlock) BlockAssertions.createBooleansBlock(com.facebook.presto.block.BlockAssertions.createBooleansBlock) BlockAssertions.createDoublesBlock(com.facebook.presto.block.BlockAssertions.createDoublesBlock) Test(org.testng.annotations.Test)

Aggregations

Signature (com.facebook.presto.metadata.Signature)123 TypeSignature.parseTypeSignature (com.facebook.presto.spi.type.TypeSignature.parseTypeSignature)96 Test (org.testng.annotations.Test)91 MapType (com.facebook.presto.type.MapType)18 ImmutableList (com.google.common.collect.ImmutableList)16 RowExpression (com.facebook.presto.sql.relational.RowExpression)12 TypeSignature (com.facebook.presto.spi.type.TypeSignature)11 FunctionCall (com.facebook.presto.sql.tree.FunctionCall)11 Block (com.facebook.presto.spi.block.Block)10 Type (com.facebook.presto.spi.type.Type)10 InternalAggregationFunction (com.facebook.presto.operator.aggregation.InternalAggregationFunction)8 Page (com.facebook.presto.spi.Page)8 DecimalType (com.facebook.presto.spi.type.DecimalType)8 CallExpression (com.facebook.presto.sql.relational.CallExpression)8 MethodHandle (java.lang.invoke.MethodHandle)8 MetadataManager (com.facebook.presto.metadata.MetadataManager)7 PlanNode (com.facebook.presto.sql.planner.plan.PlanNode)7 PlanNodeId (com.facebook.presto.sql.planner.plan.PlanNodeId)7 ConstantExpression (com.facebook.presto.sql.relational.ConstantExpression)7 BlockBuilder (com.facebook.presto.spi.block.BlockBuilder)6