Search in sources :

Example 1 with AbstractExpression

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

the class AbstractParsedStmt method rejectDisallowedRowOpExpressions.

private void rejectDisallowedRowOpExpressions(AbstractExpression expr) {
    ExpressionType exprType = expr.getExpressionType();
    // searching for row op subquery expressions.
    if (ExpressionType.CONJUNCTION_AND == exprType || ExpressionType.CONJUNCTION_OR == exprType) {
        rejectDisallowedRowOpExpressions(expr.getLeft());
        rejectDisallowedRowOpExpressions(expr.getRight());
        return;
    }
    if (ExpressionType.OPERATOR_NOT == exprType) {
        rejectDisallowedRowOpExpressions(expr.getLeft());
    }
    // The problem cases are all comparison ops.
    if (!(expr instanceof ComparisonExpression)) {
        return;
    }
    // The problem cases all have row expressions as an operand.
    AbstractExpression rowExpression = expr.getLeft();
    if (rowExpression instanceof RowSubqueryExpression) {
        rejectDisallowedRowColumns(rowExpression);
    }
    rowExpression = expr.getRight();
    if (rowExpression instanceof RowSubqueryExpression) {
        rejectDisallowedRowColumns(rowExpression);
    }
}
Also used : ComparisonExpression(org.voltdb.expressions.ComparisonExpression) AbstractExpression(org.voltdb.expressions.AbstractExpression) RowSubqueryExpression(org.voltdb.expressions.RowSubqueryExpression) ExpressionType(org.voltdb.types.ExpressionType)

Example 2 with AbstractExpression

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

the class AccessPath method toString.

@Override
public String toString() {
    String retval = "";
    retval += "INDEX: " + ((index == null) ? "NULL" : (index.getParent().getTypeName() + "." + index.getTypeName())) + "\n";
    retval += "USE:   " + use.toString() + "\n";
    retval += "FOR:   " + indexPurposeString() + "\n";
    retval += "TYPE:  " + lookupType.toString() + "\n";
    retval += "DIR:   " + sortDirection.toString() + "\n";
    retval += "ITER?: " + String.valueOf(keyIterate) + "\n";
    retval += "NLIJ?: " + String.valueOf(nestLoopIndexJoin) + "\n";
    retval += "IDX EXPRS:\n";
    int i = 0;
    for (AbstractExpression expr : indexExprs) retval += "\t(" + String.valueOf(i++) + ") " + expr.toString() + "\n";
    retval += "END EXPRS:\n";
    i = 0;
    for (AbstractExpression expr : endExprs) retval += "\t(" + String.valueOf(i++) + ") " + expr.toString() + "\n";
    retval += "OTHER EXPRS:\n";
    i = 0;
    for (AbstractExpression expr : otherExprs) retval += "\t(" + String.valueOf(i++) + ") " + expr.toString() + "\n";
    retval += "JOIN EXPRS:\n";
    i = 0;
    for (AbstractExpression expr : joinExprs) retval += "\t(" + String.valueOf(i++) + ") " + expr.toString() + "\n";
    retval += "ELIMINATED POST FILTER EXPRS:\n";
    i = 0;
    for (AbstractExpression expr : eliminatedPostExprs) retval += "\t(" + String.valueOf(i++) + ") " + expr.toString() + "\n";
    return retval;
}
Also used : AbstractExpression(org.voltdb.expressions.AbstractExpression)

Example 3 with AbstractExpression

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

the class AbstractParsedStmt method parseTableCondition.

/** Parse a where or join clause. This behavior is common to all kinds of statements.
     */
private AbstractExpression parseTableCondition(VoltXMLElement tableScan, String joinOrWhere) {
    AbstractExpression condExpr = null;
    for (VoltXMLElement childNode : tableScan.children) {
        if (!childNode.name.equalsIgnoreCase(joinOrWhere)) {
            continue;
        }
        assert (childNode.children.size() == 1);
        assert (condExpr == null);
        condExpr = parseConditionTree(childNode.children.get(0));
        assert (condExpr != null);
        ExpressionUtil.finalizeValueTypes(condExpr);
        condExpr = ExpressionUtil.evaluateExpression(condExpr);
        // If the condition is a trivial CVE(TRUE) (after the evaluation) simply drop it
        if (ConstantValueExpression.isBooleanTrue(condExpr)) {
            condExpr = null;
        }
    }
    return condExpr;
}
Also used : AbstractExpression(org.voltdb.expressions.AbstractExpression) VoltXMLElement(org.hsqldb_voltpatches.VoltXMLElement)

Example 4 with AbstractExpression

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

the class AbstractParsedStmt method parseRowExpression.

/**
     *
     * @param exprNode
     * @return
     */
