Search in sources :

Example 1 with ExpressionType

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

the class OperatorExpression method finalizeValueTypes.

@Override
public void finalizeValueTypes() {
    finalizeChildValueTypes();
    ExpressionType type = getExpressionType();
    if (m_right == null) {
        if (type == ExpressionType.OPERATOR_IS_NULL || type == ExpressionType.OPERATOR_NOT || type == ExpressionType.OPERATOR_EXISTS) {
            m_valueType = VoltType.BOOLEAN;
            m_valueSize = m_valueType.getLengthInBytesForFixedTypes();
        }
        return;
    }
    if (type == ExpressionType.OPERATOR_CASE_WHEN || type == ExpressionType.OPERATOR_ALTERNATIVE) {
        assert (m_valueType != null);
        m_valueSize = m_valueType.getMaxLengthInBytes();
        return;
    }
    VoltType left_type = m_left.getValueType();
    //XXX Not sure how unary minus (and unary plus?) are handled (possibly via an implicit zero left argument?)
    VoltType right_type = m_right.getValueType();
    VoltType cast_type = VoltTypeUtil.determineImplicitCasting(left_type, right_type);
    if (cast_type == VoltType.INVALID) {
        throw new RuntimeException("ERROR: Invalid output value type for Expression '" + this + "'");
    }
    m_valueType = cast_type;
    // this may not always be safe
    m_valueSize = cast_type.getLengthInBytesForFixedTypes();
}
Also used : VoltType(org.voltdb.VoltType) ExpressionType(org.voltdb.types.ExpressionType)

Example 2 with ExpressionType

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

the class ExpressionUtil method isNullRejectingExpression.

/**
     *  A condition is null-rejected for a given table in the following cases:
     *      If it is of the form A IS NOT NULL, where A is an attribute of any of the inner tables
     *      If it is a predicate containing a reference to an inner table that evaluates to UNKNOWN
     *          when one of its arguments is NULL
     *      If it is a conjunction containing a null-rejected condition as a conjunct
     *      If it is a disjunction of null-rejected conditions
     *
     * @param expr
     * @param tableAlias
     * @return
     */
public static boolean isNullRejectingExpression(AbstractExpression expr, String tableAlias) {
    ExpressionType exprType = expr.getExpressionType();
    if (exprType == ExpressionType.CONJUNCTION_AND) {
        assert (expr.m_left != null && expr.m_right != null);
        return isNullRejectingExpression(expr.m_left, tableAlias) || isNullRejectingExpression(expr.m_right, tableAlias);
    }
    if (exprType == ExpressionType.CONJUNCTION_OR) {
        assert (expr.m_left != null && expr.m_right != null);
        return isNullRejectingExpression(expr.m_left, tableAlias) && isNullRejectingExpression(expr.m_right, tableAlias);
    }
    if (exprType == ExpressionType.COMPARE_NOTDISTINCT) {
        return false;
    }
    if (exprType == ExpressionType.OPERATOR_NOT) {
        assert (expr.m_left != null);
        // (switches?) the handling of ANDs and ORs to enforce the above equivalences.
        if (expr.m_left.getExpressionType() == ExpressionType.OPERATOR_IS_NULL) {
            return containsMatchingTVE(expr, tableAlias);
        }
        if (expr.m_left.getExpressionType() == ExpressionType.CONJUNCTION_AND || expr.m_left.getExpressionType() == ExpressionType.CONJUNCTION_OR) {
            assert (expr.m_left.m_left != null && expr.m_left.m_right != null);
            // Need to test for an existing child NOT and skip it.
            // e.g. NOT (P AND NOT Q) --> (NOT P) OR NOT NOT Q --> (NOT P) OR Q
            AbstractExpression tempLeft = null;
            if (expr.m_left.m_left.getExpressionType() != ExpressionType.OPERATOR_NOT) {
                tempLeft = new OperatorExpression(ExpressionType.OPERATOR_NOT, expr.m_left.m_left, null);
            } else {
                assert (expr.m_left.m_left.m_left != null);
                tempLeft = expr.m_left.m_left.m_left;
            }
            AbstractExpression tempRight = null;
            if (expr.m_left.m_right.getExpressionType() != ExpressionType.OPERATOR_NOT) {
                tempRight = new OperatorExpression(ExpressionType.OPERATOR_NOT, expr.m_left.m_right, null);
            } else {
                assert (expr.m_left.m_right.m_left != null);
                tempRight = expr.m_left.m_right.m_left;
            }
            ExpressionType type = (expr.m_left.getExpressionType() == ExpressionType.CONJUNCTION_AND) ? ExpressionType.CONJUNCTION_OR : ExpressionType.CONJUNCTION_AND;
            AbstractExpression tempExpr = new OperatorExpression(type, tempLeft, tempRight);
            return isNullRejectingExpression(tempExpr, tableAlias);
        }
        if (expr.m_left.getExpressionType() == ExpressionType.OPERATOR_NOT) {
            // (like "NOT T.c IS NOT NULL"). Yet, we could also handle them here
            assert (expr.m_left.m_left != null);
            return isNullRejectingExpression(expr.m_left.m_left, tableAlias);
        }
        return isNullRejectingExpression(expr.m_left, tableAlias);
    }
    if (exprType == ExpressionType.COMPARE_NOTDISTINCT) {
        // runtime filters.
        return false;
    }
    if (exprType == ExpressionType.OPERATOR_IS_NULL) {
        // IS NOT NULL is NULL rejecting -- IS NULL is not
        return false;
    }
    if (expr.hasAnySubexpressionOfClass(OperatorExpression.class)) {
        // COALESCE expression is a sub-expression
        // For example, COALESCE (C1, C2) > 0
        List<OperatorExpression> coalesceExprs = expr.findAllSubexpressionsOfClass(OperatorExpression.class);
        for (OperatorExpression coalesceExpr : coalesceExprs) {
            if ((coalesceExpr.getExpressionType() == ExpressionType.OPERATOR_ALTERNATIVE) && containsMatchingTVE(coalesceExpr, tableAlias)) {
                // This table is part of the COALESCE expression - not NULL-rejecting
                return false;
            }
        }
    // If we get there it means that the tableAlias is not part of any of COALESCE expression
    // still need to check the catch all case
    }
    // of reasons and may need special casing here.
    return containsMatchingTVE(expr, tableAlias);
}
Also used : ExpressionType(org.voltdb.types.ExpressionType)

