/// <summary>
 ///     Ctor.
 /// </summary>
 /// <param name="convOne">convertor for LHS</param>
 /// <param name="convTwo">convertor for RHS</param>
 public SubtractDecimalConvComputer(
     Coercer convOne,
     Coercer convTwo)
 {
     this.convOne = convOne;
     this.convTwo = convTwo;
 }
 /// <summary>
 ///     Ctor.
 /// </summary>
 /// <param name="convOne">conversion for LHS</param>
 /// <param name="convTwo">conversion for RHS</param>
 public MultiplyDecimalConvComputer(
     Coercer convOne,
     Coercer convTwo)
 {
     this.convOne = convOne;
     this.convTwo = convTwo;
 }
        /// <summary>
        ///     Constructor.
        /// </summary>
        /// <param name="lookupable">is the lookupable</param>
        /// <param name="filterOperator">is the type of compare</param>
        /// <param name="resultEventAsName">is the name of the result event from which to get a property value to compare</param>
        /// <param name="resultEventProperty">is the name of the property to get from the named result event</param>
        /// <param name="isMustCoerce">indicates on whether numeric coercion must be performed</param>
        /// <param name="coercionType">indicates the numeric coercion type to use</param>
        /// <param name="numberCoercer">interface to use to perform coercion</param>
        /// <param name="resultEventIndex">index</param>
        /// <param name="statementName">statement name</param>
        /// <param name="eventType">event type</param>
        /// <throws>ArgumentException if an operator was supplied that does not take a single constant value</throws>
        public FilterSpecParamEventPropIndexedForge(
            ExprFilterSpecLookupableForge lookupable,
            FilterOperator filterOperator,
            string resultEventAsName,
            int resultEventIndex,
            string resultEventProperty,
            EventType eventType,
            bool isMustCoerce,
            Coercer numberCoercer,
            Type coercionType,
            string statementName)
            : base(lookupable, filterOperator)
        {
            ResultEventAsName = resultEventAsName;
            ResultEventIndex = resultEventIndex;
            ResultEventProperty = resultEventProperty;
            EventType = eventType;
            IsMustCoerce = isMustCoerce;
            _numberCoercer = numberCoercer;
            CoercionType = coercionType;
            _statementName = statementName;

            if (filterOperator.IsRangeOperator()) {
                throw new ArgumentException(
                    "Illegal filter operator " +
                    filterOperator +
                    " supplied to " +
                    "event property filter parameter");
            }
        }
        private static FilterSpecParamEventProp MakeParam(String eventAsName, String property)
        {
            Coercer numberCoercer = CoercerFactory.GetCoercer(typeof(int), typeof(int));

            return(new FilterSpecParamEventProp(MakeLookupable("IntPrimitive"), FilterOperator.EQUAL, eventAsName,
                                                property, false, numberCoercer, typeof(int), "Test"));
        }
 public DivideDecimalConvComputerNoMathCtx(
     Coercer convOne,
     Coercer convTwo,
     bool divisionByZeroReturnsNull)
     : base(convOne, convTwo, divisionByZeroReturnsNull)
 {
 }
 public FilterSpecParamContextProp(FilterSpecLookupable lookupable, FilterOperator filterOperator, String contextPropertyName, EventPropertyGetter getter, Coercer numberCoercer)
     : base(lookupable, filterOperator)
 {
     _contextPropertyName = contextPropertyName;
     _getter        = getter;
     _numberCoercer = numberCoercer;
 }
Example #7
0
        private IDictionary <string, object> CreateMapFromRow(string[] row)
        {
            var map = new Dictionary <string, object>();

            var count = 0;

            try
            {
                foreach (var property in _propertyOrder)
                {
                    // Skip properties that are in the title row but not
                    // part of the map to send
                    if ((_propertyTypes != null) &&
                        (!_propertyTypes.ContainsKey(property)) &&
                        (!property.Equals(_adapterSpec.TimestampColumn)))
                    {
                        count++;
                        continue;
                    }

                    var value = Coercer.Coerce(property, row[count++]);
                    map.Put(property, value);
                }
            }
            catch (Exception e)
            {
                throw new EPException(e);
            }

            return(map);
        }
 /// <summary>
 ///     Ctor.
 /// </summary>
 /// <param name="convOne">conversion for LHS</param>
 /// <param name="convTwo">conversion for RHS</param>
 public AddDecimalConvComputer(
     Coercer convOne,
     Coercer convTwo)
 {
     this._convOne = convOne;
     this._convTwo = convTwo;
 }
