Search in sources :

Example 6 with BeamRelMetadataQuery

use of org.apache.beam.sdk.extensions.sql.impl.planner.BeamRelMetadataQuery in project beam by apache.

the class BeamCalcRelTest method testFilterNodeStats.

@Test
public void testFilterNodeStats() {
    String sql = "SELECT * FROM ORDER_DETAILS_BOUNDED where order_id=1";
    RelNode root = env.parseQuery(sql);
    Assert.assertTrue(root instanceof BeamCalcRel);
    NodeStats estimate = BeamSqlRelUtils.getNodeStats(root, ((BeamRelMetadataQuery) root.getCluster().getMetadataQuery()));
    Assert.assertTrue(5d > estimate.getRowCount());
    Assert.assertTrue(5d > estimate.getWindow());
    Assert.assertEquals(0., estimate.getRate(), 0.001);
}
Also used : NodeStats(org.apache.beam.sdk.extensions.sql.impl.planner.NodeStats) BeamRelMetadataQuery(org.apache.beam.sdk.extensions.sql.impl.planner.BeamRelMetadataQuery) RelNode(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.RelNode) Test(org.junit.Test)

Example 7 with BeamRelMetadataQuery

use of org.apache.beam.sdk.extensions.sql.impl.planner.BeamRelMetadataQuery in project beam by apache.

the class BeamCalcRelTest method testProjectionNodeStats.

@Test
public void testProjectionNodeStats() {
    String sql = "SELECT order_id FROM ORDER_DETAILS_BOUNDED";
    RelNode root = env.parseQuery(sql);
    Assert.assertTrue(root instanceof BeamCalcRel);
    NodeStats estimate = BeamSqlRelUtils.getNodeStats(root, ((BeamRelMetadataQuery) root.getCluster().getMetadataQuery()));
    Assert.assertEquals(5d, estimate.getRowCount(), 0.001);
    Assert.assertEquals(5d, estimate.getWindow(), 0.001);
    Assert.assertEquals(0., estimate.getRate(), 0.001);
}
Also used : NodeStats(org.apache.beam.sdk.extensions.sql.impl.planner.NodeStats) BeamRelMetadataQuery(org.apache.beam.sdk.extensions.sql.impl.planner.BeamRelMetadataQuery) RelNode(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.RelNode) Test(org.junit.Test)

Example 8 with BeamRelMetadataQuery

use of org.apache.beam.sdk.extensions.sql.impl.planner.BeamRelMetadataQuery in project beam by apache.

the class BeamIOSourceRelTest method testBoundedNodeStats.

@Test
public void testBoundedNodeStats() {
    String sql = "SELECT * FROM ORDER_DETAILS_BOUNDED";
    RelNode root = env.parseQuery(sql);
    while (!(root instanceof BeamIOSourceRel)) {
        root = root.getInput(0);
    }
    NodeStats estimate = BeamSqlRelUtils.getNodeStats(root, ((BeamRelMetadataQuery) root.getCluster().getMetadataQuery()));
    Assert.assertEquals(5d, estimate.getRowCount(), 0.01);
    Assert.assertEquals(0d, estimate.getRate(), 0.01);
    Assert.assertEquals(5d, estimate.getWindow(), 0.01);
}
Also used : NodeStats(org.apache.beam.sdk.extensions.sql.impl.planner.NodeStats) BeamRelMetadataQuery(org.apache.beam.sdk.extensions.sql.impl.planner.BeamRelMetadataQuery) RelNode(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.RelNode) Test(org.junit.Test)

Example 9 with BeamRelMetadataQuery

use of org.apache.beam.sdk.extensions.sql.impl.planner.BeamRelMetadataQuery in project beam by apache.

the class BeamIOSourceRelTest method testUnboundedNodeStats.

