Search in sources :

Example 1 with ScalarValueExpression

use of org.voltdb.expressions.ScalarValueExpression in project voltdb by VoltDB.

the class TestPlansScalarSubQueries method testSelectCorrelatedScalarWithGroupby.

public void testSelectCorrelatedScalarWithGroupby() {
    String sql = "select franchise_id, count(*) as stores_in_category_AdHoc, " + " (select category from store_types where type_id = stores.type_id) as store_category " + "from stores group by franchise_id, type_id;";
    AbstractPlanNode pn = compile(sql);
    pn = pn.getChild(0);
    assertTrue(pn instanceof ProjectionPlanNode);
    NodeSchema schema = pn.getOutputSchema();
    assertEquals(3, schema.size());
    SchemaColumn col = schema.getColumns().get(2);
    assertTrue(col != null);
    assertEquals("STORE_CATEGORY", col.getColumnName());
    assertTrue(col.getExpression() instanceof ScalarValueExpression);
    pn = pn.getChild(0);
    assertTrue(pn instanceof AbstractScanPlanNode);
    assertNotNull(pn.getInlinePlanNode(PlanNodeType.HASHAGGREGATE));
}
Also used : AbstractPlanNode(org.voltdb.plannodes.AbstractPlanNode) AbstractScanPlanNode(org.voltdb.plannodes.AbstractScanPlanNode) ScalarValueExpression(org.voltdb.expressions.ScalarValueExpression) SchemaColumn(org.voltdb.plannodes.SchemaColumn) NodeSchema(org.voltdb.plannodes.NodeSchema) ProjectionPlanNode(org.voltdb.plannodes.ProjectionPlanNode)

Example 2 with ScalarValueExpression

use of org.voltdb.expressions.ScalarValueExpression in project voltdb by VoltDB.

the class TestPlansScalarSubQueries method testSelectCorrelatedScalarInGroupbyClause.

public void testSelectCorrelatedScalarInGroupbyClause() {
    String sql = "select franchise_id, count(*) as stores_in_category_AdHoc " + " from stores group by franchise_id, (select category from store_types where type_id = stores.type_id);";
    AbstractPlanNode pn = compile(sql);
    pn = pn.getChild(0);
    assertTrue(pn instanceof ProjectionPlanNode);
    NodeSchema schema = pn.getOutputSchema();
    assertEquals(2, schema.size());
    pn = pn.getChild(0);
    assertTrue(pn instanceof AbstractScanPlanNode);
    assertNotNull(pn.getInlinePlanNode(PlanNodeType.HASHAGGREGATE));
    HashAggregatePlanNode aggNode = (HashAggregatePlanNode) pn.getInlinePlanNode(PlanNodeType.HASHAGGREGATE);
    assertEquals(2, aggNode.getGroupByExpressionsSize());
    AbstractExpression tveExpr = aggNode.getGroupByExpressions().get(0);
    assertTrue(tveExpr instanceof TupleValueExpression);
    AbstractExpression gbExpr = aggNode.getGroupByExpressions().get(1);
    assertTrue(gbExpr instanceof ScalarValueExpression);
    assertTrue(gbExpr.getLeft() instanceof SelectSubqueryExpression);
}
Also used : AbstractPlanNode(org.voltdb.plannodes.AbstractPlanNode) AbstractScanPlanNode(org.voltdb.plannodes.AbstractScanPlanNode) TupleValueExpression(org.voltdb.expressions.TupleValueExpression) AbstractExpression(org.voltdb.expressions.AbstractExpression) ScalarValueExpression(org.voltdb.expressions.ScalarValueExpression) HashAggregatePlanNode(org.voltdb.plannodes.HashAggregatePlanNode) SelectSubqueryExpression(org.voltdb.expressions.SelectSubqueryExpression) NodeSchema(org.voltdb.plannodes.NodeSchema) ProjectionPlanNode(org.voltdb.plannodes.ProjectionPlanNode)

Aggregations

ScalarValueExpression (org.voltdb.expressions.ScalarValueExpression)2 AbstractPlanNode (org.voltdb.plannodes.AbstractPlanNode)2 AbstractScanPlanNode (org.voltdb.plannodes.AbstractScanPlanNode)2 NodeSchema (org.voltdb.plannodes.NodeSchema)2 ProjectionPlanNode (org.voltdb.plannodes.ProjectionPlanNode)2 AbstractExpression (org.voltdb.expressions.AbstractExpression)1 SelectSubqueryExpression (org.voltdb.expressions.SelectSubqueryExpression)1 TupleValueExpression (org.voltdb.expressions.TupleValueExpression)1 HashAggregatePlanNode (org.voltdb.plannodes.HashAggregatePlanNode)1 SchemaColumn (org.voltdb.plannodes.SchemaColumn)1