Search in sources :

Example 1 with FeaturesConfig

use of com.facebook.presto.sql.analyzer.FeaturesConfig in project presto by prestodb.

the class TestFunctionRegistry method testIdentityCast.

@Test
public void testIdentityCast() {
    TypeRegistry typeManager = new TypeRegistry();
    FunctionRegistry registry = new FunctionRegistry(typeManager, new BlockEncodingManager(typeManager), new FeaturesConfig());
    Signature exactOperator = registry.getCoercion(HYPER_LOG_LOG, HYPER_LOG_LOG);
    assertEquals(exactOperator.getName(), mangleOperatorName(OperatorType.CAST.name()));
    assertEquals(transform(exactOperator.getArgumentTypes(), Functions.toStringFunction()), ImmutableList.of(StandardTypes.HYPER_LOG_LOG));
    assertEquals(exactOperator.getReturnType().getBase(), StandardTypes.HYPER_LOG_LOG);
}
Also used : BlockEncodingManager(com.facebook.presto.block.BlockEncodingManager) FeaturesConfig(com.facebook.presto.sql.analyzer.FeaturesConfig) TypeSignature(com.facebook.presto.spi.type.TypeSignature) FunctionRegistry.getMagicLiteralFunctionSignature(com.facebook.presto.metadata.FunctionRegistry.getMagicLiteralFunctionSignature) TypeSignature.parseTypeSignature(com.facebook.presto.spi.type.TypeSignature.parseTypeSignature) TypeRegistry(com.facebook.presto.type.TypeRegistry) Test(org.testng.annotations.Test)

Example 2 with FeaturesConfig

use of com.facebook.presto.sql.analyzer.FeaturesConfig in project presto by prestodb.

the class TestFunctionRegistry method testConflictingScalarAggregation.

@Test(expectedExceptions = IllegalStateException.class, expectedExceptionsMessageRegExp = "'sum' is both an aggregation and a scalar function")
public void testConflictingScalarAggregation() throws Exception {
    List<SqlFunction> functions = new FunctionListBuilder().scalars(ScalarSum.class).getFunctions();
    TypeRegistry typeManager = new TypeRegistry();
    FunctionRegistry registry = new FunctionRegistry(typeManager, new BlockEncodingManager(typeManager), new FeaturesConfig());
    registry.addFunctions(functions);
}
Also used : BlockEncodingManager(com.facebook.presto.block.BlockEncodingManager) FeaturesConfig(com.facebook.presto.sql.analyzer.FeaturesConfig) TypeRegistry(com.facebook.presto.type.TypeRegistry) Test(org.testng.annotations.Test)

Example 3 with FeaturesConfig

use of com.facebook.presto.sql.analyzer.FeaturesConfig in project presto by prestodb.

the class TestFunctionRegistry method testExactMatchBeforeCoercion.

@Test
public void testExactMatchBeforeCoercion() {
    TypeRegistry typeManager = new TypeRegistry();
    FunctionRegistry registry = new FunctionRegistry(typeManager, new BlockEncodingManager(typeManager), new FeaturesConfig());
    boolean foundOperator = false;
    for (SqlFunction function : registry.listOperators()) {
        OperatorType operatorType = unmangleOperator(function.getSignature().getName());
        if (operatorType == OperatorType.CAST || operatorType == OperatorType.SATURATED_FLOOR_CAST) {
            continue;
        }
        if (!function.getSignature().getTypeVariableConstraints().isEmpty()) {
            continue;
        }
        if (function.getSignature().getArgumentTypes().stream().anyMatch(TypeSignature::isCalculated)) {
            continue;
        }
        Signature exactOperator = registry.resolveOperator(operatorType, resolveTypes(function.getSignature().getArgumentTypes(), typeManager));
        assertEquals(exactOperator, function.getSignature());
        foundOperator = true;
    }
    assertTrue(foundOperator);
}
Also used : TypeSignature(com.facebook.presto.spi.type.TypeSignature) TypeSignature.parseTypeSignature(com.facebook.presto.spi.type.TypeSignature.parseTypeSignature) BlockEncodingManager(com.facebook.presto.block.BlockEncodingManager) FeaturesConfig(com.facebook.presto.sql.analyzer.FeaturesConfig) TypeSignature(com.facebook.presto.spi.type.TypeSignature) FunctionRegistry.getMagicLiteralFunctionSignature(com.facebook.presto.metadata.FunctionRegistry.getMagicLiteralFunctionSignature) TypeSignature.parseTypeSignature(com.facebook.presto.spi.type.TypeSignature.parseTypeSignature) TypeRegistry(com.facebook.presto.type.TypeRegistry) OperatorType(com.facebook.presto.spi.function.OperatorType) Test(org.testng.annotations.Test)

