Search in sources :

Example 31 with SchemaColumn

use of org.voltdb.plannodes.SchemaColumn in project voltdb by VoltDB.

the class TestPlansScalarSubQueries method testSelectParameterScalar.

public void testSelectParameterScalar() {
    AbstractPlanNode pn = compile("select r2.c, (select d from r1 where r1.c = ? ) scalar from r2");
    pn = pn.getChild(0);
    assertTrue(pn instanceof AbstractScanPlanNode);
    AbstractPlanNode proj = pn.getInlinePlanNode(PlanNodeType.PROJECTION);
    NodeSchema schema = proj.getOutputSchema();
    assertEquals(2, schema.size());
    SchemaColumn col = schema.getColumns().get(1);
    assertTrue(col != null);
    assertEquals("SCALAR", col.getColumnName());
    AbstractExpression colExpr = col.getExpression();
    assertEquals(ExpressionType.VALUE_SCALAR, colExpr.getExpressionType());
    assertTrue(colExpr.getLeft() instanceof AbstractSubqueryExpression);
    AbstractSubqueryExpression subqueryExpr = (AbstractSubqueryExpression) colExpr.getLeft();
    AbstractPlanNode subquery = subqueryExpr.getSubqueryNode();
    assertEquals(PlanNodeType.SEQSCAN, subquery.getPlanNodeType());
    AbstractExpression pred = ((SeqScanPlanNode) subquery).getPredicate();
    assertEquals(ExpressionType.VALUE_PARAMETER, pred.getRight().getExpressionType());
}
Also used : AbstractPlanNode(org.voltdb.plannodes.AbstractPlanNode) SeqScanPlanNode(org.voltdb.plannodes.SeqScanPlanNode) AbstractScanPlanNode(org.voltdb.plannodes.AbstractScanPlanNode) AbstractExpression(org.voltdb.expressions.AbstractExpression) AbstractSubqueryExpression(org.voltdb.expressions.AbstractSubqueryExpression) SchemaColumn(org.voltdb.plannodes.SchemaColumn) NodeSchema(org.voltdb.plannodes.NodeSchema)

Example 32 with SchemaColumn

use of org.voltdb.plannodes.SchemaColumn 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 33 with SchemaColumn

use of org.voltdb.plannodes.SchemaColumn in project voltdb by VoltDB.

the class TestPlansJoin method perJoinOpTestBasicInnerJoin.

private void perJoinOpTestBasicInnerJoin(JoinOp joinOp) {
    String query;
    String pattern;
    AbstractPlanNode pn;
    List<SchemaColumn> selectColumns;
    // SELECT * with ON clause should return all columns from all tables
    query = "SELECT * FROM R1 JOIN R2 ON R1.C" + joinOp + "R2.C";
    pn = compileToTopDownTree(query, 5, PlanNodeType.SEND, PlanNodeType.PROJECTION, PlanNodeType.NESTLOOP, PlanNodeType.SEQSCAN, PlanNodeType.SEQSCAN);
    query = "SELECT R1.A, R1.C, D FROM R1 JOIN R2 ON R1.C" + joinOp + "R2.C";
    pn = compileToTopDownTree(query, 3, PlanNodeType.SEND, PlanNodeType.PROJECTION, PlanNodeType.NESTLOOP, PlanNodeType.SEQSCAN, PlanNodeType.SEQSCAN);
    query = "SELECT R1.A, C, R1.D FROM R1 JOIN R2 USING(C)";
    pn = compileToTopDownTree(query, 3, PlanNodeType.SEND, PlanNodeType.PROJECTION, PlanNodeType.NESTLOOP, PlanNodeType.SEQSCAN, PlanNodeType.SEQSCAN);
    query = "SELECT R1.A, R2.C, R1.D FROM R1 JOIN R2 ON R1.C" + joinOp + "R2.C";
    pn = compileToTopDownTree(query, 3, PlanNodeType.SEND, PlanNodeType.PROJECTION, PlanNodeType.NESTLOOP, PlanNodeType.SEQSCAN, PlanNodeType.SEQSCAN);
    selectColumns = pn.getOutputSchema().getColumns();
    assertEquals("R1", selectColumns.get(0).getTableName());
    assertEquals("R2", selectColumns.get(1).getTableName());
    // The output table for C can be either R1 or R2 because it's an INNER join
    query = "SELECT R1.A, C, R1.D FROM R1 JOIN R2 USING(C)";
    pn = compileToTopDownTree(query, 3, PlanNodeType.SEND, PlanNodeType.PROJECTION, PlanNodeType.NESTLOOP, PlanNodeType.SEQSCAN, PlanNodeType.SEQSCAN);
    selectColumns = pn.getOutputSchema().getColumns();
    assertEquals("R1", selectColumns.get(0).getTableName());
    String table = selectColumns.get(1).getTableName();
    assertTrue("R2".equals(table) || "R1".equals(table));
    table = selectColumns.get(2).getTableName();
    assertEquals("R1", table);
    query = "SELECT R2.C FROM R1 JOIN R2 ON R1.X" + joinOp + "R2.X";
    pattern = "user lacks privilege or object not found: R1.X";
    failToCompile(query, pattern);
    query = "SELECT * FROM R1 JOIN R2 ON R1.C" + joinOp + "R2.C AND 1";
    pattern = "data type of expression is not boolean";
    failToCompile(query, pattern);
    query = "SELECT * FROM R1 JOIN R2 ON R1.C" + joinOp + "R2.C AND MOD(3,1)=1";
    pattern = "Join with filters that do not depend on joined tables is not supported in VoltDB";
    failToCompile(query, pattern);
}
Also used : AbstractPlanNode(org.voltdb.plannodes.AbstractPlanNode) SchemaColumn(org.voltdb.plannodes.SchemaColumn)

