Search in sources :

Example 66 with CallExpression

use of io.prestosql.spi.relation.CallExpression in project hetu-core by openlookeng.

the class ClickHouseRowExpressionConverter method handleOperatorFunction.

private String handleOperatorFunction(CallExpression call, FunctionMetadata functionMetadata, JdbcConverterContext context) {
    Optional<OperatorType> operatorTypeOptional = functionMetadata.getOperatorType();
    OperatorType type = operatorTypeOptional.get();
    if (type.equals(OperatorType.CAST)) {
        return handleCastOperator(call.getArguments().get(0), call.getType(), context);
    }
    List<String> argumentList = call.getArguments().stream().map(expr -> expr.accept(this, context)).collect(Collectors.toList());
    if (type.isArithmeticOperator()) {
        return format("(%s %s %s)", argumentList.get(0), type.getOperator(), argumentList.get(1));
    }
    if (type.isComparisonOperator()) {
        final String[] clickHouseCompareOperators = new String[] { "=", ">", "<", ">=", "<=", "!=", "<>" };
        if (Arrays.asList(clickHouseCompareOperators).contains(type.getOperator())) {
            return format("(%s %s %s)", argumentList.get(0), type.getOperator(), argumentList.get(1));
        } else {
            String exceptionInfo = "ClickHouse Connector does not support comparison operator " + type.getOperator();
            throw new PrestoException(NOT_SUPPORTED, exceptionInfo);
        }
    }
    if (type.equals(OperatorType.SUBSCRIPT)) {
        throw new PrestoException(NOT_SUPPORTED, "ClickHouse Connector does not support subscript now");
    }
    /*
         * "Negative" needs to be tested
         */
    if (call.getArguments().size() == 1 && type.equals(OperatorType.NEGATION)) {
        String value = argumentList.get(0);
        String separator = value.startsWith("-") ? " " : "";
        return format("-%s%s", separator, value);
    }
    throw new PrestoException(NOT_SUPPORTED, String.format("Unknown operator %s in push down", type.getOperator()));
}
Also used : FunctionWriterManager(io.prestosql.sql.builder.functioncall.FunctionWriterManager) Arrays(java.util.Arrays) ConstantExpression(io.prestosql.spi.relation.ConstantExpression) JdbcConverterContext(io.prestosql.plugin.jdbc.optimization.JdbcConverterContext) HashMap(java.util.HashMap) DateParseFunctionCallRewriter(io.hetu.core.plugin.clickhouse.rewrite.functioncall.DateParseFunctionCallRewriter) StandardFunctionResolution(io.prestosql.spi.function.StandardFunctionResolution) DeterminismEvaluator(io.prestosql.spi.relation.DeterminismEvaluator) BaseFunctionUtil.isDefaultFunction(io.prestosql.sql.builder.functioncall.BaseFunctionUtil.isDefaultFunction) CallExpression(io.prestosql.spi.relation.CallExpression) ClickHouseConstants(io.hetu.core.plugin.clickhouse.ClickHouseConstants) ConfigSupplier(io.prestosql.configmanager.ConfigSupplier) OperatorType(io.prestosql.spi.function.OperatorType) Map(java.util.Map) FunctionMetadataManager(io.prestosql.spi.function.FunctionMetadataManager) ImmutableSet.toImmutableSet(com.google.common.collect.ImmutableSet.toImmutableSet) FunctionMetadata(io.prestosql.spi.function.FunctionMetadata) UdfFunctionRewriteConstants(io.hetu.core.plugin.clickhouse.rewrite.UdfFunctionRewriteConstants) Type(io.prestosql.spi.type.Type) FromBase64CallRewriter(io.prestosql.sql.builder.functioncall.functions.base.FromBase64CallRewriter) SpecialForm(io.prestosql.spi.relation.SpecialForm) ENGLISH(java.util.Locale.ENGLISH) DefaultConnectorConfigFunctionRewriter(io.prestosql.sql.builder.functioncall.functions.config.DefaultConnectorConfigFunctionRewriter) PrestoException(io.prestosql.spi.PrestoException) BaseJdbcConfig(io.prestosql.plugin.jdbc.BaseJdbcConfig) Set(java.util.Set) FunctionCallRewriter(io.prestosql.sql.builder.functioncall.functions.FunctionCallRewriter) Collectors(java.util.stream.Collectors) String.format(java.lang.String.format) FunctionHandle(io.prestosql.spi.function.FunctionHandle) ClickHouseUnsupportedFunctionCallRewriter(io.hetu.core.plugin.clickhouse.rewrite.ClickHouseUnsupportedFunctionCallRewriter) RowExpressionService(io.prestosql.spi.relation.RowExpressionService) List(java.util.List) BaseJdbcRowExpressionConverter(io.prestosql.plugin.jdbc.optimization.BaseJdbcRowExpressionConverter) Stream(java.util.stream.Stream) FunctionWriterManagerGroup(io.prestosql.sql.builder.functioncall.FunctionWriterManagerGroup) QualifiedName(io.prestosql.spi.sql.expression.QualifiedName) RowExpression(io.prestosql.spi.relation.RowExpression) Optional(java.util.Optional) NOT_SUPPORTED(io.prestosql.spi.StandardErrorCode.NOT_SUPPORTED) DefaultUdfRewriteConfigSupplier(io.prestosql.configmanager.DefaultUdfRewriteConfigSupplier) BuildInDirectMapFunctionCallRewriter(io.hetu.core.plugin.clickhouse.rewrite.BuildInDirectMapFunctionCallRewriter) ClickHouseConfig(io.hetu.core.plugin.clickhouse.ClickHouseConfig) Collections(java.util.Collections) VarcharType(io.prestosql.spi.type.VarcharType) Joiner(com.google.common.base.Joiner) PrestoException(io.prestosql.spi.PrestoException) OperatorType(io.prestosql.spi.function.OperatorType)

