Search in sources :

Example 11 with BeamRelMetadataQuery

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

the class BeamCoGBKJoinRelBoundedVsBoundedTest method testNodeStatsOfMoreConditions.

@Test
public void testNodeStatsOfMoreConditions() {
    String sql1 = "SELECT *  " + " FROM ORDER_DETAILS1 o1 " + " JOIN ORDER_DETAILS2 o2 " + " on " + " o1.order_id=o2.site_id ";
    String sql2 = "SELECT *  " + " FROM ORDER_DETAILS1 o1 " + " JOIN ORDER_DETAILS2 o2 " + " on " + " o1.order_id=o2.site_id AND o2.price=o1.site_id";
    RelNode root1 = env.parseQuery(sql1);
    while (!(root1 instanceof BeamCoGBKJoinRel)) {
        root1 = root1.getInput(0);
    }
    RelNode root2 = env.parseQuery(sql2);
    while (!(root2 instanceof BeamCoGBKJoinRel)) {
        root2 = root2.getInput(0);
    }
    NodeStats estimate1 = BeamSqlRelUtils.getNodeStats(root1, ((BeamRelMetadataQuery) root1.getCluster().getMetadataQuery()));
    NodeStats estimate2 = BeamSqlRelUtils.getNodeStats(root2, ((BeamRelMetadataQuery) root1.getCluster().getMetadataQuery()));
    Assert.assertNotEquals(0d, estimate2.getRowCount(), 0.001);
    // A join with two conditions should have lower estimate.
    Assert.assertTrue(estimate2.getRowCount() < estimate1.getRowCount());
}
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 12 with BeamRelMetadataQuery

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

the class BeamUnionRel method estimateNodeStats.

@Override
public NodeStats estimateNodeStats(BeamRelMetadataQuery mq) {
    // The summation of the input stats
    NodeStats summationOfEstimates = inputs.stream().map(input -> BeamSqlRelUtils.getNodeStats(input, mq)).reduce(NodeStats.create(0, 0, 0), NodeStats::plus);
    // If all is set then we propagate duplicated values. Otherwise we assume a constant factor of
    // them are duplicate.
    summationOfEstimates = all ? summationOfEstimates : summationOfEstimates.multiply(0.5);
    return summationOfEstimates;
}
Also used : SetOp(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.core.SetOp) RelNode(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.RelNode) NodeStats(org.apache.beam.sdk.extensions.sql.impl.planner.NodeStats) BeamCostModel(org.apache.beam.sdk.extensions.sql.impl.planner.BeamCostModel) WindowFn(org.apache.beam.sdk.transforms.windowing.WindowFn) Union(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.core.Union) PCollection(org.apache.beam.sdk.values.PCollection) PTransform(org.apache.beam.sdk.transforms.PTransform) RelOptCluster(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.plan.RelOptCluster) List(java.util.List) PCollectionList(org.apache.beam.sdk.values.PCollectionList) RelTraitSet(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.plan.RelTraitSet) BeamRelMetadataQuery(org.apache.beam.sdk.extensions.sql.impl.planner.BeamRelMetadataQuery) Row(org.apache.beam.sdk.values.Row) RelOptPlanner(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.plan.RelOptPlanner) NodeStats(org.apache.beam.sdk.extensions.sql.impl.planner.NodeStats)

Example 13 with BeamRelMetadataQuery

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

the class BeamCoGBKJoinRelBoundedVsBoundedTest method testNodeStatsEstimation.

@Test
public void testNodeStatsEstimation() {
    String sql = "SELECT *  " + " FROM ORDER_DETAILS1 o1 " + " JOIN ORDER_DETAILS2 o2 " + " on " + " o1.order_id=o2.site_id ";
    RelNode root = env.parseQuery(sql);
    while (!(root instanceof BeamCoGBKJoinRel)) {
        root = root.getInput(0);
    }
    NodeStats estimate = BeamSqlRelUtils.getNodeStats(root, ((BeamRelMetadataQuery) root.getCluster().getMetadataQuery()));
    NodeStats leftEstimate = BeamSqlRelUtils.getNodeStats(((BeamCoGBKJoinRel) root).getLeft(), ((BeamRelMetadataQuery) root.getCluster().getMetadataQuery()));
    NodeStats rightEstimate = BeamSqlRelUtils.getNodeStats(((BeamCoGBKJoinRel) root).getRight(), ((BeamRelMetadataQuery) root.getCluster().getMetadataQuery()));
    Assert.assertFalse(estimate.isUnknown());
    Assert.assertEquals(0d, estimate.getRate(), 0.01);
    Assert.assertNotEquals(0d, estimate.getRowCount(), 0.001);
    Assert.assertTrue(estimate.getRowCount() < leftEstimate.getRowCount() * rightEstimate.getRowCount());
    Assert.assertNotEquals(0d, estimate.getWindow(), 0.001);
    Assert.assertTrue(estimate.getWindow() < leftEstimate.getWindow() * rightEstimate.getWindow());
}
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 14 with BeamRelMetadataQuery

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

the class BeamIntersectRelTest method testNodeStatsEstimation.

@Test
public void testNodeStatsEstimation() {
    String sql = "SELECT order_id, site_id, price " + " FROM ORDER_DETAILS1 " + " INTERSECT " + " SELECT order_id, site_id, price " + " FROM ORDER_DETAILS2 ";
    RelNode root = env.parseQuery(sql);
    while (!(root instanceof BeamIntersectRel)) {
        root = root.getInput(0);
    }
    NodeStats estimate = BeamSqlRelUtils.getNodeStats(root, ((BeamRelMetadataQuery) root.getCluster().getMetadataQuery()));
    Assert.assertFalse(estimate.isUnknown());
    Assert.assertEquals(0d, estimate.getRate(), 0.01);
    Assert.assertEquals(3. / 2., estimate.getRowCount(), 0.01);
    Assert.assertEquals(3. / 2., 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 15 with BeamRelMetadataQuery

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

the class BeamSortRelTest method testNodeStatsEstimation.

@Test
public void testNodeStatsEstimation() {
    String sql = "SELECT order_id, site_id, price, order_time " + "FROM ORDER_DETAILS " + "ORDER BY order_time asc limit 11";
    RelNode root = env.parseQuery(sql);
    while (!(root instanceof BeamSortRel)) {
        root = root.getInput(0);
    }
    NodeStats estimate = BeamSqlRelUtils.getNodeStats(root, ((BeamRelMetadataQuery) root.getCluster().getMetadataQuery()));
    Assert.assertFalse(estimate.isUnknown());
    Assert.assertEquals(0d, estimate.getRate(), 0.01);
    Assert.assertEquals(10., estimate.getRowCount(), 0.01);
    Assert.assertEquals(10., 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)

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