Search in sources :

Example 1 with QuantifierType

use of org.voltdb.types.QuantifierType in project voltdb by VoltDB.

the class AbstractParsedStmt method parseOperationExpression.

/**
     *
     * @param paramsById
     * @param exprNode
     * @return
     */
private AbstractExpression parseOperationExpression(VoltXMLElement exprNode) {
    String optype = exprNode.attributes.get("optype");
    ExpressionType exprType = ExpressionType.get(optype);
    AbstractExpression expr = null;
    if (exprType == ExpressionType.INVALID) {
        throw new PlanningErrorException("Unsupported operation type '" + optype + "'");
    }
    try {
        expr = exprType.getExpressionClass().newInstance();
    } catch (Exception e) {
        e.printStackTrace();
        throw new RuntimeException(e.getMessage(), e);
    }
    expr.setExpressionType(exprType);
    if (exprType == ExpressionType.OPERATOR_CASE_WHEN || exprType == ExpressionType.OPERATOR_ALTERNATIVE) {
        String valueType = exprNode.attributes.get("valuetype");
        expr.setValueType(VoltType.typeFromString(valueType));
    }
    if (expr instanceof ComparisonExpression) {
        String opsubtype = exprNode.attributes.get("opsubtype");
        if (opsubtype != null) {
            QuantifierType quantifier = QuantifierType.get(opsubtype);
            if (quantifier != QuantifierType.NONE) {
                ((ComparisonExpression) expr).setQuantifier(quantifier);
            }
        }
    }
    // get the first (left) node that is an element
    VoltXMLElement leftExprNode = exprNode.children.get(0);
    assert (leftExprNode != null);
    // recursively parse the left subtree (could be another operator or
    // a constant/tuple/param value operand).
    AbstractExpression leftExpr = parseExpressionNode(leftExprNode);
    assert ((leftExpr != null) || (exprType == ExpressionType.AGGREGATE_COUNT));
    expr.setLeft(leftExpr);
    // get the second (right) node that is an element (might be null)
    VoltXMLElement rightExprNode = null;
    if (exprNode.children.size() > 1) {
        rightExprNode = exprNode.children.get(1);
    }
    if (expr.needsRightExpression()) {
        assert (rightExprNode != null);
        // recursively parse the right subtree
        AbstractExpression rightExpr = parseExpressionNode(rightExprNode);
        assert (rightExpr != null);
        expr.setRight(rightExpr);
    } else {
        assert (rightExprNode == null);
        if (exprType == ExpressionType.OPERATOR_CAST) {
            String valuetype = exprNode.attributes.get("valuetype");
            assert (valuetype != null);
            VoltType voltType = VoltType.typeFromString(valuetype);
            expr.setValueType(voltType);
            // We don't support parameterized casting, such as specifically to "VARCHAR(3)" vs. VARCHAR,
            // so assume max length for variable-length types (VARCHAR and VARBINARY).
            int size = voltType.getMaxLengthInBytes();
            expr.setValueSize(size);
        }
    }
    if (exprType == ExpressionType.COMPARE_EQUAL && QuantifierType.ANY == ((ComparisonExpression) expr).getQuantifier()) {
        // Break up UNION/INTERSECT (ALL) set ops into individual selects connected by
        // AND/OR operator
        // col IN ( queryA UNION queryB ) - > col IN (queryA) OR col IN (queryB)
        // col IN ( queryA INTERSECTS queryB ) - > col IN (queryA) AND col IN (queryB)
        expr = ParsedUnionStmt.breakUpSetOpSubquery(expr);
    } else if (exprType == ExpressionType.OPERATOR_EXISTS) {
        expr = optimizeExistsExpression(expr);
    }
    return expr;
}
Also used : ComparisonExpression(org.voltdb.expressions.ComparisonExpression) AbstractExpression(org.voltdb.expressions.AbstractExpression) VoltType(org.voltdb.VoltType) QuantifierType(org.voltdb.types.QuantifierType) VoltXMLElement(org.hsqldb_voltpatches.VoltXMLElement) ExpressionType(org.voltdb.types.ExpressionType) JSONException(org.json_voltpatches.JSONException) Constraint(org.voltdb.catalog.Constraint)

Aggregations

VoltXMLElement (org.hsqldb_voltpatches.VoltXMLElement)1 JSONException (org.json_voltpatches.JSONException)1 VoltType (org.voltdb.VoltType)1 Constraint (org.voltdb.catalog.Constraint)1 AbstractExpression (org.voltdb.expressions.AbstractExpression)1 ComparisonExpression (org.voltdb.expressions.ComparisonExpression)1 ExpressionType (org.voltdb.types.ExpressionType)1 QuantifierType (org.voltdb.types.QuantifierType)1