Example 67 with CallExpression

use of io.prestosql.spi.relation.CallExpression in project hetu-core by openlookeng.

the class CubeOptimizer method rewriteAggregationNode.

private PlanNode rewriteAggregationNode(CubeRewriteResult cubeRewriteResult, PlanNode inputPlanNode) {
    TypeProvider typeProvider = context.getSymbolAllocator().getTypes();
    // Add group by
    List<Symbol> groupings = aggregationNode.getGroupingKeys().stream().map(Symbol::getName).map(columnRewritesMap::get).map(optimizedPlanMappings::get).collect(Collectors.toList());
    Map<Symbol, Symbol> cubeScanToAggOutputMap = new HashMap<>();
    // Rewrite AggregationNode using Cube table
    ImmutableMap.Builder<Symbol, AggregationNode.Aggregation> aggregationsBuilder = ImmutableMap.builder();
    for (CubeRewriteResult.AggregatorSource aggregatorSource : cubeRewriteResult.getAggregationColumns()) {
        Type type = cubeRewriteResult.getSymbolMetadataMap().get(aggregatorSource.getOriginalAggSymbol()).getType();
        TypeSignature typeSignature = type.getTypeSignature();
        ColumnHandle cubeColHandle = cubeRewriteResult.getTableScanNode().getAssignments().get(aggregatorSource.getScanSymbol());
        ColumnMetadata cubeColumnMetadata = metadata.getColumnMetadata(context.getSession(), cubeTableHandle, cubeColHandle);
        AggregationSignature aggregationSignature = cubeMetadata.getAggregationSignature(cubeColumnMetadata.getName()).orElseThrow(() -> new ColumnNotFoundException(new SchemaTableName("", ""), cubeColHandle.getColumnName()));
        String aggFunction = COUNT.getName().equals(aggregationSignature.getFunction()) ? SUM.getName() : aggregationSignature.getFunction();
        SymbolReference argument = toSymbolReference(aggregatorSource.getScanSymbol());
        FunctionHandle functionHandle = metadata.getFunctionAndTypeManager().lookupFunction(aggFunction, TypeSignatureProvider.fromTypeSignatures(typeSignature));
        cubeScanToAggOutputMap.put(aggregatorSource.getScanSymbol(), aggregatorSource.getOriginalAggSymbol());
        aggregationsBuilder.put(aggregatorSource.getOriginalAggSymbol(), new AggregationNode.Aggregation(new CallExpression(aggFunction, functionHandle, type, ImmutableList.of(castToRowExpression(argument))), ImmutableList.of(castToRowExpression(argument)), false, Optional.empty(), Optional.empty(), Optional.empty()));
    }
    PlanNode planNode = inputPlanNode;
    AggregationNode aggNode = new AggregationNode(context.getIdAllocator().getNextId(), planNode, aggregationsBuilder.build(), singleGroupingSet(groupings), ImmutableList.of(), AggregationNode.Step.SINGLE, Optional.empty(), Optional.empty(), AggregationNode.AggregationType.HASH, Optional.empty());
    if (cubeRewriteResult.getAvgAggregationColumns().isEmpty()) {
        return aggNode;
    }
    if (!cubeRewriteResult.getComputeAvgDividingSumByCount()) {
        Map<Symbol, Expression> aggregateAssignments = new HashMap<>();
        for (CubeRewriteResult.AggregatorSource aggregatorSource : cubeRewriteResult.getAggregationColumns()) {
            aggregateAssignments.put(aggregatorSource.getOriginalAggSymbol(), toSymbolReference(aggregatorSource.getScanSymbol()));
        }
        planNode = new ProjectNode(context.getIdAllocator().getNextId(), aggNode, new Assignments(aggregateAssignments.entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, entry -> castToRowExpression(entry.getValue())))));
    } else {
        // If there was an AVG aggregation, map it to AVG = SUM/COUNT
        Map<Symbol, Expression> projections = new HashMap<>();
        aggNode.getGroupingKeys().forEach(symbol -> projections.put(symbol, toSymbolReference(symbol)));
        aggNode.getAggregations().keySet().stream().filter(originalAggregationsMap::containsValue).forEach(aggSymbol -> projections.put(aggSymbol, toSymbolReference(aggSymbol)));
        // Add AVG = SUM / COUNT
        for (CubeRewriteResult.AverageAggregatorSource avgAggSource : cubeRewriteResult.getAvgAggregationColumns()) {
            Symbol sumSymbol = cubeScanToAggOutputMap.get(avgAggSource.getSum());
            Symbol countSymbol = cubeScanToAggOutputMap.get(avgAggSource.getCount());
            Type avgResultType = typeProvider.get(avgAggSource.getOriginalAggSymbol());
            ArithmeticBinaryExpression division = new ArithmeticBinaryExpression(ArithmeticBinaryExpression.Operator.DIVIDE, new Cast(toSymbolReference(sumSymbol), avgResultType.getTypeSignature().toString()), new Cast(toSymbolReference(countSymbol), avgResultType.getTypeSignature().toString()));
            projections.put(avgAggSource.getOriginalAggSymbol(), division);
        }
        return new ProjectNode(context.getIdAllocator().getNextId(), aggNode, new Assignments(projections.entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, entry -> castToRowExpression(entry.getValue())))));
    }
    return planNode;
}
Also used : ArithmeticBinaryExpression(io.prestosql.sql.tree.ArithmeticBinaryExpression) Cast(io.prestosql.sql.tree.Cast) LongSupplier(java.util.function.LongSupplier) ConstantExpression(io.prestosql.spi.relation.ConstantExpression) PrestoWarning(io.prestosql.spi.PrestoWarning) TypeProvider(io.prestosql.sql.planner.TypeProvider) SqlParser(io.prestosql.sql.parser.SqlParser) ColumnNotFoundException(io.prestosql.spi.connector.ColumnNotFoundException) AggregationNode(io.prestosql.spi.plan.AggregationNode) CallExpression(io.prestosql.spi.relation.CallExpression) Cast(io.prestosql.sql.tree.Cast) FilterNode(io.prestosql.spi.plan.FilterNode) Pair(org.apache.commons.lang3.tuple.Pair) Map(java.util.Map) OriginalExpressionUtils.castToRowExpression(io.prestosql.sql.relational.OriginalExpressionUtils.castToRowExpression) Type(io.prestosql.spi.type.Type) OriginalExpressionUtils.castToExpression(io.prestosql.sql.relational.OriginalExpressionUtils.castToExpression) CubeFilter(io.hetu.core.spi.cube.CubeFilter) ENGLISH(java.util.Locale.ENGLISH) Identifier(io.prestosql.sql.tree.Identifier) AggregationNode.singleGroupingSet(io.prestosql.spi.plan.AggregationNode.singleGroupingSet) CubeMetaStore(io.hetu.core.spi.cube.io.CubeMetaStore) PrestoException(io.prestosql.spi.PrestoException) SymbolsExtractor(io.prestosql.sql.planner.SymbolsExtractor) SUM(io.hetu.core.spi.cube.CubeAggregateFunction.SUM) ImmutableMap(com.google.common.collect.ImmutableMap) CubeAggregateFunction(io.hetu.core.spi.cube.CubeAggregateFunction) TableScanNode(io.prestosql.spi.plan.TableScanNode) Set(java.util.Set) PlanNode(io.prestosql.spi.plan.PlanNode) UUID(java.util.UUID) ProjectNode(io.prestosql.spi.plan.ProjectNode) Collectors(java.util.stream.Collectors) Metadata(io.prestosql.metadata.Metadata) String.format(java.lang.String.format) FunctionHandle(io.prestosql.spi.function.FunctionHandle) Objects(java.util.Objects) SymbolUtils.toSymbolReference(io.prestosql.sql.planner.SymbolUtils.toSymbolReference) ReuseExchangeOperator(io.prestosql.spi.operator.ReuseExchangeOperator) List(java.util.List) ExpressionUtils(io.prestosql.sql.ExpressionUtils) LongLiteral(io.prestosql.sql.tree.LongLiteral) SymbolReference(io.prestosql.sql.tree.SymbolReference) AggregationSignature(io.hetu.core.spi.cube.aggregator.AggregationSignature) Optional(java.util.Optional) NOT_SUPPORTED(io.prestosql.spi.StandardErrorCode.NOT_SUPPORTED) TypeSignature(io.prestosql.spi.type.TypeSignature) OriginalExpressionUtils(io.prestosql.sql.relational.OriginalExpressionUtils) Iterables(com.google.common.collect.Iterables) COUNT(io.hetu.core.spi.cube.CubeAggregateFunction.COUNT) TableMetadata(io.prestosql.metadata.TableMetadata) Logger(io.airlift.log.Logger) TypeSignatureProvider(io.prestosql.sql.analyzer.TypeSignatureProvider) Literal(io.prestosql.sql.tree.Literal) HashMap(java.util.HashMap) TableHandle(io.prestosql.spi.metadata.TableHandle) ExpressionTreeRewriter(io.prestosql.sql.tree.ExpressionTreeRewriter) QualifiedObjectName(io.prestosql.spi.connector.QualifiedObjectName) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) SchemaTableName(io.prestosql.spi.connector.SchemaTableName) Lists(com.google.common.collect.Lists) ArithmeticBinaryExpression(io.prestosql.sql.tree.ArithmeticBinaryExpression) ImmutableList(com.google.common.collect.ImmutableList) ExpressionDomainTranslator(io.prestosql.sql.planner.ExpressionDomainTranslator) BooleanLiteral(io.prestosql.sql.tree.BooleanLiteral) Objects.requireNonNull(java.util.Objects.requireNonNull) Session(io.prestosql.Session) RowExpressionRewriter(io.prestosql.expressions.RowExpressionRewriter) RowExpressionTreeRewriter(io.prestosql.expressions.RowExpressionTreeRewriter) ExpressionRewriter(io.prestosql.sql.tree.ExpressionRewriter) JoinNode(io.prestosql.spi.plan.JoinNode) ParsingOptions(io.prestosql.sql.parser.ParsingOptions) Symbol(io.prestosql.spi.plan.Symbol) AssignmentUtils(io.prestosql.sql.planner.plan.AssignmentUtils) EXPIRED_CUBE(io.prestosql.spi.connector.StandardWarningCode.EXPIRED_CUBE) Assignments(io.prestosql.spi.plan.Assignments) Rule(io.prestosql.sql.planner.iterative.Rule) ColumnMetadata(io.prestosql.spi.connector.ColumnMetadata) TupleDomain(io.prestosql.spi.predicate.TupleDomain) ComparisonExpression(io.prestosql.sql.tree.ComparisonExpression) VariableReferenceExpression(io.prestosql.spi.relation.VariableReferenceExpression) SymbolAllocator(io.prestosql.spi.SymbolAllocator) ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair) ColumnHandle(io.prestosql.spi.connector.ColumnHandle) CUBE_ERROR(io.prestosql.spi.StandardErrorCode.CUBE_ERROR) RowExpression(io.prestosql.spi.relation.RowExpression) CubeMetadata(io.hetu.core.spi.cube.CubeMetadata) Comparator(java.util.Comparator) Expression(io.prestosql.sql.tree.Expression) ColumnMetadata(io.prestosql.spi.connector.ColumnMetadata) HashMap(java.util.HashMap) Symbol(io.prestosql.spi.plan.Symbol) SymbolUtils.toSymbolReference(io.prestosql.sql.planner.SymbolUtils.toSymbolReference) SymbolReference(io.prestosql.sql.tree.SymbolReference) Assignments(io.prestosql.spi.plan.Assignments) TypeSignature(io.prestosql.spi.type.TypeSignature) PlanNode(io.prestosql.spi.plan.PlanNode) FunctionHandle(io.prestosql.spi.function.FunctionHandle) CallExpression(io.prestosql.spi.relation.CallExpression) ColumnHandle(io.prestosql.spi.connector.ColumnHandle) TypeProvider(io.prestosql.sql.planner.TypeProvider) AggregationSignature(io.hetu.core.spi.cube.aggregator.AggregationSignature) AggregationNode(io.prestosql.spi.plan.AggregationNode) SchemaTableName(io.prestosql.spi.connector.SchemaTableName) ImmutableMap(com.google.common.collect.ImmutableMap) Type(io.prestosql.spi.type.Type) ColumnNotFoundException(io.prestosql.spi.connector.ColumnNotFoundException) ConstantExpression(io.prestosql.spi.relation.ConstantExpression) CallExpression(io.prestosql.spi.relation.CallExpression) OriginalExpressionUtils.castToRowExpression(io.prestosql.sql.relational.OriginalExpressionUtils.castToRowExpression) OriginalExpressionUtils.castToExpression(io.prestosql.sql.relational.OriginalExpressionUtils.castToExpression) ArithmeticBinaryExpression(io.prestosql.sql.tree.ArithmeticBinaryExpression) ComparisonExpression(io.prestosql.sql.tree.ComparisonExpression) VariableReferenceExpression(io.prestosql.spi.relation.VariableReferenceExpression) RowExpression(io.prestosql.spi.relation.RowExpression) Expression(io.prestosql.sql.tree.Expression) ProjectNode(io.prestosql.spi.plan.ProjectNode) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap)

