|
| 1 | +/* |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one or more |
| 3 | + * contributor license agreements. See the NOTICE file distributed with |
| 4 | + * this work for additional information regarding copyright ownership. |
| 5 | + * The ASF licenses this file to you under the Apache License, Version 2.0 |
| 6 | + * (the "License"); you may not use this file except in compliance with |
| 7 | + * the License. You may obtain a copy of the License at |
| 8 | + * |
| 9 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | + * |
| 11 | + * Unless required by applicable law or agreed to in writing, software |
| 12 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | + * See the License for the specific language governing permissions and |
| 15 | + * limitations under the License. |
| 16 | + */ |
| 17 | +package org.apache.calcite.adapter.enumerable; |
| 18 | + |
| 19 | +import org.apache.calcite.plan.RelOptTable; |
| 20 | +import org.apache.calcite.rel.RelCollation; |
| 21 | +import org.apache.calcite.rel.RelNode; |
| 22 | +import org.apache.calcite.rel.core.CorrelationId; |
| 23 | +import org.apache.calcite.rel.hint.RelHint; |
| 24 | +import org.apache.calcite.rel.type.RelDataType; |
| 25 | +import org.apache.calcite.rex.RexNode; |
| 26 | +import org.apache.calcite.rex.RexUtil; |
| 27 | +import org.apache.calcite.sql.validate.SqlValidatorUtil; |
| 28 | + |
| 29 | +import java.util.List; |
| 30 | +import java.util.Set; |
| 31 | + |
| 32 | +/** |
| 33 | + * Contains factory interface and default implementation for creating various |
| 34 | + * rel nodes. |
| 35 | + */ |
| 36 | +public class EnumerableRelFactories { |
| 37 | + |
| 38 | + public static final org.apache.calcite.rel.core.RelFactories.TableScanFactory |
| 39 | + ENUMERABLE_TABLE_SCAN_FACTORY = new TableScanFactoryImpl(); |
| 40 | + |
| 41 | + public static final org.apache.calcite.rel.core.RelFactories.ProjectFactory |
| 42 | + ENUMERABLE_PROJECT_FACTORY = new ProjectFactoryImpl(); |
| 43 | + |
| 44 | + public static final org.apache.calcite.rel.core.RelFactories.FilterFactory |
| 45 | + ENUMERABLE_FILTER_FACTORY = new FilterFactoryImpl(); |
| 46 | + |
| 47 | + public static final org.apache.calcite.rel.core.RelFactories.SortFactory |
| 48 | + ENUMERABLE_SORT_FACTORY = new SortFactoryImpl(); |
| 49 | + |
| 50 | + /** |
| 51 | + * Implementation of {@link org.apache.calcite.rel.core.RelFactories.TableScanFactory} that |
| 52 | + * returns a vanilla {@link EnumerableTableScan}. |
| 53 | + */ |
| 54 | + private static class TableScanFactoryImpl |
| 55 | + implements org.apache.calcite.rel.core.RelFactories.TableScanFactory { |
| 56 | + public RelNode createScan(RelOptTable.ToRelContext toRelContext, RelOptTable table) { |
| 57 | + return EnumerableTableScan.create(toRelContext.getCluster(), table); |
| 58 | + } |
| 59 | + } |
| 60 | + |
| 61 | + /** |
| 62 | + * Implementation of {@link org.apache.calcite.rel.core.RelFactories.ProjectFactory} that |
| 63 | + * returns a vanilla {@link EnumerableProject}. |
| 64 | + */ |
| 65 | + private static class ProjectFactoryImpl |
| 66 | + implements org.apache.calcite.rel.core.RelFactories.ProjectFactory { |
| 67 | + public RelNode createProject(RelNode input, List<RelHint> hints, |
| 68 | + List<? extends RexNode> childExprs, List<String> fieldNames) { |
| 69 | + final RelDataType rowType = |
| 70 | + RexUtil.createStructType(input.getCluster().getTypeFactory(), childExprs, |
| 71 | + fieldNames, SqlValidatorUtil.F_SUGGESTER); |
| 72 | + return EnumerableProject.create(input, childExprs, rowType); |
| 73 | + } |
| 74 | + } |
| 75 | + |
| 76 | + /** |
| 77 | + * Implementation of {@link org.apache.calcite.rel.core.RelFactories.FilterFactory} that |
| 78 | + * returns a vanilla {@link EnumerableFilter}. |
| 79 | + */ |
| 80 | + private static class FilterFactoryImpl |
| 81 | + implements org.apache.calcite.rel.core.RelFactories.FilterFactory { |
| 82 | + public RelNode createFilter(RelNode input, RexNode condition, |
| 83 | + Set<CorrelationId> variablesSet) { |
| 84 | + return EnumerableFilter.create(input, condition); |
| 85 | + } |
| 86 | + } |
| 87 | + |
| 88 | + /** |
| 89 | + * Implementation of {@link org.apache.calcite.rel.core.RelFactories.SortFactory} that |
| 90 | + * returns a vanilla {@link EnumerableSort}. |
| 91 | + */ |
| 92 | + private static class SortFactoryImpl |
| 93 | + implements org.apache.calcite.rel.core.RelFactories.SortFactory { |
| 94 | + public RelNode createSort(RelNode input, RelCollation collation, |
| 95 | + RexNode offset, RexNode fetch) { |
| 96 | + return EnumerableSort.create(input, collation, offset, fetch); |
| 97 | + } |
| 98 | + } |
| 99 | + |
| 100 | + private EnumerableRelFactories() { |
| 101 | + } |
| 102 | +} |
0 commit comments