Example #9
0
        public override Object Evaluate(EvaluateParams evaluateParams)
        {
            var scriptArgs = new ScriptArgs();
            var bindings   = new Dictionary <string, object>();

            bindings.Put(ExprNodeScript.CONTEXT_BINDING_NAME, evaluateParams.ExprEvaluatorContext.AgentInstanceScriptContext);
            for (int i = 0; i < Names.Length; i++)
            {
                bindings.Put(Names[i], Parameters[i].Evaluate(evaluateParams));
            }

            scriptArgs.Bindings = bindings;

            try
            {
                var result = _scriptAction.Invoke(scriptArgs);

                if (Coercer != null)
                {
                    result = Coercer.Invoke(result);
                }

                return(result);
            }
            catch (Exception e)
            {
                String message = "Unexpected exception executing script '" + ScriptName + "' for statement '" + StatementName + "' : " + e.Message;
                Log.Error(message, e);
                throw new EPException(message, e);
            }
        }
Example #10
0
 public InSetOfValuesContextProp(String propertyName, EventPropertyGetter getter, Coercer coercer, Type returnType)
 {
     _propertyName = propertyName;
     _getter = getter;
     _numberCoercer = coercer;
     _returnType = returnType;
 }
 public SubselectEvalStrategyNREqualsInUnfiltered(
     ExprEvaluator valueEval,
     ExprEvaluator selectEval,
     bool notIn,
     Coercer coercer)
     : base(valueEval, selectEval, notIn, coercer)
 {
 }
 public FilterForEvalContextPropMayCoerce(string propertyName, EventPropertyGetter getter, Coercer coercer,
     Type returnType)
 {
     _propertyName = propertyName;
     _getter = getter;
     _numberCoercer = coercer;
     _returnType = returnType;
 }
Example #13
0
 public ExprEqualsEvaluatorCoercingArray(ExprEqualsNodeImpl parent, ExprEvaluator lhs, ExprEvaluator rhs, Coercer coercerLHS, Coercer coercerRHS)
 {
     _parent     = parent;
     _lhs        = lhs;
     _rhs        = rhs;
     _coercerLHS = coercerLHS;
     _coercerRHS = coercerRHS;
 }
Example #14
0
 public ExprEqualsEvaluatorCoercing(ExprEqualsNodeImpl parent, ExprEvaluator lhs, ExprEvaluator rhs, Coercer numberCoercerLHS, Coercer numberCoercerRHS)
 {
     _parent           = parent;
     _lhs              = lhs;
     _rhs              = rhs;
     _numberCoercerLHS = numberCoercerLHS;
     _numberCoercerRHS = numberCoercerRHS;
 }
Example #15
0
        internal static Pair<ExprForge[], ExprEvaluator[]> MakeVarargArrayEval(
            MethodInfo method,
            ExprForge[] childForges)
        {
            var methodParameterTypes = method.GetParameterTypes();
            ExprEvaluator[] evals = new ExprEvaluator[methodParameterTypes.Length];
            ExprForge[] forges = new ExprForge[methodParameterTypes.Length];
            Type varargClass = methodParameterTypes[methodParameterTypes.Length - 1].GetElementType();
            Type varargClassBoxed = varargClass.GetBoxedType();
            if (methodParameterTypes.Length > 1) {
                Array.Copy(childForges, 0, forges, 0, forges.Length - 1);
            }

            int varargArrayLength = childForges.Length - methodParameterTypes.Length + 1;

            // handle passing array along
            if (varargArrayLength == 1) {
                ExprForge lastForge = childForges[methodParameterTypes.Length - 1];
                Type lastReturns = lastForge.EvaluationType;
                if (lastReturns != null && lastReturns.IsArray) {
                    forges[methodParameterTypes.Length - 1] = lastForge;
                    return new Pair<ExprForge[], ExprEvaluator[]>(forges, evals);
                }
            }

            // handle parameter conversion to vararg parameter
            ExprForge[] varargForges = new ExprForge[varargArrayLength];
            Coercer[] coercers = new Coercer[varargForges.Length];
            bool needCoercion = false;
            for (int i = 0; i < varargArrayLength; i++) {
                int childIndex = i + methodParameterTypes.Length - 1;
                Type resultType = childForges[childIndex].EvaluationType;
                varargForges[i] = childForges[childIndex];

                if (resultType == null && varargClass.CanBeNull()) {
                    continue;
                }

                if (TypeHelper.IsSubclassOrImplementsInterface(resultType, varargClass)) {
                    // no need to coerce
                    continue;
                }

                if (resultType.GetBoxedType() != varargClassBoxed) {
                    needCoercion = true;
                    coercers[i] = SimpleNumberCoercerFactory.GetCoercer(resultType, varargClassBoxed);
                }
            }

            ExprForge varargForge = new ExprNodeVarargOnlyArrayForge(
                varargForges,
                varargClass,
                needCoercion ? coercers : null);
            forges[methodParameterTypes.Length - 1] = varargForge;
            evals[methodParameterTypes.Length - 1] = varargForge.ExprEvaluator;
            return new Pair<ExprForge[], ExprEvaluator[]>(forges, evals);
        }
