Esempio n. 1
0
        /// <summary>
        /// Generates a view that includes only the most recent among events having the same value for
        /// the result of the sepcified list of properties.
        /// <para />
        /// This view acts as a length window of size 1 for each distinct value returned by a property, or combination
        /// of values returned by multiple properties.  It thus posts as old events the prior event of the same value(s),
        /// if any.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="esperQuery">The esper query.</param>
        /// <param name="expressions">The expressions.</param>
        /// <returns></returns>
        /// <exception cref="System.ArgumentException">at least one property must be provided</exception>
        public static EsperQuery <T> Unique <T>(this EsperQuery <T> esperQuery, params System.Linq.Expressions.Expression <Func <T, object> >[] expressions)
        {
            if (expressions == null)
            {
                throw new ArgumentException("at least one property must be provided");
            }

            return(esperQuery.FilterView(() => View.Create("unique",
                                                           expressions.Select(e => LinqToSoda.LinqToSodaExpression(e)).ToArray())));
        }
Esempio n. 2
0
        /// <summary>
        /// Creates the variable.
        /// </summary>
        /// <param name="serviceProvider">The service provider.</param>
        /// <param name="variableName">Name of the variable.</param>
        /// <param name="variableType">Type of the variable.</param>
        /// <param name="assignment">The assignment.</param>
        public static void CreateVariable(this EPServiceProvider serviceProvider,
                                          string variableName,
                                          string variableType,
                                          System.Linq.Expressions.Expression <Func <object> > assignment)
        {
            var objectModel = new EPStatementObjectModel();

            objectModel.CreateVariable = CreateVariableClause.Create(variableType, variableName);
            objectModel.CreateVariable.OptionalAssignment = LinqToSoda.LinqToSodaExpression(assignment);
            serviceProvider.EPAdministrator.Create(objectModel);
        }
Esempio n. 3
0
 /// <summary>
 /// Creates a delete trigger with two stream expression capability.
 /// </summary>
 /// <typeparam name="T1">The type of the 1.</typeparam>
 /// <typeparam name="T2">The type of the 2.</typeparam>
 /// <param name="serviceProvider">The service provider.</param>
 /// <param name="windowName">Name of the window.</param>
 /// <param name="asName">As name.</param>
 /// <param name="fromClause">From clause.</param>
 /// <param name="whereClause">The where clause.</param>
 /// <returns></returns>
 public static EPStatement CreateDeleteTrigger <T1, T2>(this EPServiceProvider serviceProvider,
                                                        string windowName,
                                                        string asName,
                                                        EsperQuery <T1> fromClause,
                                                        System.Linq.Expressions.Expression <Func <T1, T2, bool> > whereClause)
 {
     return(CreateDeleteTrigger(
                serviceProvider,
                windowName,
                asName,
                fromClause,
                () => LinqToSoda.LinqToSodaExpression(whereClause)));
 }
Esempio n. 4
0
        /// <summary>
        ///     Groups the results of the expression.
        /// </summary>
        /// <typeparam name="TSource">The type of the source.</typeparam>
        /// <typeparam name="TKey">The type of the key.</typeparam>
        /// <param name="esperQuery">The esper query.</param>
        /// <param name="keySelectionExpression">The key selection expression.</param>
        /// <returns></returns>
        public static EsperQuery <TSource> GroupBy <TSource, TKey>(
            this EsperQuery <TSource> esperQuery,
            Expression <Func <TSource, TKey> > keySelectionExpression)
        {
            var parentObjectModel = esperQuery.ObjectModel;
            var deriveObjectModel = parentObjectModel.ShallowCopy();

            // Adapt or set the where clause according to the expression contents
            using (ScopedInstance <EPStatementObjectModel> .Set(deriveObjectModel)) {
                var sodaExpression = LinqToSoda.LinqToSodaExpression(keySelectionExpression);
                deriveObjectModel.GroupByClause = GroupByClause.Create(sodaExpression);
                return(new EsperQuery <TSource>(esperQuery.ServiceProvider, deriveObjectModel));
            }
        }
Esempio n. 5
0
        /// <summary>
        ///     Adds the property.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="esperQuery">The esper query.</param>
        /// <param name="propertyName">Name of the property.</param>
        /// <param name="expression">The expression.</param>
        /// <returns></returns>
        public static EsperQuery <T> AddProperty <T>(
            this EsperQuery <T> esperQuery,
            string propertyName,
            Expression <Func <object> > expression)
        {
            var parentObjectModel = esperQuery.ObjectModel;
            var deriveObjectModel = parentObjectModel.ShallowCopy();

            using (ScopedInstance <EPStatementObjectModel> .Set(deriveObjectModel)) {
                deriveObjectModel.SelectClause.Add(
                    LinqToSoda.LinqToSodaExpression(expression),
                    propertyName);
                return(new EsperQuery <T>(esperQuery.ServiceProvider, deriveObjectModel));
            }
        }
