Deveel.Data.Sql.GroupOperatorHelper.EvaluateAny C# (CSharp) Метод

EvaluateAny() публичный статический Метод

public static EvaluateAny ( SqlExpressionType plainType, Field ob1, Field ob2, EvaluateContext context ) : Field
plainType SqlExpressionType
ob1 Field
ob2 Field
context Deveel.Data.Sql.Expressions.EvaluateContext
Результат Field
        public static Field EvaluateAny(SqlExpressionType plainType, Field ob1, Field ob2, EvaluateContext context)
        {
            if (ob2.Type is QueryType) {
                // The sub-query plan
                var plan = ((SqlQueryObject)ob2.Value).QueryPlan;
                // Discover the correlated variables for this plan.
                var list = plan.DiscoverQueryReferences(1);

                if (list.Count > 0) {
                    // Set the correlated variables from the IVariableResolver
                    foreach (var variable in list) {
                        variable.Evaluate(context.VariableResolver, context.Request);
                    }

                    // Clear the cache in the context
                    context.Request.Access().ClearCachedTables();
                }

                // Evaluate the plan,
                var t = plan.Evaluate(context.Request);

                // The ANY operation
                var revPlainOp = plainType.Reverse();
                return Field.Boolean(t.AnyRowMatchesColumnValue(0, revPlainOp, ob1));
            }

            if (ob2.Type is ArrayType) {
                var expList = (SqlArray)ob2.Value;
                // Assume there are no matches
                var retVal = Field.BooleanFalse;
                foreach (var exp in expList) {
                    var expItem = exp.Evaluate(context);
                    if (expItem.ExpressionType != SqlExpressionType.Constant)
                        throw new InvalidOperationException();

                    var evalItem = (SqlConstantExpression) expItem;

                    // If null value, return null if there isn't otherwise a match found.
                    if (evalItem.Value.IsNull) {
                        retVal = Field.BooleanNull;
                    } else if (IsTrue(Evaluate(ob1, plainType, evalItem.Value, context/*, false, true*/))) {
                        // If there is a match, the ANY set test is true
                        return Field.BooleanTrue;
                    }
                }
                // No matches, so return either false or NULL.  If there are no matches
                // and no nulls, return false.  If there are no matches and there are
                // nulls present, return null.
                return retVal;
            }

            throw new InvalidOperationException("Unknown RHS of ANY.");
        }

Usage Example

Пример #1
0
        public Field Any(SqlExpressionType type, Field other, EvaluateContext context)
        {
            if (IsNull)
            {
                return(this);
            }

            return(GroupOperatorHelper.EvaluateAny(type, this, other, context));
        }