Search in sources :

Example 1 with RelOptTable

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.plan.RelOptTable in project hive by apache.

the class HiveSubQRemoveRelBuilder method scan.

// Methods that create relational expressions
/**
 * Creates a {@link org.apache.calcite.rel.core.TableScan} of the table
 * with a given name.
 *
 * <p>Throws if the table does not exist.
 *
 * <p>Returns this builder.
 *
 * @param tableNames Name of table (can optionally be qualified)
 */
public HiveSubQRemoveRelBuilder scan(Iterable<String> tableNames) {
    final List<String> names = ImmutableList.copyOf(tableNames);
    final RelOptTable relOptTable = relOptSchema.getTableForMember(names);
    if (relOptTable == null) {
        throw Static.RESOURCE.tableNotFound(Joiner.on(".").join(names)).ex();
    }
    final RelNode scan = scanFactory.createScan(cluster, relOptTable);
    push(scan);
    return this;
}
Also used : RelNode(org.apache.calcite.rel.RelNode) NlsString(org.apache.calcite.util.NlsString) RelOptTable(org.apache.calcite.plan.RelOptTable)

Example 2 with RelOptTable

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.plan.RelOptTable in project calcite by apache.

the class TableScanNode method create.

/**
 * Creates a TableScanNode.
 *
 * <p>Tries various table SPIs, and negotiates with the table which filters
 * and projects it can implement. Adds to the Enumerable implementations of
 * any filters and projects that cannot be implemented by the table.
 */
static TableScanNode create(Compiler compiler, TableScan rel, ImmutableList<RexNode> filters, ImmutableIntList projects) {
    final RelOptTable relOptTable = rel.getTable();
    final ProjectableFilterableTable pfTable = relOptTable.unwrap(ProjectableFilterableTable.class);
    if (pfTable != null) {
        return createProjectableFilterable(compiler, rel, filters, projects, pfTable);
    }
    final FilterableTable filterableTable = relOptTable.unwrap(FilterableTable.class);
    if (filterableTable != null) {
        return createFilterable(compiler, rel, filters, projects, filterableTable);
    }
    final ScannableTable scannableTable = relOptTable.unwrap(ScannableTable.class);
    if (scannableTable != null) {
        return createScannable(compiler, rel, filters, projects, scannableTable);
    }
    // noinspection unchecked
    final Enumerable<Row> enumerable = relOptTable.unwrap(Enumerable.class);
    if (enumerable != null) {
        return createEnumerable(compiler, rel, enumerable, null, filters, projects);
    }
    final QueryableTable queryableTable = relOptTable.unwrap(QueryableTable.class);
    if (queryableTable != null) {
        return createQueryable(compiler, rel, filters, projects, queryableTable);
    }
    throw new AssertionError("cannot convert table " + relOptTable + " to enumerable");
}
Also used : QueryableTable(org.apache.calcite.schema.QueryableTable) ProjectableFilterableTable(org.apache.calcite.schema.ProjectableFilterableTable) FilterableTable(org.apache.calcite.schema.FilterableTable) ProjectableFilterableTable(org.apache.calcite.schema.ProjectableFilterableTable) RelOptTable(org.apache.calcite.plan.RelOptTable) ScannableTable(org.apache.calcite.schema.ScannableTable)

Example 3 with RelOptTable

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.plan.RelOptTable in project calcite by apache.

the class RelMdColumnOrigins method getColumnOrigins.

// Catch-all rule when none of the others apply.
public Set<RelColumnOrigin> getColumnOrigins(RelNode rel, RelMetadataQuery mq, int iOutputColumn) {
    if (rel.getInputs().size() > 0) {
        // No generic logic available for non-leaf rels.
        return null;
    }
    final Set<RelColumnOrigin> set = new HashSet<>();
    RelOptTable table = rel.getTable();
    if (table == null) {
        // VALUES clause, so we return an empty set.
        return set;
    }
    // rename as well.
    if (table.getRowType() != rel.getRowType()) {
        return null;
    }
    set.add(new RelColumnOrigin(table, iOutputColumn, false));
    return set;
}
Also used : RelOptTable(org.apache.calcite.plan.RelOptTable) HashSet(java.util.HashSet)