Esempio n. 6
0
        /// <summary>
        ///     Constrains the specified esper query.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="esperQuery">The esper query.</param>
        /// <param name="expression">The expression.</param>
        /// <returns></returns>
        public static EsperQuery <T> Where <T>(
            this EsperQuery <T> esperQuery,
            Expression <Func <T, bool> > expression)
        {
            var parentObjectModel = esperQuery.ObjectModel;
            var deriveObjectModel = parentObjectModel.ShallowCopy();

            // Adapt or set the where clause according to the expression contents
            using (ScopedInstance <EPStatementObjectModel> .Set(deriveObjectModel)) {
                var sodaExpression = LinqToSoda.LinqToSodaExpression(expression);
                deriveObjectModel.WhereClause = deriveObjectModel.WhereClause == null
                    ? sodaExpression
                    : Expressions.And(deriveObjectModel.WhereClause, sodaExpression);
                deriveObjectModel.FromClause.Streams[0].StreamName =
                    expression.Parameters[0].Name;

                return(new EsperQuery <T>(esperQuery.ServiceProvider, deriveObjectModel));
            }
        }
Esempio n. 7
0
        /// <summary>
        ///     Joins the specified outer.
        /// </summary>
        /// <typeparam name="TOuter">The type of the outer.</typeparam>
        /// <typeparam name="TInner">The type of the inner.</typeparam>
        /// <typeparam name="TKey">The type of the key.</typeparam>
        /// <typeparam name="TResult">The type of the result.</typeparam>
        /// <param name="outer">The outer.</param>
        /// <param name="inner">The inner.</param>
        /// <param name="outerKeySelector">The outer key selector.</param>
        /// <param name="innerKeySelector">The inner key selector.</param>
        /// <param name="resultSelector">The result selector.</param>
        /// <returns></returns>
        public static EsperQuery <TResult> Join <TOuter, TInner, TKey, TResult>(
            this EsperQuery <TOuter> outer,
            EsperQuery <TInner> inner,
            Expression <Func <TOuter, TKey> > outerKeySelector,
            Expression <Func <TInner, TKey> > innerKeySelector,
            Expression <Func <TOuter, TInner, TResult> > resultSelector)
        {
            var parentObjectModel = outer.ObjectModel;
            var deriveObjectModel = new EPStatementObjectModel();

            using (ScopedInstance <EPStatementObjectModel> .Set(deriveObjectModel)) {
                deriveObjectModel.Annotations = parentObjectModel.Annotations;

                var innerKey = LinqToSoda.LinqToSodaExpression(innerKeySelector);
                var outerKey = LinqToSoda.LinqToSodaExpression(outerKeySelector);

                deriveObjectModel.FromClause = new FromClause(
                    outer.ObjectModel.FromClause.Streams.Concat(
                        inner.ObjectModel.FromClause.Streams)
                    .ToArray());

                var parametersArray = resultSelector.Parameters.ToArray();
                for (var ii = 0; ii < parametersArray.Length; ii++)
                {
                    deriveObjectModel.FromClause.Streams[ii].StreamName =
                        parametersArray[ii].Name;
                }

                deriveObjectModel.FromClause.OuterJoinQualifiers = new List <OuterJoinQualifier>();
                deriveObjectModel.FromClause.OuterJoinQualifiers.Add(
                    new OuterJoinQualifier(
                        OuterJoinType.LEFT,
                        outerKey,
                        innerKey,
                        new PropertyValueExpressionPair[0]));

                deriveObjectModel.SelectClause = LinqToSoda.LinqToSelectClause(resultSelector);

                var toEPL = deriveObjectModel.ToEPL();

                return(new EsperQuery <TResult>(outer.ServiceProvider, deriveObjectModel));
            }
        }
Esempio n. 8
0
        /// <summary>
        /// Creates a window.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="serviceProvider">The service provider.</param>
        /// <param name="windowName">Name of the window.</param>
        /// <param name="view">The view.</param>
        /// <param name="esperQuery">The esper query.</param>
        /// <param name="insertWhereExpression">The insert where expression.</param>
        /// <returns></returns>
        public static EPStatementObjectModel CreateWindowAsObjectModel <T>(
            this EPServiceProvider serviceProvider,
            string windowName,
            View view,
            EsperQuery <T> esperQuery,
            System.Linq.Expressions.Expression <Func <T, bool> > insertWhereExpression)
        {
            var deriveObjectModel = DeriveObjectModel(esperQuery);

            using (ScopedInstance <EPStatementObjectModel> .Set(deriveObjectModel))
            {
                deriveObjectModel.CreateWindow          = CreateWindowClause.Create(windowName, view);
                deriveObjectModel.CreateWindow.IsInsert = false;
                if (insertWhereExpression != null)
                {
                    deriveObjectModel.CreateWindow.InsertWhereClause =
                        LinqToSoda.LinqToSodaExpression(insertWhereExpression);
                    deriveObjectModel.CreateWindow.IsInsert = true;
                }

                return(deriveObjectModel);
            }
        }
Esempio n. 9
0
 /// <summary>
 /// Expands the view to keep events (tumbling window) until the given expression is satisfied.
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="esperQuery">The esper query.</param>
 /// <param name="expression">The expression.</param>
 /// <returns></returns>
 public static EsperQuery <T> KeepUntil <T>(this EsperQuery <T> esperQuery, System.Linq.Expressions.Expression <Func <T, bool> > expression)
 {
     return(esperQuery.FilterView(() => View.Create("expr_batch", LinqToSoda.LinqToSodaExpression(expression))));
 }