public override Expression <Func <IFdbReadOnlyTransaction, IAsyncEnumerable <K> > > CompileSequence() { var prmTrans = Expression.Parameter(typeof(IFdbReadOnlyTransaction), "trans"); Expression body; switch (this.Operator) { case ExpressionType.Equal: { body = FdbExpressionHelpers.RewriteCall <Func <FdbIndex <K, V>, IFdbReadOnlyTransaction, V, bool, IAsyncEnumerable <K> > >( (index, trans, value, reverse) => index.Lookup(trans, value, reverse), Expression.Constant(this.Index, typeof(FdbIndex <K, V>)), prmTrans, this.Value, Expression.Constant(false, typeof(bool)) // reverse ); break; } case ExpressionType.GreaterThan: case ExpressionType.GreaterThanOrEqual: { body = FdbExpressionHelpers.RewriteCall <Func <FdbIndex <K, V>, IFdbReadOnlyTransaction, V, bool, IAsyncEnumerable <K> > >( (index, trans, value, reverse) => index.LookupGreaterThan(trans, value, this.Operator == ExpressionType.GreaterThanOrEqual, reverse), Expression.Constant(this.Index, typeof(FdbIndex <K, V>)), prmTrans, this.Value, Expression.Constant(false, typeof(bool)) // reverse ); break; } case ExpressionType.LessThan: case ExpressionType.LessThanOrEqual: { body = FdbExpressionHelpers.RewriteCall <Func <FdbIndex <K, V>, IFdbReadOnlyTransaction, V, bool, IAsyncEnumerable <K> > >( (index, trans, value, reverse) => index.LookupLessThan(trans, value, this.Operator == ExpressionType.LessThanOrEqual, reverse), Expression.Constant(this.Index, typeof(FdbIndex <K, V>)), prmTrans, this.Value, Expression.Constant(false, typeof(bool)) // reverse ); break; } default: { throw new NotImplementedException(); } } return(Expression.Lambda <Func <IFdbReadOnlyTransaction, IAsyncEnumerable <K> > >(body, prmTrans)); }
public override Expression <Func <IFdbReadOnlyTransaction, IFdbAsyncEnumerable <T> > > CompileSequence() { // compile the key selector var prmTrans = Expression.Parameter(typeof(IFdbReadOnlyTransaction), "trans"); // get all inner enumerables var enumerables = new Expression[this.Expressions.Length]; for (int i = 0; i < this.Expressions.Length; i++) { enumerables[i] = FdbExpressionHelpers.RewriteCall(this.Expressions[i].CompileSequence(), prmTrans); } var array = Expression.NewArrayInit(typeof(IFdbAsyncEnumerable <T>), enumerables); Expression body; switch (this.MergeType) { case FdbQueryMergeType.Intersect: { body = FdbExpressionHelpers.RewriteCall <Func <IFdbAsyncEnumerable <T>[], IComparer <T>, IFdbAsyncEnumerable <T> > >( (sources, comparer) => FdbMergeQueryExtensions.Intersect(sources, comparer), array, Expression.Constant(this.KeyComparer, typeof(IComparer <T>)) ); break; } case FdbQueryMergeType.Union: { body = FdbExpressionHelpers.RewriteCall <Func <IFdbAsyncEnumerable <T>[], IComparer <T>, IFdbAsyncEnumerable <T> > >( (sources, comparer) => FdbMergeQueryExtensions.Union(sources, comparer), array, Expression.Constant(this.KeyComparer, typeof(IComparer <T>)) ); break; } default: { throw new InvalidOperationException(String.Format("Unsupported index merge mode {0}", this.MergeType.ToString())); } } return(Expression.Lambda <Func <IFdbReadOnlyTransaction, IFdbAsyncEnumerable <T> > >( body, prmTrans )); }
public override Expression <Func <IFdbReadOnlyTransaction, IAsyncEnumerable <KeyValuePair <Slice, Slice> > > > CompileSequence() { var prmTrans = Expression.Parameter(typeof(IFdbReadOnlyTransaction), "trans"); var body = FdbExpressionHelpers.RewriteCall <Func <IFdbReadOnlyTransaction, KeySelectorPair, FdbRangeOptions, FdbRangeQuery <KeyValuePair <Slice, Slice> > > >( (trans, range, options) => trans.GetRange(range, options), prmTrans, Expression.Constant(this.Range, typeof(KeySelectorPair)), Expression.Constant(this.Options, typeof(FdbRangeOptions)) ); return(Expression.Lambda <Func <IFdbReadOnlyTransaction, IAsyncEnumerable <KeyValuePair <Slice, Slice> > > >( body, prmTrans )); }
public override Expression <Func <IFdbReadOnlyTransaction, IFdbAsyncEnumerable <T> > > CompileSequence() { var lambda = this.Filter.Compile(); var enumerable = this.Source.CompileSequence(); var prmTrans = Expression.Parameter(typeof(IFdbReadOnlyTransaction), "trans"); // (tr) => sourceEnumerable(tr).Where(lambda); var body = FdbExpressionHelpers.RewriteCall <Func <IFdbAsyncEnumerable <T>, Func <T, bool>, IFdbAsyncEnumerable <T> > >( (sequence, predicate) => sequence.Where(predicate), FdbExpressionHelpers.RewriteCall(enumerable, prmTrans), Expression.Constant(lambda) ); return(Expression.Lambda <Func <IFdbReadOnlyTransaction, IFdbAsyncEnumerable <T> > >(body, prmTrans)); }
/// <summary>Returns a new expression that creates an async sequence that will execute this query on a transaction</summary> public override Expression <Func <IFdbReadOnlyTransaction, IAsyncEnumerable <R> > > CompileSequence() { var lambda = this.Transform.Compile(); var enumerable = this.Source.CompileSequence(); var prmTrans = Expression.Parameter(typeof(IFdbReadOnlyTransaction), "trans"); // (tr) => sourceEnumerable(tr).Select(lambda); var body = FdbExpressionHelpers.RewriteCall <Func <IAsyncEnumerable <T>, Func <T, R>, IAsyncEnumerable <R> > >( (sequence, selector) => sequence.Select(selector), FdbExpressionHelpers.RewriteCall(enumerable, prmTrans), Expression.Constant(lambda) ); return(Expression.Lambda <Func <IFdbReadOnlyTransaction, IAsyncEnumerable <R> > >(body, prmTrans)); }