@Test
public void testUnboundedNodeStats() {
    String sql = "SELECT * FROM ORDER_DETAILS_UNBOUNDED";
    RelNode root = env.parseQuery(sql);
    while (!(root instanceof BeamIOSourceRel)) {
        root = root.getInput(0);
    }
    NodeStats estimate = BeamSqlRelUtils.getNodeStats(root, ((BeamRelMetadataQuery) root.getCluster().getMetadataQuery()));
    Assert.assertEquals(0d, estimate.getRowCount(), 0.01);
    Assert.assertEquals(2d, estimate.getRate(), 0.01);
    Assert.assertEquals(BeamIOSourceRel.CONSTANT_WINDOW_SIZE, estimate.getWindow(), 0.01);
}
Also used : NodeStats(org.apache.beam.sdk.extensions.sql.impl.planner.NodeStats) BeamRelMetadataQuery(org.apache.beam.sdk.extensions.sql.impl.planner.BeamRelMetadataQuery) RelNode(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.RelNode) Test(org.junit.Test)

Example 10 with BeamRelMetadataQuery

use of org.apache.beam.sdk.extensions.sql.impl.planner.BeamRelMetadataQuery in project beam by apache.

the class BeamMinusRelTest method testNodeStatsEstimationUnbounded.

@Test
public void testNodeStatsEstimationUnbounded() {
    String sql = "SELECT * " + "FROM " + "(select order_id FROM ORDER_DETAILS_UNBOUNDED " + "          GROUP BY order_id, TUMBLE(order_time, INTERVAL '1' HOUR)) o1 " + " EXCEPT ALL " + " select order_id FROM ORDER_DETAILS_UNBOUNDED " + "          GROUP BY order_id, TUMBLE(order_time, INTERVAL '1' HOUR) ";
    RelNode root = env.parseQuery(sql);
    while (!(root instanceof BeamMinusRel)) {
        root = root.getInput(0);
    }
    NodeStats estimate = BeamSqlRelUtils.getNodeStats(root, ((BeamRelMetadataQuery) root.getCluster().getMetadataQuery()));
    // note that we have group by
    Assert.assertEquals(4d / 2 - 4d / 4, estimate.getRate(), 0.01);
    Assert.assertEquals(0d, estimate.getRowCount(), 0.01);
}
Also used : NodeStats(org.apache.beam.sdk.extensions.sql.impl.planner.NodeStats) BeamRelMetadataQuery(org.apache.beam.sdk.extensions.sql.impl.planner.BeamRelMetadataQuery) RelNode(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.RelNode) Test(org.junit.Test)

Aggregations

BeamRelMetadataQuery (org.apache.beam.sdk.extensions.sql.impl.planner.BeamRelMetadataQuery)19 NodeStats (org.apache.beam.sdk.extensions.sql.impl.planner.NodeStats)17 RelNode (org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.RelNode)17 Test (org.junit.Test)16 RelTraitSet (org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.plan.RelTraitSet)3 BeamRelNode (org.apache.beam.sdk.extensions.sql.impl.rel.BeamRelNode)2 RelOptPlanner (org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.plan.RelOptPlanner)2 RelRoot (org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.RelRoot)2 List (java.util.List)1 SqlConversionException (org.apache.beam.sdk.extensions.sql.impl.SqlConversionException)1 BeamCostModel (org.apache.beam.sdk.extensions.sql.impl.planner.BeamCostModel)1 PTransform (org.apache.beam.sdk.transforms.PTransform)1 WindowFn (org.apache.beam.sdk.transforms.windowing.WindowFn)1 PCollection (org.apache.beam.sdk.values.PCollection)1 PCollectionList (org.apache.beam.sdk.values.PCollectionList)1 Row (org.apache.beam.sdk.values.Row)1 RelOptCluster (org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.plan.RelOptCluster)1 CannotPlanException (org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.plan.RelOptPlanner.CannotPlanException)1 SetOp (org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.core.SetOp)1 Union (org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.core.Union)1