Example #16
0
 public ScriptEvaluatorLambda(
     string scriptName,
     string[] parameterNames,
     ExprEvaluator[] parameters,
     Coercer coercer,
     ExpressionScriptCompiled compiled) : base(scriptName, parameterNames, parameters, coercer)
 {
     _scriptAction = compiled.ScriptAction;
 }
 public FilterForEvalDeployTimeConstForge(
     ExprNodeDeployTimeConst deployTimeConst,
     Coercer numberCoercer,
     Type returnType)
 {
     _deployTimeConst = deployTimeConst;
     _numberCoercer = numberCoercer;
     _returnType = returnType;
 }
 public FilterForEvalLimitedExprForge(
     ExprNode value,
     MatchedEventConvertorForge convertor,
     Coercer numberCoercer)
 {
     this.value = value;
     this.convertor = convertor;
     this.numberCoercer = numberCoercer;
 }
 public DivideDecimalConvComputerWithMathCtx(
     Coercer convOne,
     Coercer convTwo,
     bool divisionByZeroReturnsNull,
     MathContext mathContext)
     : base(convOne, convTwo, divisionByZeroReturnsNull)
 {
     _mathContext = mathContext;
 }
 /// <summary>
 ///     Ctor.
 /// </summary>
 /// <param name="convOne">convertor for LHS</param>
 /// <param name="convTwo">convertor for RHS</param>
 /// <param name="divisionByZeroReturnsNull">false for division-by-zero returns infinity, true for null</param>
 protected DivideDecimalConvComputerBase(
     Coercer convOne,
     Coercer convTwo,
     bool divisionByZeroReturnsNull)
 {
     _convOne = convOne;
     _convTwo = convTwo;
     _divisionByZeroReturnsNull = divisionByZeroReturnsNull;
 }
 public ExprEqualsNodeForgeCoercion(
     ExprEqualsNodeImpl parent,
     Coercer coercerLhs,
     Coercer coercerRhs)
     : base(parent)
 {
     CoercerLHS = coercerLhs;
     CoercerRHS = coercerRhs;
 }
Example #22
0
 /// <summary>Ctor. </summary>
 /// <param name="streamNum">is the stream number of the indexed stream</param>
 /// <param name="eventType">is the event type of the indexed stream</param>
 /// <param name="propertyName">are the property names to get property values</param>
 /// <param name="coercionType">are the classes to coerce indexed values to</param>
 public PropertyIndexedEventTableSingleCoerceAddFactory(
     int streamNum,
     EventType eventType,
     String propertyName,
     Type coercionType)
     : base(streamNum, eventType, propertyName, false, null)
 {
     CoercionType = coercionType;
     Coercer      = coercionType.IsNumeric() ? CoercerFactory.GetCoercer(null, coercionType) : null;
 }
Example #23
0
 protected SubselectEvalStrategyNREqualsInBase(
     ExprEvaluator valueEval,
     ExprEvaluator selectEval,
     bool notIn,
     Coercer coercer)
     : base(valueEval, selectEval, notIn)
 {
     IsNotIn = notIn;
     Coercer = coercer;
 }
 public SubselectEvalStrategyNREqualsInWGroupBy(
     ExprEvaluator valueEval,
     ExprEvaluator selectEval,
     bool notIn,
     Coercer coercer,
     ExprEvaluator havingEval)
     : base(valueEval, selectEval, notIn, coercer)
 {
     _havingEval = havingEval;
 }