Example 4 with FeaturesConfig

use of com.facebook.presto.sql.analyzer.FeaturesConfig in project presto by prestodb.

the class TestQuerySpillLimits method createLocalQueryRunner.

private LocalQueryRunner createLocalQueryRunner(NodeSpillConfig nodeSpillConfig) {
    LocalQueryRunner queryRunner = new LocalQueryRunner(SESSION, new FeaturesConfig().setSpillerSpillPaths(spillPath.getAbsolutePath()).setSpillEnabled(true), nodeSpillConfig, false, true);
    queryRunner.createCatalog(SESSION.getCatalog().get(), new TpchConnectorFactory(1), ImmutableMap.of());
    return queryRunner;
}
Also used : TpchConnectorFactory(com.facebook.presto.tpch.TpchConnectorFactory) FeaturesConfig(com.facebook.presto.sql.analyzer.FeaturesConfig) LocalQueryRunner(com.facebook.presto.testing.LocalQueryRunner)

Example 5 with FeaturesConfig

use of com.facebook.presto.sql.analyzer.FeaturesConfig in project presto by prestodb.

the class TestJoinCompiler method testMultiChannel.

@Test(dataProvider = "hashEnabledValues")
public void testMultiChannel(boolean hashEnabled) {
    // compile a single channel hash strategy
    JoinCompiler joinCompiler = new JoinCompiler(MetadataManager.createTestMetadataManager(), new FeaturesConfig());
    List<Type> types = ImmutableList.of(VARCHAR, VARCHAR, BIGINT, DOUBLE, BOOLEAN, VARCHAR);
    List<Type> joinTypes = ImmutableList.of(VARCHAR, BIGINT, DOUBLE, BOOLEAN);
    List<Type> outputTypes = ImmutableList.of(VARCHAR, BIGINT, DOUBLE, BOOLEAN, VARCHAR);
    List<Integer> joinChannels = Ints.asList(1, 2, 3, 4);
    List<Integer> outputChannels = Ints.asList(1, 2, 3, 4, 0);
    // crate hash strategy with a single channel blocks -- make sure there is some overlap in values
    List<Block> extraChannel = ImmutableList.of(BlockAssertions.createStringSequenceBlock(10, 20), BlockAssertions.createStringSequenceBlock(20, 30), BlockAssertions.createStringSequenceBlock(15, 25));
    List<Block> varcharChannel = ImmutableList.of(BlockAssertions.createStringSequenceBlock(10, 20), BlockAssertions.createStringSequenceBlock(20, 30), BlockAssertions.createStringSequenceBlock(15, 25));
    List<Block> longChannel = ImmutableList.of(BlockAssertions.createLongSequenceBlock(10, 20), BlockAssertions.createLongSequenceBlock(20, 30), BlockAssertions.createLongSequenceBlock(15, 25));
    List<Block> doubleChannel = ImmutableList.of(BlockAssertions.createDoubleSequenceBlock(10, 20), BlockAssertions.createDoubleSequenceBlock(20, 30), BlockAssertions.createDoubleSequenceBlock(15, 25));
    List<Block> booleanChannel = ImmutableList.of(BlockAssertions.createBooleanSequenceBlock(10, 20), BlockAssertions.createBooleanSequenceBlock(20, 30), BlockAssertions.createBooleanSequenceBlock(15, 25));
    List<Block> extraUnusedChannel = ImmutableList.of(BlockAssertions.createBooleanSequenceBlock(10, 20), BlockAssertions.createBooleanSequenceBlock(20, 30), BlockAssertions.createBooleanSequenceBlock(15, 25));
    OptionalInt hashChannel = OptionalInt.empty();
    ImmutableList<List<Block>> channels = ImmutableList.of(extraChannel, varcharChannel, longChannel, doubleChannel, booleanChannel, extraUnusedChannel);
    List<Block> precomputedHash = ImmutableList.of();
    if (hashEnabled) {
        ImmutableList.Builder<Block> hashChannelBuilder = ImmutableList.builder();
        for (int i = 0; i < 3; i++) {
            hashChannelBuilder.add(TypeUtils.getHashBlock(joinTypes, varcharChannel.get(i), longChannel.get(i), doubleChannel.get(i), booleanChannel.get(i)));
        }
        hashChannel = OptionalInt.of(6);
        precomputedHash = hashChannelBuilder.build();
        channels = ImmutableList.of(extraChannel, varcharChannel, longChannel, doubleChannel, booleanChannel, extraUnusedChannel, precomputedHash);
        types = ImmutableList.of(VARCHAR, VARCHAR, BIGINT, DOUBLE, BOOLEAN, VARCHAR, BIGINT);
        outputTypes = ImmutableList.of(VARCHAR, BIGINT, DOUBLE, BOOLEAN, VARCHAR, BIGINT);
        outputChannels = Ints.asList(1, 2, 3, 4, 0, 6);
    }
    PagesHashStrategyFactory pagesHashStrategyFactory = joinCompiler.compilePagesHashStrategyFactory(types, joinChannels, Optional.of(outputChannels));
    PagesHashStrategy hashStrategy = pagesHashStrategyFactory.createPagesHashStrategy(channels, hashChannel);
    // todo add tests for filter function
    PagesHashStrategy expectedHashStrategy = new SimplePagesHashStrategy(types, outputChannels, channels, joinChannels, hashChannel, Optional.empty(), FUNCTION_MANAGER, groupByUsesEqualTo);
    // verify channel count
    assertEquals(hashStrategy.getChannelCount(), outputChannels.size());
    // verify size
    int instanceSize = ClassLayout.parseClass(hashStrategy.getClass()).instanceSize();
    long sizeInBytes = instanceSize + channels.stream().flatMap(List::stream).mapToLong(Block::getRetainedSizeInBytes).sum();
    assertEquals(hashStrategy.getSizeInBytes(), sizeInBytes);
    // verify hashStrategy is consistent with equals and hash code from block
    for (int leftBlockIndex = 0; leftBlockIndex < varcharChannel.size(); leftBlockIndex++) {
        PageBuilder pageBuilder = new PageBuilder(outputTypes);
        Block[] leftBlocks = new Block[4];
        leftBlocks[0] = varcharChannel.get(leftBlockIndex);
        leftBlocks[1] = longChannel.get(leftBlockIndex);
        leftBlocks[2] = doubleChannel.get(leftBlockIndex);
        leftBlocks[3] = booleanChannel.get(leftBlockIndex);
        int leftPositionCount = varcharChannel.get(leftBlockIndex).getPositionCount();
        for (int leftBlockPosition = 0; leftBlockPosition < leftPositionCount; leftBlockPosition++) {
            // hash code of position must match block hash
            assertEquals(hashStrategy.hashPosition(leftBlockIndex, leftBlockPosition), expectedHashStrategy.hashPosition(leftBlockIndex, leftBlockPosition));
            // position must be equal to itself
            assertTrue(hashStrategy.positionEqualsPositionIgnoreNulls(leftBlockIndex, leftBlockPosition, leftBlockIndex, leftBlockPosition));
            assertTrue(hashStrategy.positionEqualsPosition(leftBlockIndex, leftBlockPosition, leftBlockIndex, leftBlockPosition));
            // check equality of every position against every other position in the block
            for (int rightBlockIndex = 0; rightBlockIndex < varcharChannel.size(); rightBlockIndex++) {
                Block rightBlock = varcharChannel.get(rightBlockIndex);
                for (int rightBlockPosition = 0; rightBlockPosition < rightBlock.getPositionCount(); rightBlockPosition++) {
                    assertEquals(hashStrategy.positionEqualsPositionIgnoreNulls(leftBlockIndex, leftBlockPosition, rightBlockIndex, rightBlockPosition), expectedHashStrategy.positionEqualsPositionIgnoreNulls(leftBlockIndex, leftBlockPosition, rightBlockIndex, rightBlockPosition));
                    assertEquals(hashStrategy.positionEqualsPosition(leftBlockIndex, leftBlockPosition, rightBlockIndex, rightBlockPosition), expectedHashStrategy.positionEqualsPosition(leftBlockIndex, leftBlockPosition, rightBlockIndex, rightBlockPosition));
                }
            }
            // check equality of every position against every other position in the block cursor
            for (int rightBlockIndex = 0; rightBlockIndex < varcharChannel.size(); rightBlockIndex++) {
                Block[] rightBlocks = new Block[4];
                rightBlocks[0] = varcharChannel.get(rightBlockIndex);
                rightBlocks[1] = longChannel.get(rightBlockIndex);
                rightBlocks[2] = doubleChannel.get(rightBlockIndex);
                rightBlocks[3] = booleanChannel.get(rightBlockIndex);
                int rightPositionCount = varcharChannel.get(rightBlockIndex).getPositionCount();
                for (int rightPosition = 0; rightPosition < rightPositionCount; rightPosition++) {
                    boolean expected = expectedHashStrategy.positionEqualsRow(leftBlockIndex, leftBlockPosition, rightPosition, new Page(rightBlocks));
                    assertEquals(hashStrategy.positionEqualsRow(leftBlockIndex, leftBlockPosition, rightPosition, new Page(rightBlocks)), expected);
                    assertEquals(hashStrategy.rowEqualsRow(leftBlockPosition, new Page(leftBlocks), rightPosition, new Page(rightBlocks)), expected);
                    assertEquals(hashStrategy.positionEqualsRowIgnoreNulls(leftBlockIndex, leftBlockPosition, rightPosition, new Page(rightBlocks)), expected);
                }
            }
            // write position to output block
            pageBuilder.declarePosition();
            hashStrategy.appendTo(leftBlockIndex, leftBlockPosition, pageBuilder, 0);
        }
        // verify output block matches
        Page page = pageBuilder.build();
        if (hashEnabled) {
            assertPageEquals(outputTypes, page, new Page(varcharChannel.get(leftBlockIndex), longChannel.get(leftBlockIndex), doubleChannel.get(leftBlockIndex), booleanChannel.get(leftBlockIndex), extraChannel.get(leftBlockIndex), precomputedHash.get(leftBlockIndex)));
        } else {
            assertPageEquals(outputTypes, page, new Page(varcharChannel.get(leftBlockIndex), longChannel.get(leftBlockIndex), doubleChannel.get(leftBlockIndex), booleanChannel.get(leftBlockIndex), extraChannel.get(leftBlockIndex)));
        }
    }
}
Also used : PagesHashStrategyFactory(com.facebook.presto.sql.gen.JoinCompiler.PagesHashStrategyFactory) FeaturesConfig(com.facebook.presto.sql.analyzer.FeaturesConfig) ImmutableList(com.google.common.collect.ImmutableList) Page(com.facebook.presto.common.Page) OptionalInt(java.util.OptionalInt) PageBuilder(com.facebook.presto.common.PageBuilder) SimplePagesHashStrategy(com.facebook.presto.operator.SimplePagesHashStrategy) Type(com.facebook.presto.common.type.Type) PagesHashStrategy(com.facebook.presto.operator.PagesHashStrategy) SimplePagesHashStrategy(com.facebook.presto.operator.SimplePagesHashStrategy) Block(com.facebook.presto.common.block.Block) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) Test(org.testng.annotations.Test)

