use of org.apache.beam.sdk.extensions.sql.impl.planner.NodeStats in project beam by apache.
the class BeamSideInputJoinRelTest method testNodeStatsEstimation.
@Test
public void testNodeStatsEstimation() {
String sql = "SELECT o1.order_id, o1.sum_site_id, o2.buyer 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 " + " ORDER_DETAILS1 o2 " + " on " + " o1.order_id=o2.order_id";
RelNode root = env.parseQuery(sql);
while (!(root instanceof BeamSideInputJoinRel)) {
root = root.getInput(0);
}
NodeStats estimate = BeamSqlRelUtils.getNodeStats(root, ((BeamRelMetadataQuery) root.getCluster().getMetadataQuery()));
NodeStats leftEstimate = BeamSqlRelUtils.getNodeStats(((BeamSideInputJoinRel) root).getLeft(), ((BeamRelMetadataQuery) root.getCluster().getMetadataQuery()));
NodeStats rightEstimate = BeamSqlRelUtils.getNodeStats(((BeamSideInputJoinRel) 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.getRowCount() * rightEstimate.getWindow() + rightEstimate.getRowCount() * 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 BeamUnionRelTest method testNodeStatsEstimation.
@Test
public void testNodeStatsEstimation() {
String sql = "SELECT " + " order_id, site_id, price " + "FROM ORDER_DETAILS " + " UNION SELECT " + " order_id, site_id, price " + "FROM ORDER_DETAILS ";
RelNode root = env.parseQuery(sql);
while (!(root instanceof BeamUnionRel)) {
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(2., estimate.getRowCount(), 0.01);
Assert.assertEquals(2., estimate.getWindow(), 0.01);
}
use of org.apache.beam.sdk.extensions.sql.impl.planner.NodeStats in project beam by apache.
the class BeamCalcRelTest method testNodeStatsNumberOfConditions.
@Test
public void testNodeStatsNumberOfConditions() {
String equalSql = "SELECT * FROM ORDER_DETAILS_BOUNDED where order_id=1";
String doubleEqualSql = "SELECT * FROM ORDER_DETAILS_BOUNDED WHERE order_id=1 AND site_id=2 ";
RelNode equalRoot = env.parseQuery(equalSql);
RelNode doubleEqualRoot = env.parseQuery(doubleEqualSql);
NodeStats equalEstimate = BeamSqlRelUtils.getNodeStats(equalRoot, ((BeamRelMetadataQuery) equalRoot.getCluster().getMetadataQuery()));
NodeStats doubleEqualEstimate = BeamSqlRelUtils.getNodeStats(doubleEqualRoot, ((BeamRelMetadataQuery) doubleEqualRoot.getCluster().getMetadataQuery()));
Assert.assertTrue(doubleEqualEstimate.getRowCount() < equalEstimate.getRowCount());
Assert.assertTrue(doubleEqualEstimate.getWindow() < equalEstimate.getWindow());
}
use of org.apache.beam.sdk.extensions.sql.impl.planner.NodeStats 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);
}
use of org.apache.beam.sdk.extensions.sql.impl.planner.NodeStats 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);
}
Aggregations