private AbstractExpression parseRowExpression(List<VoltXMLElement> exprNodes) {
    // Parse individual columnref expressions from the IN output schema
    List<AbstractExpression> exprs = new ArrayList<>();
    for (VoltXMLElement exprNode : exprNodes) {
        AbstractExpression expr = parseExpressionNode(exprNode);
        exprs.add(expr);
    }
    return new RowSubqueryExpression(exprs);
}
Also used : AbstractExpression(org.voltdb.expressions.AbstractExpression) RowSubqueryExpression(org.voltdb.expressions.RowSubqueryExpression) ArrayList(java.util.ArrayList) VoltXMLElement(org.hsqldb_voltpatches.VoltXMLElement)

Example 5 with AbstractExpression

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

the class AbstractParsedStmt method replaceExpressionsWithPve.

/**
     * Helper method to replace all TVEs and aggregated expressions with the corresponding PVEs.
     * The original expressions are placed into the map to be propagated to the EE.
     * The key to the map is the parameter index.
     *
     *
     * @param stmt - subquery statement
     * @param expr - expression with parent TVEs
     * @return Expression with parent TVE replaced with PVE
     */
protected AbstractExpression replaceExpressionsWithPve(AbstractExpression expr) {
    assert (expr != null);
    if (expr instanceof TupleValueExpression) {
        int paramIdx = NEXT_PARAMETER_ID++;
        ParameterValueExpression pve = new ParameterValueExpression(paramIdx, expr);
        m_parameterTveMap.put(paramIdx, expr);
        return pve;
    }
    if (expr instanceof AggregateExpression) {
        int paramIdx = NEXT_PARAMETER_ID++;
        ParameterValueExpression pve = new ParameterValueExpression(paramIdx, expr);
        // Disallow aggregation of parent columns in a subquery.
        // except the case HAVING AGG(T1.C1) IN (SELECT T2.C2 ...)
        List<TupleValueExpression> tves = ExpressionUtil.getTupleValueExpressions(expr);
        assert (m_parentStmt != null);
        for (TupleValueExpression tve : tves) {
            int origId = tve.getOrigStmtId();
            if (m_stmtId != origId && m_parentStmt.m_stmtId != origId) {
                throw new PlanningErrorException("Subqueries do not support aggregation of parent statement columns");
            }
        }
        m_parameterTveMap.put(paramIdx, expr);
        return pve;
    }
    if (expr.getLeft() != null) {
        expr.setLeft(replaceExpressionsWithPve(expr.getLeft()));
    }
    if (expr.getRight() != null) {
        expr.setRight(replaceExpressionsWithPve(expr.getRight()));
    }
    if (expr.getArgs() != null) {
        List<AbstractExpression> newArgs = new ArrayList<>();
        for (AbstractExpression argument : expr.getArgs()) {
            newArgs.add(replaceExpressionsWithPve(argument));
        }
        expr.setArgs(newArgs);
    }
    return expr;
}
Also used : TupleValueExpression(org.voltdb.expressions.TupleValueExpression) AbstractExpression(org.voltdb.expressions.AbstractExpression) ArrayList(java.util.ArrayList) ParameterValueExpression(org.voltdb.expressions.ParameterValueExpression) AggregateExpression(org.voltdb.expressions.AggregateExpression) Constraint(org.voltdb.catalog.Constraint)

Aggregations

AbstractExpression (org.voltdb.expressions.AbstractExpression)215 TupleValueExpression (org.voltdb.expressions.TupleValueExpression)59 AbstractPlanNode (org.voltdb.plannodes.AbstractPlanNode)55 ArrayList (java.util.ArrayList)43 SeqScanPlanNode (org.voltdb.plannodes.SeqScanPlanNode)26 SchemaColumn (org.voltdb.plannodes.SchemaColumn)25 NestLoopPlanNode (org.voltdb.plannodes.NestLoopPlanNode)23 Constraint (org.voltdb.catalog.Constraint)22 IndexScanPlanNode (org.voltdb.plannodes.IndexScanPlanNode)22 HashSet (java.util.HashSet)21 Column (org.voltdb.catalog.Column)21 AbstractScanPlanNode (org.voltdb.plannodes.AbstractScanPlanNode)21 JSONException (org.json_voltpatches.JSONException)19 ColumnRef (org.voltdb.catalog.ColumnRef)19 Table (org.voltdb.catalog.Table)17 AbstractSubqueryExpression (org.voltdb.expressions.AbstractSubqueryExpression)16 ParameterValueExpression (org.voltdb.expressions.ParameterValueExpression)16 StmtTableScan (org.voltdb.planner.parseinfo.StmtTableScan)16 ExpressionType (org.voltdb.types.ExpressionType)16 VoltXMLElement (org.hsqldb_voltpatches.VoltXMLElement)14