Example 34 with SchemaColumn

use of org.voltdb.plannodes.SchemaColumn in project voltdb by VoltDB.

the class StmtSubqueryScan method promoteSinglePartitionInfo.

/**
     * upgrade single partitioning expression to parent level
     * add the info to equality sets and input value equivalence
     * @param valueEquivalence
     * @param eqSets
     */
public void promoteSinglePartitionInfo(HashMap<AbstractExpression, Set<AbstractExpression>> valueEquivalence, Set<Set<AbstractExpression>> eqSets) {
    assert (m_subqueriesPartitioning != null);
    if (m_subqueriesPartitioning.getCountOfPartitionedTables() == 0 || m_subqueriesPartitioning.requiresTwoFragments()) {
        return;
    }
    // This subquery is a single partitioned query on partitioned tables
    // promoting the single partition expression up to its parent level.
    AbstractExpression spExpr = m_subqueriesPartitioning.singlePartitioningExpression();
    for (SchemaColumn col : m_partitioningColumns) {
        AbstractExpression tveKey = col.getExpression();
        assert (tveKey instanceof TupleValueExpression);
        Set<AbstractExpression> values = null;
        if (valueEquivalence.containsKey(tveKey)) {
            values = valueEquivalence.get(tveKey);
        } else if (valueEquivalence.containsKey(spExpr)) {
            values = valueEquivalence.get(spExpr);
        } else {
            for (SchemaColumn otherCol : m_partitioningColumns) {
                if (col != otherCol && valueEquivalence.containsKey(otherCol.getExpression())) {
                    values = valueEquivalence.get(otherCol.getExpression());
                    break;
                }
            }
            if (values == null) {
                values = new HashSet<>();
            }
        }
        updateEqualSets(values, valueEquivalence, eqSets, tveKey, spExpr);
    }
}
Also used : TupleValueExpression(org.voltdb.expressions.TupleValueExpression) AbstractExpression(org.voltdb.expressions.AbstractExpression) SchemaColumn(org.voltdb.plannodes.SchemaColumn) HashSet(java.util.HashSet)

Example 35 with SchemaColumn

use of org.voltdb.plannodes.SchemaColumn in project voltdb by VoltDB.

the class StmtSubqueryScan method processTVE.

@Override
public AbstractExpression processTVE(TupleValueExpression expr, String columnName) {
    Integer idx = m_outputColumnIndexMap.get(Pair.of(columnName, expr.getDifferentiator()));
    if (idx == null) {
        throw new PlanningErrorException("Mismatched columns " + columnName + " in subquery");
    }
    SchemaColumn schemaCol = m_outputColumnList.get(idx.intValue());
    expr.setColumnIndex(idx.intValue());
    expr.setTypeSizeAndInBytes(schemaCol);
    return expr;
}
Also used : PlanningErrorException(org.voltdb.planner.PlanningErrorException) SchemaColumn(org.voltdb.plannodes.SchemaColumn)

Aggregations

SchemaColumn (org.voltdb.plannodes.SchemaColumn)37 AbstractExpression (org.voltdb.expressions.AbstractExpression)19 TupleValueExpression (org.voltdb.expressions.TupleValueExpression)16 AbstractPlanNode (org.voltdb.plannodes.AbstractPlanNode)13 NodeSchema (org.voltdb.plannodes.NodeSchema)13 ProjectionPlanNode (org.voltdb.plannodes.ProjectionPlanNode)6 HashSet (java.util.HashSet)5 StmtTableScan (org.voltdb.planner.parseinfo.StmtTableScan)5 AbstractScanPlanNode (org.voltdb.plannodes.AbstractScanPlanNode)5 NestLoopPlanNode (org.voltdb.plannodes.NestLoopPlanNode)5 Table (org.voltdb.catalog.Table)4 OrderByPlanNode (org.voltdb.plannodes.OrderByPlanNode)4 SeqScanPlanNode (org.voltdb.plannodes.SeqScanPlanNode)4 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 Column (org.voltdb.catalog.Column)3 Constraint (org.voltdb.catalog.Constraint)3 AbstractReceivePlanNode (org.voltdb.plannodes.AbstractReceivePlanNode)3 SendPlanNode (org.voltdb.plannodes.SendPlanNode)3 Set (java.util.Set)2