Search in sources :

Example 46 with RelOptTable

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

the class RelMetadataTest method testAverageRowSize.

/**
 * Unit test for
 * {@link org.apache.calcite.rel.metadata.RelMetadataQuery#getAverageColumnSizes(org.apache.calcite.rel.RelNode)},
 * {@link org.apache.calcite.rel.metadata.RelMetadataQuery#getAverageRowSize(org.apache.calcite.rel.RelNode)}.
 */
@Test
public void testAverageRowSize() {
    final Project rel = (Project) convertSql("select * from emp, dept");
    final Join join = (Join) rel.getInput();
    final RelOptTable empTable = join.getInput(0).getTable();
    final RelOptTable deptTable = join.getInput(1).getTable();
    Frameworks.withPlanner(new Frameworks.PlannerAction<Void>() {

        public Void apply(RelOptCluster cluster, RelOptSchema relOptSchema, SchemaPlus rootSchema) {
            checkAverageRowSize(cluster, empTable, deptTable);
            return null;
        }
    });
}
Also used : RelOptCluster(org.apache.calcite.plan.RelOptCluster) Project(org.apache.calcite.rel.core.Project) LogicalProject(org.apache.calcite.rel.logical.LogicalProject) RelOptSchema(org.apache.calcite.plan.RelOptSchema) Frameworks(org.apache.calcite.tools.Frameworks) SchemaPlus(org.apache.calcite.schema.SchemaPlus) SemiJoin(org.apache.calcite.rel.core.SemiJoin) Join(org.apache.calcite.rel.core.Join) LogicalJoin(org.apache.calcite.rel.logical.LogicalJoin) EnumerableMergeJoin(org.apache.calcite.adapter.enumerable.EnumerableMergeJoin) RelOptTable(org.apache.calcite.plan.RelOptTable) Test(org.junit.Test)

Example 47 with RelOptTable

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

the class RelMetadataTest method checkTwoColumnOrigin.

// WARNING:  this requires the two table names to be different
private void checkTwoColumnOrigin(String sql, String expectedTableName1, String expectedColumnName1, String expectedTableName2, String expectedColumnName2, boolean expectedDerived) {
    Set<RelColumnOrigin> result = checkColumnOrigin(sql);
    assertTrue(result != null);
    assertEquals(2, result.size());
    for (RelColumnOrigin rco : result) {
        RelOptTable actualTable = rco.getOriginTable();
        List<String> actualTableName = actualTable.getQualifiedName();
        String actualUnqualifiedName = Iterables.getLast(actualTableName);
        if (actualUnqualifiedName.equals(expectedTableName1)) {
            checkColumnOrigin(rco, expectedTableName1, expectedColumnName1, expectedDerived);
        } else {
            checkColumnOrigin(rco, expectedTableName2, expectedColumnName2, expectedDerived);
        }
    }
}
Also used : RelColumnOrigin(org.apache.calcite.rel.metadata.RelColumnOrigin) RelOptTable(org.apache.calcite.plan.RelOptTable)

Example 48 with RelOptTable

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

the class RelMetadataTest method testPredicates.

/**
 * Unit test for
 * {@link org.apache.calcite.rel.metadata.RelMdPredicates#getPredicates(Join, RelMetadataQuery)}.
 */
@Test
public void testPredicates() {
    final Project rel = (Project) convertSql("select * from emp, dept");
    final Join join = (Join) rel.getInput();
    final RelOptTable empTable = join.getInput(0).getTable();
    final RelOptTable deptTable = join.getInput(1).getTable();
    Frameworks.withPlanner(new Frameworks.PlannerAction<Void>() {

        public Void apply(RelOptCluster cluster, RelOptSchema relOptSchema, SchemaPlus rootSchema) {
            checkPredicates(cluster, empTable, deptTable);
            return null;
        }
    });
}
Also used : RelOptCluster(org.apache.calcite.plan.RelOptCluster) Project(org.apache.calcite.rel.core.Project) LogicalProject(org.apache.calcite.rel.logical.LogicalProject) RelOptSchema(org.apache.calcite.plan.RelOptSchema) Frameworks(org.apache.calcite.tools.Frameworks) SchemaPlus(org.apache.calcite.schema.SchemaPlus) SemiJoin(org.apache.calcite.rel.core.SemiJoin) Join(org.apache.calcite.rel.core.Join) LogicalJoin(org.apache.calcite.rel.logical.LogicalJoin) EnumerableMergeJoin(org.apache.calcite.adapter.enumerable.EnumerableMergeJoin) RelOptTable(org.apache.calcite.plan.RelOptTable) Test(org.junit.Test)

