use of org.apache.beam.sdk.extensions.sql.impl.planner.NodeStats in project beam by apache.
the class BeamValuesRelTest method testNodeStatsEstimation.
@Test
public void testNodeStatsEstimation() {
String sql = "SELECT * FROM (VALUES ('value1'),('value2'),('value3'),('value4'),('value5')," + " ('value6'),('value7'),('value8'),('value9'))";
RelNode root = env.parseQuery(sql);
while (!(root instanceof BeamValuesRel)) {
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(9., estimate.getRowCount(), 0.01);
Assert.assertEquals(9., estimate.getWindow(), 0.01);
}
use of org.apache.beam.sdk.extensions.sql.impl.planner.NodeStats in project beam by apache.
the class BeamCalcRelTest method testNodeStatsConditionType.
@Test
public void testNodeStatsConditionType() {
String equalSql = "SELECT * FROM ORDER_DETAILS_BOUNDED where order_id=1";
String geqSql = "SELECT * FROM ORDER_DETAILS_BOUNDED where order_id>=1";
RelNode equalRoot = env.parseQuery(equalSql);
RelNode geqRoot = env.parseQuery(geqSql);
NodeStats equalEstimate = BeamSqlRelUtils.getNodeStats(equalRoot, ((BeamRelMetadataQuery) equalRoot.getCluster().getMetadataQuery()));
NodeStats geqEstimate = BeamSqlRelUtils.getNodeStats(geqRoot, ((BeamRelMetadataQuery) geqRoot.getCluster().getMetadataQuery()));
Assert.assertTrue(geqEstimate.getRowCount() > equalEstimate.getRowCount());
Assert.assertTrue(geqEstimate.getWindow() > equalEstimate.getWindow());
}
use of org.apache.beam.sdk.extensions.sql.impl.planner.NodeStats in project beam by apache.
the class BeamCoGBKJoinRelUnboundedVsUnboundedTest method testNodeStatsEstimation.
@Test
public void testNodeStatsEstimation() {
String sql = "SELECT * FROM " + "(select order_id, sum(site_id) as sum_site_id FROM ORDER_DETAILS " + " GROUP BY order_id, TUMBLE(order_time, INTERVAL '1' HOUR)) o1 " + " JOIN " + "(select order_id, sum(site_id) as sum_site_id FROM ORDER_DETAILS " + " GROUP BY order_id, TUMBLE(order_time, INTERVAL '1' HOUR)) o2 " + " on " + " o1.order_id=o2.order_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.getRowCount(), 0.01);
Assert.assertNotEquals(0d, estimate.getRate(), 0.001);
Assert.assertTrue(estimate.getRate() < leftEstimate.getRate() * rightEstimate.getWindow() + rightEstimate.getRate() * leftEstimate.getWindow());
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.NodeStats in project beam by apache.
the class BeamMinusRelTest method testNodeStatsEstimation.
@Test
public void testNodeStatsEstimation() {
String sql = "SELECT order_id, site_id, price " + "FROM ORDER_DETAILS1 " + " EXCEPT ALL " + "SELECT order_id, site_id, price " + "FROM ORDER_DETAILS2 ";
RelNode root = env.parseQuery(sql);
while (!(root instanceof BeamMinusRel)) {
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(5. - 3. / 2., estimate.getRowCount(), 0.01);
Assert.assertEquals(5. - 3. / 2., estimate.getWindow(), 0.01);
}
Aggregations