/// <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("std", "unique", expressions.Select(e => LinqToSoda.LinqToSodaExpression(e)).ToArray()))); }
/// <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); }
/// <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))); }
/// <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)); } }
/// <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, System.Linq.Expressions.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)); } }
/// <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> Having <T>(this EsperQuery <T> esperQuery, System.Linq.Expressions.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.HavingClause = deriveObjectModel.HavingClause == null ? sodaExpression : Expressions.And(deriveObjectModel.WhereClause, sodaExpression); deriveObjectModel.FromClause.Streams[0].StreamName = expression.Parameters[0].Name; return(new EsperQuery <T>(esperQuery.ServiceProvider, deriveObjectModel)); } }
/// <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, System.Linq.Expressions.Expression <Func <TOuter, TKey> > outerKeySelector, System.Linq.Expressions.Expression <Func <TInner, TKey> > innerKeySelector, System.Linq.Expressions.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 (int 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)); } }
/// <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); } }
/// <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("win", "expr_batch", LinqToSoda.LinqToSodaExpression(expression)))); }