Example 4 with RelOptTable

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.plan.RelOptTable in project calcite by apache.

the class LogicalTableScan method create.

/**
 * Creates a LogicalTableScan.
 *
 * @param cluster Cluster
 * @param relOptTable Table
 */
public static LogicalTableScan create(RelOptCluster cluster, final RelOptTable relOptTable) {
    final Table table = relOptTable.unwrap(Table.class);
    final RelTraitSet traitSet = cluster.traitSetOf(Convention.NONE).replaceIfs(RelCollationTraitDef.INSTANCE, new Supplier<List<RelCollation>>() {

        public List<RelCollation> get() {
            if (table != null) {
                return table.getStatistic().getCollations();
            }
            return ImmutableList.of();
        }
    });
    return new LogicalTableScan(cluster, traitSet, relOptTable);
}
Also used : Table(org.apache.calcite.schema.Table) RelOptTable(org.apache.calcite.plan.RelOptTable) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) RelTraitSet(org.apache.calcite.plan.RelTraitSet)

Example 5 with RelOptTable

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.plan.RelOptTable in project calcite by apache.

the class LoptOptimizeJoinRule method getSimpleFactors.

/**
 * Retrieves join factors that correspond to simple table references. A
 * simple table reference is a single table reference with no grouping or
 * aggregation.
 *
 * @param multiJoin join factors being optimized
 *
 * @return map consisting of the simple factors and the tables they
 * correspond
 */
private Map<Integer, RelOptTable> getSimpleFactors(RelMetadataQuery mq, LoptMultiJoin multiJoin) {
    final Map<Integer, RelOptTable> returnList = new HashMap<>();
    // are null-generating or will be removed because of semijoins.
    if (multiJoin.getMultiJoinRel().isFullOuterJoin()) {
        return returnList;
    }
    for (int factIdx = 0; factIdx < multiJoin.getNumJoinFactors(); factIdx++) {
        if (multiJoin.isNullGenerating(factIdx) || (multiJoin.getJoinRemovalFactor(factIdx) != null)) {
            continue;
        }
        final RelNode rel = multiJoin.getJoinFactor(factIdx);
        final RelOptTable table = mq.getTableOrigin(rel);
        if (table != null) {
            returnList.put(factIdx, table);
        }
    }
    return returnList;
}
Also used : RelNode(org.apache.calcite.rel.RelNode) HashMap(java.util.HashMap) RelOptTable(org.apache.calcite.plan.RelOptTable)

Aggregations

RelOptTable (org.apache.calcite.plan.RelOptTable)63 RelDataType (org.apache.calcite.rel.type.RelDataType)20 RexNode (org.apache.calcite.rex.RexNode)18 RelNode (org.apache.calcite.rel.RelNode)17 Table (org.apache.calcite.schema.Table)15 ArrayList (java.util.ArrayList)14 RelDataTypeField (org.apache.calcite.rel.type.RelDataTypeField)12 RelTraitSet (org.apache.calcite.plan.RelTraitSet)10 SqlNode (org.apache.calcite.sql.SqlNode)10 RelOptCluster (org.apache.calcite.plan.RelOptCluster)9 ImmutableList (com.google.common.collect.ImmutableList)8 NlsString (org.apache.calcite.util.NlsString)8 List (java.util.List)6 LogicalJoin (org.apache.calcite.rel.logical.LogicalJoin)6 SchemaPlus (org.apache.calcite.schema.SchemaPlus)6 RelOptSchema (org.apache.calcite.plan.RelOptSchema)5 Project (org.apache.calcite.rel.core.Project)5 LogicalProject (org.apache.calcite.rel.logical.LogicalProject)5 ProjectableFilterableTable (org.apache.calcite.schema.ProjectableFilterableTable)5 Test (org.junit.Test)5