Example 3 with ExpressionType

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

the class ComparisonExpression method getLtFilterFromPrefixLike.

/// Construct the upper bound comparison filter implied by a prefix LIKE comparison.
public ComparisonExpression getLtFilterFromPrefixLike() {
    ExpressionType rangeComparator = ExpressionType.COMPARE_LESSTHAN;
    String comparand = extractAndIncrementLikePatternPrefix();
    return rangeFilterFromPrefixLike(m_left, rangeComparator, comparand);
}
Also used : ExpressionType(org.voltdb.types.ExpressionType)

Example 4 with ExpressionType

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

the class ComparisonExpression method getGteFilterFromPrefixLike.

/// Construct the lower bound comparison filter implied by a prefix LIKE comparison.
public ComparisonExpression getGteFilterFromPrefixLike() {
    ExpressionType rangeComparator = ExpressionType.COMPARE_GREATERTHANOREQUALTO;
    String comparand = extractLikePatternPrefix();
    return rangeFilterFromPrefixLike(m_left, rangeComparator, comparand);
}
Also used : ExpressionType(org.voltdb.types.ExpressionType)

Example 5 with ExpressionType

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

the class ComparisonExpression method reverseOperator.

public ComparisonExpression reverseOperator() {
    ExpressionType reverseType = reverses.get(this.m_type);
    // Left and right exprs are reversed on purpose
    ComparisonExpression reversed = new ComparisonExpression(reverseType, m_right, m_left);
    return reversed;
}
Also used : ExpressionType(org.voltdb.types.ExpressionType)

Aggregations

ExpressionType (org.voltdb.types.ExpressionType)30 AbstractExpression (org.voltdb.expressions.AbstractExpression)16 ArrayList (java.util.ArrayList)6 ComparisonExpression (org.voltdb.expressions.ComparisonExpression)6 JSONException (org.json_voltpatches.JSONException)5 VoltType (org.voltdb.VoltType)5 TupleValueExpression (org.voltdb.expressions.TupleValueExpression)5 Constraint (org.voltdb.catalog.Constraint)4 VoltXMLElement (org.hsqldb_voltpatches.VoltXMLElement)3 Column (org.voltdb.catalog.Column)3 AggregateExpression (org.voltdb.expressions.AggregateExpression)3 ColumnRef (org.voltdb.catalog.ColumnRef)2 MaterializedViewHandlerInfo (org.voltdb.catalog.MaterializedViewHandlerInfo)2 MaterializedViewInfo (org.voltdb.catalog.MaterializedViewInfo)2 OperatorExpression (org.voltdb.expressions.OperatorExpression)2 SelectSubqueryExpression (org.voltdb.expressions.SelectSubqueryExpression)2 WindowFunctionExpression (org.voltdb.expressions.WindowFunctionExpression)2 AbstractPlanNode (org.voltdb.plannodes.AbstractPlanNode)2 AggregatePlanNode (org.voltdb.plannodes.AggregatePlanNode)2 HashAggregatePlanNode (org.voltdb.plannodes.HashAggregatePlanNode)2