Example #25
0
 public ScriptEvaluatorBase(
     string scriptName,
     string[] parameterNames,
     ExprEvaluator[] parameters,
     Coercer coercer)
 {
     this.scriptName = scriptName;
     this.parameterNames = parameterNames;
     this.parameters = parameters;
     this.coercer = coercer;
 }
 public SubselectEvalStrategyNREqualsAllDefault(
     ExprEvaluator valueEval,
     ExprEvaluator selectEval,
     bool resultWhenNoMatchingEvents,
     bool notIn,
     Coercer coercer,
     ExprEvaluator filterEval)
     : base(valueEval, selectEval, resultWhenNoMatchingEvents, notIn, coercer)
 {
     this._filterEval = filterEval;
 }
Example #27
0
 public SubselectEvalStrategyNREqualsAllAnyAggregated(
     ExprEvaluator valueEval,
     ExprEvaluator selectEval,
     bool resultWhenNoMatchingEvents,
     bool notIn,
     Coercer coercer,
     ExprEvaluator havingEval)
     : base(valueEval, selectEval, resultWhenNoMatchingEvents, notIn, coercer)
 {
     _havingEval = havingEval;
 }
Example #28
0
 public SubselectForgeNREqualsIn(
     ExprSubselectNode subselect,
     ExprForge valueEval,
     ExprForge selectEval,
     bool resultWhenNoMatchingEvents,
     bool isNotIn,
     Coercer coercer,
     ExprForge filterEval)
     : base(subselect, valueEval, selectEval, resultWhenNoMatchingEvents, isNotIn, coercer)
 {
     this.filterEval = filterEval;
 }
 public SubselectForgeNREqualsInAggregated(
     ExprSubselectNode subselect,
     ExprForge valueEval,
     ExprForge selectEval,
     bool resultWhenNoMatchingEvents,
     bool isNotIn,
     Coercer coercer,
     ExprForge havingEval)
     : base(subselect, valueEval, selectEval, resultWhenNoMatchingEvents, isNotIn, coercer)
 {
     this.havingEval = havingEval;
 }
Example #30
0
 public FilterSpecParamValueLimitedExprForge(
     ExprFilterSpecLookupableForge lookupable,
     FilterOperator filterOperator,
     ExprNode value,
     MatchedEventConvertorForge convertor,
     Coercer numberCoercer)
     : base(lookupable, filterOperator)
 {
     this._value         = value;
     this._convertor     = convertor;
     this._numberCoercer = numberCoercer;
 }
Example #31
0
    public virtual Expression CoercionToIEnumerable(Expression source, TypeNode sourceType, TypeNode targetType, bool explicitCoercion, TypeViewer typeViewer){
      if (source == null || sourceType == null || targetType == null) return null;
      if (sourceType == SystemTypes.Object) return null;
      SourceContext sctx = source.SourceContext;
      TypeNode sElementType = this.GetStreamElementType(sourceType, typeViewer);
      TypeNode tElementType = this.GetStreamElementType(targetType, typeViewer);
      if (!explicitCoercion && !this.ImplicitCoercionFromTo(sElementType, tElementType, typeViewer)){
        if (tElementType is TupleType && sourceType is TupleType)
          sElementType = sourceType;
        else
          return null;
      }
      //S[] -> T*
      if (sourceType is ArrayType) return null; //TODO: provide a wrapper
      //S- -> S
      if (sourceType.Template == SystemTypes.GenericInvariant){
        source = new MethodCall(new MemberBinding(null, TypeViewer.GetTypeView(typeViewer, sourceType).GetMethod(StandardIds.opImplicit, sourceType)), 
          new ExpressionList(source), NodeType.Call, sElementType);
        sourceType = sElementType;
      }
      //S -> S?
      if (sElementType == sourceType){
        sourceType = SystemTypes.GenericBoxed.GetTemplateInstance(this.currentType, sourceType);
        if (sourceType == null) return null;
        source = this.ImplicitCoercion(source, sourceType, typeViewer);
        if (source == null) return null;
      }
      // (S! | S? | S+ | S*) -> T*
      TypeNode sStreamType = SystemTypes.GenericIEnumerable.GetTemplateInstance(this.currentType, sElementType);
      if (sStreamType == null) return null;
      Debug.Assert(TypeViewer.GetTypeView(typeViewer, sourceType).IsAssignableTo(sStreamType));
      if (sStreamType == targetType){
        if (sourceType.IsValueType)
          source = new BinaryExpression(source, new MemberBinding(null, sourceType), NodeType.Box, targetType);
        return source;
      }

      Coercer coercer = null;
      if (explicitCoercion)
        coercer = new Coercer(this.ExplicitCoercionAdapter);
      else
        coercer = new Coercer(this.ImplicitCoercionAdapter);
      TypeNode streamAdapter = StreamAdapter.For((Interface)sStreamType, (Interface)targetType, this.currentType, coercer, sctx);
      if (streamAdapter == null) return null;
      if (sourceType.IsValueType)
        source = new BinaryExpression(source, new MemberBinding(null, sourceType), NodeType.Box, targetType);
      return new Construct(new MemberBinding(null, TypeViewer.GetTypeView(typeViewer, streamAdapter).GetConstructor(sStreamType)), new ExpressionList(source), targetType);
    }
