Пример #1
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));
            }
        }
Пример #2
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));
            }
        }
Пример #3
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));
            }
        }
Пример #4
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));
            }
        }
Пример #5
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);
            }
        }
Пример #6
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))));
 }