public SubselectEvalStrategyNRRelOpAnyDefault(
     ExprEvaluator valueEval,
     ExprEvaluator selectEval,
     bool resultWhenNoMatchingEvents,
     RelationalComputer computer,
     ExprEvaluator filterEval)
     : base(valueEval, selectEval, resultWhenNoMatchingEvents, computer)
 {
     _filterEval = filterEval;
 }
 public SubselectEvalStrategyNRRelOpAllWGroupBy(
     ExprEvaluator valueEval,
     ExprEvaluator selectEval,
     bool resultWhenNoMatchingEvents,
     RelationalComputer computer,
     ExprEvaluator havingEval)
     : base(valueEval, selectEval, resultWhenNoMatchingEvents, computer)
 {
     _havingEval = havingEval;
 }
        public override ExprNode Validate(ExprValidationContext validationContext)
        {
            // Must have 2 child nodes
            if (ChildNodes.Count != 2)
            {
                throw new IllegalStateException("Relational op node does not have exactly 2 parameters");
            }
            _evaluators = ExprNodeUtility.GetEvaluators(ChildNodes);

            // Must be either numeric or string
            Type typeOne = _evaluators[0].ReturnType.GetBoxedType();
            Type typeTwo = _evaluators[1].ReturnType.GetBoxedType();
            Type compareType;

            if (typeOne == typeTwo)
            {
                compareType = typeOne;
            }
            else if ((typeOne == typeof(string)) && (typeTwo == typeof(string)))
            {
                compareType = typeof(string);
            }
            else
            {
                try
                {
                    compareType = typeOne.GetCompareToCoercionType(typeTwo);
                }
                catch (CoercionException)
                {
                    if (!typeOne.IsNumeric())
                    {
                        throw new ExprValidationException(
                                  string.Format("Implicit conversion from datatype '{0}' to numeric is not allowed", typeOne.FullName));
                    }
                    else if (!typeTwo.IsNumeric())
                    {
                        throw new ExprValidationException(
                                  string.Format("Implicit conversion from datatype '{0}' to numeric is not allowed", typeTwo.FullName));
                    }
                    else
                    {
                        throw;
                    }
                }
            }

            _computer = _relationalOpEnum.GetComputer(compareType, typeOne, typeTwo);

            return(null);
        }
        public static SubselectEvalStrategyNR CreateStrategyAnyAllIn(ExprSubselectNode subselectExpression,
                                                                     bool isNot,
                                                                     bool isAll,
                                                                     bool isAny,
                                                                     RelationalOpEnum?relationalOp)
        {
            if (subselectExpression.ChildNodes.Count != 1)
            {
                throw new ExprValidationException("The Subselect-IN requires 1 child expression");
            }
            ExprNode valueExpr = subselectExpression.ChildNodes[0];

            // Must be the same boxed type returned by expressions under this
            Type typeOne = subselectExpression.ChildNodes[0].ExprEvaluator.ReturnType.GetBoxedType();

            // collections, array or map not supported
            if ((typeOne.IsArray) ||
                (typeOne.IsImplementsInterface(typeof(ICollection <object>))) ||
                (typeOne.IsImplementsInterface(typeof(IDictionary <string, object>))))
            {
                throw new ExprValidationException("Collection or array comparison is not allowed for the IN, ANY, SOME or ALL keywords");
            }

            Type typeTwo;

            if (subselectExpression.SelectClause != null)
            {
                typeTwo = subselectExpression.SelectClause[0].ExprEvaluator.ReturnType;
            }
            else
            {
                typeTwo = subselectExpression.RawEventType.UnderlyingType;
            }

            bool          aggregated = Aggregated(subselectExpression.SubselectAggregationType);
            bool          grouped    = Grouped(subselectExpression.StatementSpecCompiled.GroupByExpressions);
            ExprEvaluator selectEval = subselectExpression.SelectClause == null ? null : subselectExpression.SelectClause[0].ExprEvaluator;
            ExprEvaluator valueEval  = valueExpr.ExprEvaluator;
            ExprEvaluator filterEval = subselectExpression.FilterExpr;
            ExprEvaluator havingEval = subselectExpression.HavingExpr;

            if (relationalOp != null)
            {
                if ((typeOne != typeof(string)) || (typeTwo != typeof(string)))
                {
                    if (!typeOne.IsNumeric())
                    {
                        throw new ExprValidationException("Implicit conversion from datatype '" + Name.Of(typeOne) + "' to numeric is not allowed");
                    }
                    if (!typeTwo.IsNumeric())
                    {
                        throw new ExprValidationException("Implicit conversion from datatype '" + Name.Of(typeTwo) + "' to numeric is not allowed");
                    }
                }

                Type compareType            = typeOne.GetCompareToCoercionType(typeTwo);
                RelationalComputer computer = relationalOp.Value.GetComputer(compareType, typeOne, typeTwo);

                if (isAny)
                {
                    if (grouped)
                    {
                        return(new SubselectEvalStrategyNRRelOpAnyWGroupBy(valueEval, selectEval, false, computer, havingEval));
                    }
                    if (aggregated)
                    {
                        return(new SubselectEvalStrategyNRRelOpAllAnyAggregated(valueEval, selectEval, false, computer, havingEval));
                    }
                    return(new SubselectEvalStrategyNRRelOpAnyDefault(valueEval, selectEval, false, computer, filterEval));
                }

                // handle ALL
                if (grouped)
                {
                    return(new SubselectEvalStrategyNRRelOpAllWGroupBy(valueEval, selectEval, true, computer, havingEval));
                }
                if (aggregated)
                {
                    return(new SubselectEvalStrategyNRRelOpAllAnyAggregated(valueEval, selectEval, true, computer, havingEval));
                }
                return(new SubselectEvalStrategyNRRelOpAllDefault(valueEval, selectEval, true, computer, filterEval));
            }

            Coercer coercer = GetCoercer(typeOne, typeTwo);

            if (isAll)
            {
                if (grouped)
                {
                    return(new SubselectEvalStrategyNREqualsAllWGroupBy(valueEval, selectEval, true, isNot, coercer, havingEval));
                }
                if (aggregated)
                {
                    return(new SubselectEvalStrategyNREqualsAllAnyAggregated(valueEval, selectEval, true, isNot, coercer, havingEval));
                }
                return(new SubselectEvalStrategyNREqualsAllDefault(valueEval, selectEval, true, isNot, coercer, filterEval));
            }
            else if (isAny)
            {
                if (grouped)
                {
                    return(new SubselectEvalStrategyNREqualsAnyWGroupBy(valueEval, selectEval, false, isNot, coercer, havingEval));
                }
                if (aggregated)
                {
                    return(new SubselectEvalStrategyNREqualsAllAnyAggregated(valueEval, selectEval, true, isNot, coercer, havingEval));
                }
                return(new SubselectEvalStrategyNREqualsAnyDefault(valueEval, selectEval, false, isNot, coercer, filterEval));
            }
            else
            {
                if (grouped)
                {
                    return(new SubselectEvalStrategyNREqualsInWGroupBy(valueEval, selectEval, isNot, coercer, havingEval));
                }
                if (aggregated)
                {
                    return(new SubselectEvalStrategyNREqualsInAggregated(valueEval, selectEval, isNot, coercer, havingEval));
                }
                if (filterEval == null)
                {
                    return(new SubselectEvalStrategyNREqualsInUnfiltered(valueEval, selectEval, isNot, coercer));
                }
                return(new SubselectEvalStrategyNREqualsInFiltered(valueEval, selectEval, isNot, coercer, filterEval));
            }
        }
        public override ExprNode Validate(ExprValidationContext validationContext)
        {
            // Must have 2 child nodes
            var childNodes = ChildNodes;

            if (childNodes.Count < 1)
            {
                throw new IllegalStateException("Group relational op node must have 1 or more parameters");
            }

            _evaluators = ExprNodeUtility.GetEvaluators(childNodes);

            var typeOne = _evaluators[0].ReturnType.GetBoxedType();

            // collections, array or map not supported
            if ((typeOne.IsArray) ||
                (typeOne.IsGenericCollection()) ||
                (typeOne.IsGenericDictionary()))
            {
                throw new ExprValidationException(
                          "Collection or array comparison is not allowed for the IN, ANY, SOME or ALL keywords");
            }

            _transformList = new Func <object, object> [childNodes.Count];

            var comparedTypes = new List <Type>();

            comparedTypes.Add(typeOne);
            _hasCollectionOrArray = false;
            for (int i = 1; i < childNodes.Count; i++)
            {
                var propType = _evaluators[i].ReturnType;
                if (propType.IsArray)
                {
                    _hasCollectionOrArray = true;
                    if (propType.GetElementType() != typeof(Object))
                    {
                        comparedTypes.Add(propType.GetElementType());
                    }
                }
                else if (propType.IsGenericDictionary())
                {
                    var baseTransform = MagicMarker.GetDictionaryFactory(propType);
                    _transformList[i]     = o => baseTransform(o);
                    _hasCollectionOrArray = true;
                }
                else if (propType.IsGenericCollection())
                {
                    var baseTransform = MagicMarker.GetCollectionFactory(propType);
                    _transformList[i]     = o => baseTransform(o);
                    _hasCollectionOrArray = true;
                }
                else
                {
                    comparedTypes.Add(propType);
                }
            }

            // Determine common denominator type
            Type coercionType;

            try
            {
                coercionType = TypeHelper.GetCommonCoercionType(comparedTypes.ToArray());
            }
            catch (CoercionException ex)
            {
                throw new ExprValidationException("Implicit conversion not allowed: " + ex.Message);
            }

            // Must be either numeric or string
            if (coercionType != typeof(String))
            {
                if (!coercionType.IsNumeric())
                {
                    throw new ExprValidationException(string.Format("Implicit conversion from datatype '{0}' to numeric is not allowed", Name.Clean(coercionType)));
                }
            }

            _computer = _relationalOp.GetComputer(coercionType, coercionType, coercionType);

            return(null);
        }
Example #6
0
 protected SubselectEvalStrategyNRRelOpBase(ExprEvaluator valueEval, ExprEvaluator selectEval, bool resultWhenNoMatchingEvents, RelationalComputer computer)
     : base(valueEval, selectEval, resultWhenNoMatchingEvents)
 {
     Computer = computer;
 }