Search code examples
prestotrino

What's the function of DynamicFilters in PrestoSql DistributedExecutionPlanner.Visitor?


What's the function of DynamicFilters in PrestoSql DistributedExecutionPlanner.Visitor?

private Map<PlanNodeId, SplitSource> visitScanAndFilter(TableScanNode node, Optional<FilterNode> filter)
    {
        // ***What's the purpose of dynamicFilters and how to use it?***
        List<DynamicFilters.Descriptor> dynamicFilters = filter
                .map(FilterNode::getPredicate)
                .map(expression -> extractDynamicFilters(metadata, expression))
                .map(DynamicFilters.ExtractResult::getDynamicConjuncts)
                .orElse(ImmutableList.of());

        // TODO: Execution must be plugged in here 
        if (!dynamicFilters.isEmpty()) {
            log.debug("Dynamic filters: %s", dynamicFilters);
        }

        // get dataSource for table
        SplitSource splitSource = splitManager.getSplits(
                session,
                node.getTable(),
                stageExecutionDescriptor.isScanGroupedExecution(node.getId()) ? GROUPED_SCHEDULING : UNGROUPED_SCHEDULING);

        splitSources.add(splitSource);

        return ImmutableMap.of(node.getId(), splitSource);
    }

Solution

  • As Martin suggested, https://trino.io/blog/2019/06/30/dynamic-filtering.html describes the meaning of dynamic filters.

    The TODOs in the code are there because not every part of this functionality is implemented yet. You can track https://github.com/trino/presto/issues/52