Example #32
0
 public virtual Expression CoercionToNonEmptyIEnumerable(Expression source, TypeNode sourceType, TypeNode targetType, bool explicitCoercion, TypeViewer typeViewer){
   if (source == null || sourceType == null || targetType == null) return null;
   if (sourceType == SystemTypes.Object) return null;
   TypeNode sElementType = this.GetStreamElementType(sourceType, typeViewer);
   TypeNode tElementType = this.GetStreamElementType(targetType, typeViewer);
   if (!explicitCoercion && !this.ImplicitCoercionFromTo(sElementType, tElementType, typeViewer)) return null;
   //S- -> S -> T -> T+
   if (sourceType.Template == SystemTypes.GenericInvariant){
     source = new MethodCall(new MemberBinding(null, TypeViewer.GetTypeView(typeViewer, sourceType).GetMethod(StandardIds.opImplicit, sourceType)), 
       new ExpressionList(source), NodeType.Call, sElementType);
     if (explicitCoercion)
       source = this.ExplicitCoercion(source, tElementType, typeViewer);
     else
       source = this.ImplicitCoercion(source, tElementType, typeViewer);
     if (source == null) return null;
     return new Construct(new MemberBinding(null, TypeViewer.GetTypeView(typeViewer, targetType).GetConstructor(tElementType)), new ExpressionList(source), targetType);
   }
   //S -> S+ (if explicit or value type)
   if (sElementType == sourceType){
     if (!sourceType.IsValueType && !explicitCoercion) return null;
     if (sourceType != tElementType) source = this.ExplicitCoercion(source, tElementType, typeViewer);
     if (source == null) return null;
     return new Construct(new MemberBinding(null, TypeViewer.GetTypeView(typeViewer, targetType).GetConstructor(tElementType)), new ExpressionList(source), targetType);
   }
   // S* -> S+ (if explicit)
   if (sourceType.Template != SystemTypes.GenericNonEmptyIEnumerable && !explicitCoercion)
     //TODO: handle new T[] and new T{}
     return null;
   TypeNode sStreamType = SystemTypes.GenericIEnumerable.GetTemplateInstance(this.currentType, sElementType);
   Debug.Assert(TypeViewer.GetTypeView(typeViewer, sourceType).IsAssignableTo(sStreamType));
   TypeNode tStreamType = SystemTypes.GenericIEnumerable.GetTemplateInstance(this.currentType, tElementType);
   if (sStreamType != tStreamType){
     Coercer coercer = null;
     if (explicitCoercion)
       coercer = new Coercer(this.ExplicitCoercion);
     else
       coercer = new Coercer(this.ImplicitCoercion);
     TypeNode streamAdaptor = StreamAdapter.For((Interface)sStreamType, (Interface)tStreamType, this.currentType, coercer, source.SourceContext);
     if (streamAdaptor == null) return null;
     source = new Construct(new MemberBinding(null, TypeViewer.GetTypeView(typeViewer, streamAdaptor).GetConstructor(sStreamType)), new ExpressionList(source), tStreamType);
   }
   return new Construct(new MemberBinding(null, TypeViewer.GetTypeView(typeViewer, targetType).GetConstructor(tStreamType)), new ExpressionList(source), targetType);
 }