All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.trino.sql.planner.plan.Patterns Maven / Gradle / Ivy

/*
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package io.trino.sql.planner.plan;

import io.trino.matching.Pattern;
import io.trino.matching.Property;
import io.trino.sql.ir.Expression;
import io.trino.sql.planner.Symbol;
import io.trino.sql.planner.iterative.Lookup;

import java.util.List;
import java.util.Optional;

import static com.google.common.collect.ImmutableList.toImmutableList;
import static com.google.common.collect.Iterables.getOnlyElement;
import static io.trino.matching.Pattern.typeOf;
import static io.trino.matching.Property.optionalProperty;
import static io.trino.matching.Property.property;
import static io.trino.sql.planner.plan.Patterns.Values.rowCount;

public final class Patterns
{
    private Patterns() {}

    public static Pattern assignUniqueId()
    {
        return typeOf(AssignUniqueId.class);
    }

    public static Pattern aggregation()
    {
        return typeOf(AggregationNode.class);
    }

    public static Pattern groupId()
    {
        return typeOf(GroupIdNode.class);
    }

    public static Pattern applyNode()
    {
        return typeOf(ApplyNode.class);
    }

    public static Pattern tableExecute()
    {
        return typeOf(TableExecuteNode.class);
    }

    public static Pattern mergeWriter()
    {
        return typeOf(MergeWriterNode.class);
    }

    public static Pattern mergeProcessor()
    {
        return typeOf(MergeProcessorNode.class);
    }

    public static Pattern exchange()
    {
        return typeOf(ExchangeNode.class);
    }

    public static Pattern explainAnalyze()
    {
        return typeOf(ExplainAnalyzeNode.class);
    }

    public static Pattern enforceSingleRow()
    {
        return typeOf(EnforceSingleRowNode.class);
    }

    public static Pattern filter()
    {
        return typeOf(FilterNode.class);
    }

    public static Pattern indexJoin()
    {
        return typeOf(IndexJoinNode.class);
    }

    public static Pattern indexSource()
    {
        return typeOf(IndexSourceNode.class);
    }

    public static Pattern join()
    {
        return typeOf(JoinNode.class);
    }

    public static Pattern dynamicFilterSource()
    {
        return typeOf(DynamicFilterSourceNode.class);
    }

    public static Pattern spatialJoin()
    {
        return typeOf(SpatialJoinNode.class);
    }

    public static Pattern correlatedJoin()
    {
        return typeOf(CorrelatedJoinNode.class);
    }

    public static Pattern offset()
    {
        return typeOf(OffsetNode.class);
    }

    public static Pattern limit()
    {
        return typeOf(LimitNode.class);
    }

    public static Pattern markDistinct()
    {
        return typeOf(MarkDistinctNode.class);
    }

    public static Pattern output()
    {
        return typeOf(OutputNode.class);
    }

    public static Pattern project()
    {
        return typeOf(ProjectNode.class);
    }

    public static Pattern sample()
    {
        return typeOf(SampleNode.class);
    }

    public static Pattern semiJoin()
    {
        return typeOf(SemiJoinNode.class);
    }

    public static Pattern sort()
    {
        return typeOf(SortNode.class);
    }

    public static Pattern tableFinish()
    {
        return typeOf(TableFinishNode.class);
    }

    public static Pattern tableScan()
    {
        return typeOf(TableScanNode.class);
    }

    public static Pattern tableWriterNode()
    {
        return typeOf(TableWriterNode.class);
    }

    public static Pattern topN()
    {
        return typeOf(TopNNode.class);
    }

    public static Pattern union()
    {
        return typeOf(UnionNode.class);
    }

    public static Pattern values()
    {
        return typeOf(ValuesNode.class);
    }

    public static Pattern emptyValues()
    {
        return values().with(rowCount().equalTo(0));
    }

    public static Pattern unnest()
    {
        return typeOf(UnnestNode.class);
    }

    public static Pattern window()
    {
        return typeOf(WindowNode.class);
    }

    public static Pattern patternRecognition()
    {
        return typeOf(PatternRecognitionNode.class);
    }

    public static Pattern tableFunction()
    {
        return typeOf(TableFunctionNode.class);
    }

    public static Pattern tableFunctionProcessor()
    {
        return typeOf(TableFunctionProcessorNode.class);
    }

    public static Pattern rowNumber()
    {
        return typeOf(RowNumberNode.class);
    }

    public static Pattern topNRanking()
    {
        return typeOf(TopNRankingNode.class);
    }

    public static Pattern distinctLimit()
    {
        return typeOf(DistinctLimitNode.class);
    }

    public static Pattern intersect()
    {
        return typeOf(IntersectNode.class);
    }

    public static Pattern except()
    {
        return typeOf(ExceptNode.class);
    }

    public static Pattern remoteSourceNode()
    {
        return typeOf(RemoteSourceNode.class);
    }

    public static Property source()
    {
        return optionalProperty(
                "source",
                (node, lookup) -> {
                    if (node.getSources().size() == 1) {
                        PlanNode source = getOnlyElement(node.getSources());
                        return Optional.of(lookup.resolve(source));
                    }
                    return Optional.empty();
                });
    }

    public static Property> sources()
    {
        return property(
                "sources",
                (PlanNode node, Lookup lookup) -> node.getSources().stream()
                        .map(lookup::resolve)
                        .collect(toImmutableList()));
    }

    public static final class Aggregation
    {
        public static Property> groupingColumns()
        {
            return property("groupingKeys", AggregationNode::getGroupingKeys);
        }

        public static Property step()
        {
            return property("step", AggregationNode::getStep);
        }
    }

    public static final class Apply
    {
        public static Property> correlation()
        {
            return property("correlation", ApplyNode::getCorrelation);
        }
    }

    public static final class DistinctLimit
    {
        public static Property isPartial()
        {
            return property("isPartial", DistinctLimitNode::isPartial);
        }
    }

    public static final class Exchange
    {
        public static Property scope()
        {
            return property("scope", ExchangeNode::getScope);
        }
    }

    public static final class Join
    {
        public static Property type()
        {
            return property("type", JoinNode::getType);
        }

        public static Property left()
        {
            return property("left", (JoinNode joinNode, Lookup lookup) -> lookup.resolve(joinNode.getLeft()));
        }

        public static Property right()
        {
            return property("right", (JoinNode joinNode, Lookup lookup) -> lookup.resolve(joinNode.getRight()));
        }
    }

    public static final class CorrelatedJoin
    {
        public static Property> correlation()
        {
            return property("correlation", CorrelatedJoinNode::getCorrelation);
        }

        public static Property subquery()
        {
            return property("subquery", (node, context) -> context.resolve(node.getSubquery()));
        }

        public static Property filter()
        {
            return property("filter", CorrelatedJoinNode::getFilter);
        }

        public static Property type()
        {
            return property("type", CorrelatedJoinNode::getType);
        }
    }

    public static final class Limit
    {
        public static Property count()
        {
            return property("count", LimitNode::getCount);
        }

        public static Property requiresPreSortedInputs()
        {
            return property("requiresPreSortedInputs", LimitNode::requiresPreSortedInputs);
        }
    }

    public static final class Sample
    {
        public static Property sampleRatio()
        {
            return property("sampleRatio", SampleNode::getSampleRatio);
        }

        public static Property sampleType()
        {
            return property("sampleType", SampleNode::getSampleType);
        }
    }

    public static final class TopN
    {
        public static Property step()
        {
            return property("step", TopNNode::getStep);
        }

        public static Property count()
        {
            return property("count", TopNNode::getCount);
        }
    }

    public static final class Values
    {
        public static Property>> rows()
        {
            return property("rows", ValuesNode::getRows);
        }

        public static Property rowCount()
        {
            return property("rowCount", ValuesNode::getRowCount);
        }
    }

    public static final class SemiJoin
    {
        public static Property getSource()
        {
            return property(
                    "source",
                    (SemiJoinNode semiJoin, Lookup lookup) -> lookup.resolve(semiJoin.getSource()));
        }

        public static Property getFilteringSource()
        {
            return property(
                    "filteringSource",
                    (SemiJoinNode semiJoin, Lookup lookup) -> lookup.resolve(semiJoin.getFilteringSource()));
        }
    }

    public static final class Intersect
    {
        public static Property distinct()
        {
            return property("distinct", IntersectNode::isDistinct);
        }
    }

    public static final class Except
    {
        public static Property distinct()
        {
            return property("distinct", ExceptNode::isDistinct);
        }
    }

    public static final class PatternRecognition
    {
        public static Property rowsPerMatch()
        {
            return property("rowsPerMatch", PatternRecognitionNode::getRowsPerMatch);
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy