コード例 #1
0
        public override bool Equals(object obj)
        {
            if (this == obj)
            {
                return true;
            }

            if (!(obj is FilterForEvalEventPropIndexedMayCoerce))
            {
                return false;
            }

            FilterForEvalEventPropIndexedMayCoerce other = (FilterForEvalEventPropIndexedMayCoerce)obj;
            if ((other._resultEventAsName.Equals(this._resultEventAsName)) &&
                (other._resultEventProperty.Equals(this._resultEventProperty)))
            {
                return true;
            }

            return false;
        }
コード例 #2
0
        private static FilterSpecParam HandleInSetNode(
            ExprInNode constituent,
            IDictionary <string, Pair <EventType, string> > arrayEventTypes,
            ExprEvaluatorContext exprEvaluatorContext,
            string statementName)
        {
            var left = constituent.ChildNodes[0];

            if (!(left is ExprFilterOptimizableNode))
            {
                return(null);
            }

            var filterOptimizableNode = (ExprFilterOptimizableNode)left;
            var lookupable            = filterOptimizableNode.FilterLookupable;
            var op = FilterOperator.IN_LIST_OF_VALUES;

            if (constituent.IsNotIn)
            {
                op = FilterOperator.NOT_IN_LIST_OF_VALUES;
            }

            var expectedNumberOfConstants = constituent.ChildNodes.Count - 1;
            var listofValues = new List <FilterSpecParamInValue>();
            var enumerator   = constituent.ChildNodes.GetEnumerator();

            enumerator.MoveNext();  // ignore the first node as it's the identifier
            while (enumerator.MoveNext())
            {
                ExprNode subNode = enumerator.Current;
                if (ExprNodeUtility.IsConstantValueExpr(subNode))
                {
                    var constantNode = (ExprConstantNode)subNode;
                    var constant     = constantNode.GetConstantValue(exprEvaluatorContext);
                    if (constant is Array asArray)
                    {
                        for (var i = 0; i < asArray.Length; i++)
                        {
                            var arrayElement        = asArray.GetValue(i);
                            var arrayElementCoerced = HandleConstantsCoercion(lookupable, arrayElement);
                            listofValues.Add(new FilterForEvalConstantAnyType(arrayElementCoerced));
                            if (i > 0)
                            {
                                expectedNumberOfConstants++;
                            }
                        }
                    }
                    else if (constant is ICollection <object> )
                    {
                        return(null);
                    }
                    else if (constant is IDictionary <string, object> )
                    {
                        return(null);
                    }
                    else
                    {
                        constant = HandleConstantsCoercion(lookupable, constant);
                        listofValues.Add(new FilterForEvalConstantAnyType(constant));
                    }
                }
                if (subNode is ExprContextPropertyNode)
                {
                    var     contextPropertyNode = (ExprContextPropertyNode)subNode;
                    var     returnType          = contextPropertyNode.ReturnType;
                    Coercer coercer;
                    Type    coercerType;
                    if (returnType.IsCollectionMapOrArray())
                    {
                        CheckArrayCoercion(returnType, lookupable.ReturnType, lookupable.Expression);
                        coercer     = null;
                        coercerType = null;
                    }
                    else
                    {
                        coercer = GetNumberCoercer(
                            left.ExprEvaluator.ReturnType,
                            contextPropertyNode.ReturnType,
                            lookupable.Expression,
                            out coercerType);
                    }
                    var finalReturnType = coercer != null ? coercerType : returnType;
                    listofValues.Add(new FilterForEvalContextPropMayCoerce(contextPropertyNode.PropertyName, contextPropertyNode.Getter, coercer, finalReturnType));
                }
                if (subNode is ExprIdentNode)
                {
                    var identNodeInner = (ExprIdentNode)subNode;
                    if (identNodeInner.StreamId == 0)
                    {
                        break; // for same event evals use the bool expression, via count compare failing below
                    }

                    var isMustCoerce    = false;
                    var coerceToType    = lookupable.ReturnType.GetBoxedType();
                    var identReturnType = identNodeInner.ExprEvaluator.ReturnType;

                    if (identReturnType.IsCollectionMapOrArray())
                    {
                        CheckArrayCoercion(identReturnType, lookupable.ReturnType, lookupable.Expression);
                        coerceToType = identReturnType;
                        // no action
                    }
                    else if (identReturnType != lookupable.ReturnType)
                    {
                        if (lookupable.ReturnType.IsNumeric())
                        {
                            if (!identReturnType.CanCoerce(lookupable.ReturnType))
                            {
                                ThrowConversionError(identReturnType, lookupable.ReturnType, lookupable.Expression);
                            }
                            isMustCoerce = true;
                        }
                        else
                        {
                            break;  // assumed not compatible
                        }
                    }

                    FilterSpecParamInValue inValue;
                    var streamName = identNodeInner.ResolvedStreamName;
                    if (arrayEventTypes != null && !arrayEventTypes.IsEmpty() && arrayEventTypes.ContainsKey(streamName))
                    {
                        var indexAndProp = GetStreamIndex(identNodeInner.ResolvedPropertyName);
                        inValue = new FilterForEvalEventPropIndexedMayCoerce(identNodeInner.ResolvedStreamName, indexAndProp.First,
                                                                             indexAndProp.Second, isMustCoerce, coerceToType, statementName);
                    }
                    else
                    {
                        inValue = new FilterForEvalEventPropMayCoerce(identNodeInner.ResolvedStreamName, identNodeInner.ResolvedPropertyName, isMustCoerce, coerceToType);
                    }

                    listofValues.Add(inValue);
                }
            }

            // Fallback if not all values in the in-node can be resolved to properties or constants
            if (listofValues.Count == expectedNumberOfConstants)
            {
                return(new FilterSpecParamIn(lookupable, op, listofValues));
            }
            return(null);
        }