Example 68 with CallExpression

use of io.prestosql.spi.relation.CallExpression in project hetu-core by openlookeng.

the class CubeOptimizerUtil method extractMappedValue.

private static Optional<Object> extractMappedValue(Symbol symbol, ProjectNode projectNode) {
    Map<Symbol, RowExpression> assignments = projectNode.getAssignments().getMap();
    RowExpression rowExpression = assignments.get(symbol);
    if (rowExpression == null) {
        return Optional.empty();
    }
    if (OriginalExpressionUtils.isExpression(rowExpression)) {
        Expression expression = castToExpression(rowExpression);
        if (expression instanceof Cast) {
            expression = ((Cast) expression).getExpression();
        }
        if (expression instanceof SymbolReference) {
            return Optional.of(((SymbolReference) expression).getName());
        } else if (expression instanceof Literal) {
            return Optional.of(expression);
        }
    } else {
        if (rowExpression instanceof CallExpression) {
            // Extract the column symbols from CAST expressions
            while (rowExpression instanceof CallExpression) {
                rowExpression = ((CallExpression) rowExpression).getArguments().get(0);
            }
        }
        if (!(rowExpression instanceof VariableReferenceExpression)) {
            return Optional.empty();
        }
        return Optional.of(((VariableReferenceExpression) rowExpression).getName());
    }
    return Optional.empty();
}
Also used : Cast(io.prestosql.sql.tree.Cast) CallExpression(io.prestosql.spi.relation.CallExpression) OriginalExpressionUtils.castToExpression(io.prestosql.sql.relational.OriginalExpressionUtils.castToExpression) VariableReferenceExpression(io.prestosql.spi.relation.VariableReferenceExpression) RowExpression(io.prestosql.spi.relation.RowExpression) Expression(io.prestosql.sql.tree.Expression) Symbol(io.prestosql.spi.plan.Symbol) SymbolReference(io.prestosql.sql.tree.SymbolReference) VariableReferenceExpression(io.prestosql.spi.relation.VariableReferenceExpression) Literal(io.prestosql.sql.tree.Literal) RowExpression(io.prestosql.spi.relation.RowExpression) CallExpression(io.prestosql.spi.relation.CallExpression)