Example 49 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 isRemovableSelfJoin.

/**
 * Determines whether a join is a removable self-join. It is if it's an
 * inner join between identical, simple factors and the equality portion of
 * the join condition consists of the same set of unique keys.
 *
 * @param joinRel the join
 *
 * @return true if the join is removable
 */
public static boolean isRemovableSelfJoin(Join joinRel) {
    final RelNode left = joinRel.getLeft();
    final RelNode right = joinRel.getRight();
    if (joinRel.getJoinType() != JoinRelType.INNER) {
        return false;
    }
    // Make sure the join is between the same simple factor
    final RelMetadataQuery mq = joinRel.getCluster().getMetadataQuery();
    final RelOptTable leftTable = mq.getTableOrigin(left);
    if (leftTable == null) {
        return false;
    }
    final RelOptTable rightTable = mq.getTableOrigin(right);
    if (rightTable == null) {
        return false;
    }
    if (!leftTable.getQualifiedName().equals(rightTable.getQualifiedName())) {
        return false;
    }
    // Determine if the join keys are identical and unique
    return areSelfJoinKeysUnique(mq, left, right, joinRel.getCondition());
}
Also used : RelMetadataQuery(org.apache.calcite.rel.metadata.RelMetadataQuery) RelNode(org.apache.calcite.rel.RelNode) RelOptTable(org.apache.calcite.plan.RelOptTable)

Example 50 with RelOptTable

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

the class DruidRelsTest method mockDruidRel.

public static <T extends DruidRel<?>> T mockDruidRel(final Class<T> clazz, final Consumer<T> additionalExpectationsFunction, final PartialDruidQuery.Stage stage, @Nullable DruidTable druidTable, @Nullable Project selectProject, @Nullable Filter whereFilter) {
    // DruidQueryRels rely on a ton of Calcite stuff like RelOptCluster, RelOptTable, etc, which is quite verbose to
    // create real instances of. So, tragically, we'll use EasyMock.
    final PartialDruidQuery mockPartialQuery = EasyMock.mock(PartialDruidQuery.class);
    EasyMock.expect(mockPartialQuery.stage()).andReturn(stage).anyTimes();
    EasyMock.expect(mockPartialQuery.getSelectProject()).andReturn(selectProject).anyTimes();
    EasyMock.expect(mockPartialQuery.getWhereFilter()).andReturn(whereFilter).anyTimes();
    final RelOptTable mockRelOptTable = EasyMock.mock(RelOptTable.class);
    EasyMock.expect(mockRelOptTable.unwrap(DruidTable.class)).andReturn(druidTable).anyTimes();
    final T mockRel = EasyMock.mock(clazz);
    EasyMock.expect(mockRel.getPartialDruidQuery()).andReturn(mockPartialQuery).anyTimes();
    EasyMock.expect(mockRel.getTable()).andReturn(mockRelOptTable).anyTimes();
    if (clazz == DruidQueryRel.class) {
        EasyMock.expect(((DruidQueryRel) mockRel).getDruidTable()).andReturn(druidTable).anyTimes();
    }
    additionalExpectationsFunction.accept(mockRel);
    EasyMock.replay(mockRel, mockPartialQuery, mockRelOptTable);
    return mockRel;
}
Also used : DruidTable(org.apache.druid.sql.calcite.table.DruidTable) 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