Aggregations

FeaturesConfig (com.facebook.presto.sql.analyzer.FeaturesConfig)39 Test (org.testng.annotations.Test)20 JoinCompiler (com.facebook.presto.sql.gen.JoinCompiler)14 BlockEncodingManager (com.facebook.presto.block.BlockEncodingManager)10 PlanNodeId (com.facebook.presto.spi.plan.PlanNodeId)9 TypeRegistry (com.facebook.presto.type.TypeRegistry)9 Page (com.facebook.presto.common.Page)7 Type (com.facebook.presto.common.type.Type)7 SetBuilderOperatorFactory (com.facebook.presto.operator.SetBuilderOperator.SetBuilderOperatorFactory)6 RowPagesBuilder (com.facebook.presto.RowPagesBuilder)5 TypeSignature.parseTypeSignature (com.facebook.presto.spi.type.TypeSignature.parseTypeSignature)5 BlockEncodingManager (com.facebook.presto.common.block.BlockEncodingManager)4 CatalogManager (com.facebook.presto.metadata.CatalogManager)4 FunctionRegistry (com.facebook.presto.metadata.FunctionRegistry)4 FunctionRegistry.getMagicLiteralFunctionSignature (com.facebook.presto.metadata.FunctionRegistry.getMagicLiteralFunctionSignature)4 HashSemiJoinOperatorFactory (com.facebook.presto.operator.HashSemiJoinOperator.HashSemiJoinOperatorFactory)4 ImmutableList (com.google.common.collect.ImmutableList)4 List (java.util.List)4 BeforeClass (org.testng.annotations.BeforeClass)4 CounterStat (com.facebook.airlift.stats.CounterStat)3