Example 69 with CallExpression

use of io.prestosql.spi.relation.CallExpression in project hetu-core by openlookeng.

the class TestPageProcessorCompiler method testSanityFilterOnRLE.

@Test
public void testSanityFilterOnRLE() {
    Signature lessThan = internalOperator(LESS_THAN, BOOLEAN, ImmutableList.of(BIGINT, BIGINT));
    CallExpression filter = new CallExpression(lessThan.getName().getObjectName(), new BuiltInFunctionHandle(lessThan), BOOLEAN, ImmutableList.of(field(0, BIGINT), constant(10L, BIGINT)), Optional.empty());
    PageProcessor processor = compiler.compilePageProcessor(Optional.of(filter), ImmutableList.of(field(0, BIGINT)), MAX_BATCH_SIZE).get();
    Page page = new Page(createRLEBlock(5L, 100));
    Page outputPage = getOnlyElement(processor.process(null, new DriverYieldSignal(), newSimpleAggregatedMemoryContext().newLocalMemoryContext(PageProcessor.class.getSimpleName()), page)).orElseThrow(() -> new AssertionError("page is not present"));
    assertEquals(outputPage.getPositionCount(), 100);
    assertTrue(outputPage.getBlock(0) instanceof RunLengthEncodedBlock);
    RunLengthEncodedBlock rle = (RunLengthEncodedBlock) outputPage.getBlock(0);
    assertEquals(BIGINT.getLong(rle.getValue(), 0), 5L);
}
Also used : PageProcessor(io.prestosql.operator.project.PageProcessor) TypeSignature.parseTypeSignature(io.prestosql.spi.type.TypeSignature.parseTypeSignature) Signature(io.prestosql.spi.function.Signature) DriverYieldSignal(io.prestosql.operator.DriverYieldSignal) BuiltInFunctionHandle(io.prestosql.spi.function.BuiltInFunctionHandle) Page(io.prestosql.spi.Page) RunLengthEncodedBlock(io.prestosql.spi.block.RunLengthEncodedBlock) CallExpression(io.prestosql.spi.relation.CallExpression) Test(org.testng.annotations.Test)

