Example #1
0
        private bool? EvaluateInternal(
            EventBean[] eventsPerStream,
            bool isNewData,
            ExprEvaluatorContext context)
        {
            var leftResult = _lhs.Evaluate(eventsPerStream, isNewData, context);
            var rightResult = _rhs.Evaluate(eventsPerStream, isNewData, context);

            if (!_parent.IsIs) {
                if (leftResult == null || rightResult == null) {
                    // null comparison
                    return null;
                }
            }
            else {
                if (leftResult == null) {
                    return rightResult == null;
                }

                if (rightResult == null) {
                    return false;
                }
            }

            var left = _coercerLhs.CoerceBoxed(leftResult);
            var right = _coercerRhs.CoerceBoxed(rightResult);
            return left.Equals(right) ^ _parent.IsNotEquals;
        }
            public object Compute(
                object d1,
                object d2)
            {
                decimal s1 = convOne.CoerceBoxed(d1).AsDecimal();
                decimal s2 = convTwo.CoerceBoxed(d2).AsDecimal();

                return(s1 - s2);
            }
Example #3
0
        public object GetFilterValue(
            MatchedEventMap matchedEvents,
            ExprEvaluatorContext evaluatorContext)
        {
            if (evaluatorContext.ContextProperties == null) {
                return null;
            }

            var result = _getter.Get(evaluatorContext.ContextProperties);

            if (_numberCoercer == null) {
                return result;
            }

            return _numberCoercer.CoerceBoxed(result);
        }
Example #4
0
        public object EvaluateInternal(ScriptArgs scriptArgs)
        {
            try {
                var result = _scriptAction.Invoke(scriptArgs);
                if (Coercer != null)
                {
                    result = Coercer.CoerceBoxed(result);
                }

                return(result);
            }
            catch (Exception e) {
                string message = "Unexpected exception executing script '" + ScriptName + "': " + e.Message;
                Log.Error(message, e);
                throw new EPException(message, e);
            }
        }
            public object Compute(
                object d1,
                object d2)
            {
                decimal s1 = _convOne.CoerceBoxed(d1).AsDecimal();
                decimal s2 = _convTwo.CoerceBoxed(d2).AsDecimal();

                if (s2 == 0.0m)
                {
                    if (_divisionByZeroReturnsNull)
                    {
                        return(null);
                    }

                    var result = s1.AsDouble() / 0;
                    return(new decimal(result));
                }

                return(DoDivide(s1, s2));
            }
Example #6
0
        public override ExprNode Validate(ExprValidationContext validationContext)
        {
            var length = ChildNodes.Length;

            // Can be an empty array with no content
            if (ChildNodes.Length == 0) {
                forge = new ExprArrayNodeForge(this, typeof(object), CollectionUtil.OBJECTARRAY_EMPTY);
                return null;
            }

            IList<Type> comparedTypes = new List<Type>();
            for (var i = 0; i < length; i++) {
                comparedTypes.Add(ChildNodes[i].Forge.EvaluationType);
            }

            // Determine common denominator type
            Type arrayReturnType = null;
            var mustCoerce = false;
            Coercer coercer = null;
            try {
                arrayReturnType = TypeHelper.GetCommonCoercionType(comparedTypes.ToArray());

                // Determine if we need to coerce numbers when one type doesn't match any other type
                if (arrayReturnType.IsNumeric()) {
                    mustCoerce = false;
                    foreach (var comparedType in comparedTypes) {
                        if (comparedType != arrayReturnType) {
                            mustCoerce = true;
                        }
                    }

                    if (mustCoerce) {
                        coercer = SimpleNumberCoercerFactory.GetCoercer(null, arrayReturnType);
                    }
                }
            }
            catch (CoercionException) {
                // expected, such as mixing String and int values, or types (not boxed) and primitives
                // use Object[] in such cases
            }

            if (arrayReturnType == null) {
                arrayReturnType = typeof(object);
            }

            // Determine if we are dealing with constants only
            var results = new object[length];
            var index = 0;
            foreach (var child in ChildNodes) {
                if (!child.Forge.ForgeConstantType.IsCompileTimeConstant) {
                    results = null; // not using a constant result
                    break;
                }

                results[index] = ChildNodes[index].Forge.ExprEvaluator.Evaluate(null, false, null);
                index++;
            }

            // Copy constants into array and coerce, if required
            Array constantResult = null;
            if (results != null) {
                constantResult = Array.CreateInstance(arrayReturnType, length);
                for (var i = 0; i < length; i++) {
                    if (mustCoerce) {
                        var boxed = results[i];
                        if (boxed != null) {
                            object coercedResult = coercer.CoerceBoxed(boxed);
                            constantResult.SetValue(coercedResult, i);
                        }
                    }
                    else {
                        constantResult.SetValue(results[i], i);
                    }
                }
            }

            forge = new ExprArrayNodeForge(this, arrayReturnType, mustCoerce, coercer, constantResult);
            return null;
        }