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());
}
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;
}
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());
}
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);
}
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);
}
Aggregations