Example 70 with CallExpression

use of io.prestosql.spi.relation.CallExpression in project hetu-core by openlookeng.

the class TestPageProcessorCompiler method testSanityFilterOnDictionary.

@Test
public void testSanityFilterOnDictionary() {
    CallExpression lengthVarchar = new CallExpression(QualifiedObjectName.valueOfDefaultFunction("length").getObjectName(), new BuiltInFunctionHandle(new Signature(QualifiedObjectName.valueOfDefaultFunction("length"), SCALAR, parseTypeSignature(StandardTypes.BIGINT), parseTypeSignature(StandardTypes.VARCHAR))), BIGINT, ImmutableList.of(field(0, VARCHAR)), Optional.empty());
    Signature lessThan = internalOperator(LESS_THAN, BOOLEAN, ImmutableList.of(BIGINT, BIGINT));
    CallExpression filter = new CallExpression(lessThan.getName().getObjectName(), new BuiltInFunctionHandle(lessThan), BOOLEAN, ImmutableList.of(lengthVarchar, constant(10L, BIGINT)), Optional.empty());
    PageProcessor processor = compiler.compilePageProcessor(Optional.of(filter), ImmutableList.of(field(0, VARCHAR)), MAX_BATCH_SIZE).get();
    Page page = new Page(createDictionaryBlock(createExpectedValues(10), 100));
    Page outputPage = getOnlyElement(processor.process(null, new DriverYieldSignal(), newSimpleAggregatedMemoryContext().newLocalMemoryContext(PageProcessor.class.getSimpleName()), page)).orElseThrow(() -> new AssertionError("page is not present"));
    assertEquals(outputPage.getPositionCount(), 100);
    assertTrue(outputPage.getBlock(0) instanceof DictionaryBlock);
    DictionaryBlock dictionaryBlock = (DictionaryBlock) outputPage.getBlock(0);
    assertEquals(dictionaryBlock.getDictionary().getPositionCount(), 10);
    // test filter caching
    Page outputPage2 = getOnlyElement(processor.process(null, new DriverYieldSignal(), newSimpleAggregatedMemoryContext().newLocalMemoryContext(PageProcessor.class.getSimpleName()), page)).orElseThrow(() -> new AssertionError("page is not present"));
    assertEquals(outputPage2.getPositionCount(), 100);
    assertTrue(outputPage2.getBlock(0) instanceof DictionaryBlock);
    DictionaryBlock dictionaryBlock2 = (DictionaryBlock) outputPage2.getBlock(0);
    // both output pages must have the same dictionary
    assertEquals(dictionaryBlock2.getDictionary(), dictionaryBlock.getDictionary());
}
Also used : PageProcessor(io.prestosql.operator.project.PageProcessor) TypeSignature.parseTypeSignature(io.prestosql.spi.type.TypeSignature.parseTypeSignature) Signature(io.prestosql.spi.function.Signature) DictionaryBlock(io.prestosql.spi.block.DictionaryBlock) BlockAssertions.createLongDictionaryBlock(io.prestosql.block.BlockAssertions.createLongDictionaryBlock) DriverYieldSignal(io.prestosql.operator.DriverYieldSignal) BuiltInFunctionHandle(io.prestosql.spi.function.BuiltInFunctionHandle) Page(io.prestosql.spi.Page) CallExpression(io.prestosql.spi.relation.CallExpression) Test(org.testng.annotations.Test)

Aggregations

CallExpression (io.prestosql.spi.relation.CallExpression)96 RowExpression (io.prestosql.spi.relation.RowExpression)51 BuiltInFunctionHandle (io.prestosql.spi.function.BuiltInFunctionHandle)45 Signature (io.prestosql.spi.function.Signature)36 VariableReferenceExpression (io.prestosql.spi.relation.VariableReferenceExpression)29 Test (org.testng.annotations.Test)28 Symbol (io.prestosql.spi.plan.Symbol)27 Type (io.prestosql.spi.type.Type)25 FunctionHandle (io.prestosql.spi.function.FunctionHandle)24 TypeSignature (io.prestosql.spi.type.TypeSignature)24 ArrayList (java.util.ArrayList)23 ConstantExpression (io.prestosql.spi.relation.ConstantExpression)22 AggregationNode (io.prestosql.spi.plan.AggregationNode)20 Map (java.util.Map)20 ImmutableMap (com.google.common.collect.ImmutableMap)17 OperatorType (io.prestosql.spi.function.OperatorType)17 SpecialForm (io.prestosql.spi.relation.SpecialForm)15 Optional (java.util.Optional)15 List (java.util.List)14 ImmutableList (com.google.common.collect.ImmutableList)13