From 2c73b5a47d0a17a5b9298c5de8e999cd3cbf019a Mon Sep 17 00:00:00 2001 From: Craig Wilson Date: Sun, 2 May 2010 17:15:28 -0500 Subject: [PATCH] removed temporary join support. --- .../IntegrationTests/Linq/MongoQueryTests.cs | 11 - source/MongoDB/Linq/ExecutionBuilder.cs | 192 +----------------- .../Linq/Expressions/ClientJoinExpression.cs | 45 ---- .../Linq/Expressions/JoinExpression.cs | 46 ----- source/MongoDB/Linq/Expressions/JoinType.cs | 16 -- .../Expressions/MongoExpressionComparer.cs | 30 --- .../Expressions/MongoExpressionExtensions.cs | 11 - .../Expressions/MongoExpressionVisitor.cs | 42 ---- .../Linq/Expressions/NamedValueExpression.cs | 31 --- .../Linq/Expressions/OuterJoinedExpression.cs | 31 --- source/MongoDB/Linq/MongoQueryObject.cs | 2 +- source/MongoDB/Linq/MongoQueryProvider.cs | 7 - .../ClientJoinProjectionRewriter.cs | 123 ----------- .../Translators/MongoQueryObjectBuilder.cs | 7 +- .../Linq/Translators/NamedValueGatherer.cs | 29 --- .../MongoDB/Linq/Translators/QueryBinder.cs | 38 ---- .../Linq/Translators/RedundantJoinRemover.cs | 72 ------- source/MongoDB/MongoDB.csproj | 8 - 18 files changed, 9 insertions(+), 732 deletions(-) delete mode 100644 source/MongoDB/Linq/Expressions/ClientJoinExpression.cs delete mode 100644 source/MongoDB/Linq/Expressions/JoinExpression.cs delete mode 100644 source/MongoDB/Linq/Expressions/JoinType.cs delete mode 100644 source/MongoDB/Linq/Expressions/NamedValueExpression.cs delete mode 100644 source/MongoDB/Linq/Expressions/OuterJoinedExpression.cs delete mode 100644 source/MongoDB/Linq/Translators/ClientJoinProjectionRewriter.cs delete mode 100644 source/MongoDB/Linq/Translators/NamedValueGatherer.cs delete mode 100644 source/MongoDB/Linq/Translators/RedundantJoinRemover.cs diff --git a/source/MongoDB.Tests/IntegrationTests/Linq/MongoQueryTests.cs b/source/MongoDB.Tests/IntegrationTests/Linq/MongoQueryTests.cs index 374b9ccd..6677f262 100644 --- a/source/MongoDB.Tests/IntegrationTests/Linq/MongoQueryTests.cs +++ b/source/MongoDB.Tests/IntegrationTests/Linq/MongoQueryTests.cs @@ -350,16 +350,5 @@ public void Complex_Addition() Assert.AreEqual(1, people.Count); } - - [Test] - public void Join() - { - var people = Enumerable.ToList( - from p in collection.Linq() - join op in collection.Linq() on p.PrimaryAddress equals op.PrimaryAddress - select p); - - Assert.AreEqual(0, people.Count); - } } } diff --git a/source/MongoDB/Linq/ExecutionBuilder.cs b/source/MongoDB/Linq/ExecutionBuilder.cs index 522bc082..49efb464 100644 --- a/source/MongoDB/Linq/ExecutionBuilder.cs +++ b/source/MongoDB/Linq/ExecutionBuilder.cs @@ -12,129 +12,19 @@ namespace MongoDB.Linq { internal class ExecutionBuilder : MongoExpressionVisitor { - private List _initializers; - private bool _isTop; - private int _lookup; - private int _numCursors; private Expression _provider; - private MemberInfo _receivingMember; - private List _variables; - public Expression Build(Expression expression, Expression provider) { - _initializers = new List(); - _variables = new List(); - _isTop = true; _provider = provider; - return Build(expression); - } - - protected override MemberBinding VisitBinding(MemberBinding binding) - { - var save = _receivingMember; - _receivingMember = binding.Member; - var result = base.VisitBinding(binding); - _receivingMember = save; - return result; - } - - protected override Expression VisitClientJoin(ClientJoinExpression clientJoin) - { - var innerKey = MakeJoinKey(clientJoin.InnerKey); - var outerKey = MakeJoinKey(clientJoin.OuterKey); - - var pairConstructor = typeof(KeyValuePair<,>).MakeGenericType(innerKey.Type, clientJoin.Projection.Projector.Type).GetConstructor(new[] { innerKey.Type, clientJoin.Projection.Projector.Type }); - var constructPair = Expression.New(pairConstructor, innerKey, clientJoin.Projection.Projector); - var newProjection = new ProjectionExpression(clientJoin.Projection.Source, constructPair); - - int lookupIndex = _lookup++; - var execution = ExecuteProjection(newProjection); - - var pair = Expression.Parameter(constructPair.Type, "pair"); - - if (clientJoin.Projection.Projector.NodeType == (ExpressionType)MongoExpressionType.OuterJoined) - { - var lambda = Expression.Lambda( - Expression.NotEqual( - Expression.PropertyOrField(pair, "Value"), - Expression.Constant(null, clientJoin.Projection.Projector.Type)), - pair); - execution = Expression.Call(typeof(Enumerable), "Where", new[] { pair.Type }, execution, lambda); - } - - var keySelector = Expression.Lambda(Expression.PropertyOrField(pair, "Key"), pair); - var elementSelector = Expression.Lambda(Expression.PropertyOrField(pair, "Value"), pair); - var toLookup = Expression.Call(typeof(Enumerable), "ToLookup", new [] { pair.Type, outerKey.Type, clientJoin.Projection.Projector.Type }, execution, keySelector, elementSelector); - - var lookup = Expression.Parameter(toLookup.Type, "lookup" + lookupIndex); - var prop = lookup.Type.GetProperty("Item"); - Expression access = Expression.Call(lookup, prop.GetGetMethod(), Visit(outerKey)); - if(clientJoin.Projection.Aggregator != null) - access = new ExpressionReplacer().Replace(clientJoin.Projection.Aggregator.Body, clientJoin.Projection.Aggregator.Parameters[0], access); - - _variables.Add(lookup); - _initializers.Add(toLookup); - - return access; - } - - protected override Expression VisitField(FieldExpression field) - { - return Visit(field.Expression); + return Visit(expression); } protected override Expression VisitProjection(ProjectionExpression projection) { - if (_isTop) - { - _isTop = false; - return ExecuteProjection(projection); - } - else - { - return BuildInner(projection); - } - } - - private Expression AddVariables(Expression expression) - { - if (_variables.Count > 0) - { - var expressions = new List(); - for (int i = 0, n = _variables.Count; i < n; i++) - expressions.Add(MakeAssign(_variables[i], _initializers[i])); - - var sequence = MakeSequence(expressions); - - var nulls = _variables.Select(v => Expression.Constant(null, v.Type)).ToArray(); - expression = Expression.Invoke(Expression.Lambda(sequence, _variables.ToArray()), nulls); - } - return expression; - } - - private Expression Build(Expression expression) - { - expression = Visit(expression); - expression = AddVariables(expression); - return expression; - } - - private Expression BuildInner(Expression expression) - { - var builder = new ExecutionBuilder(); - builder._receivingMember = _receivingMember; - builder._numCursors = _numCursors; - builder._lookup = _lookup; - return builder.Build(expression); - } - - private Expression ExecuteProjection(ProjectionExpression projection) - { - var projection = base.VisitProjection(projection); var queryObject = new MongoQueryObjectBuilder().Build(projection); - queryObject.Projector = new ProjectionBuilder().Build(projection.Projector, queryObject.DocumentType, "d" + (_numCursors++), queryObject.IsMapReduce); - queryObject.Aggregator = projection.Aggregator; + queryObject.Projector = new ProjectionBuilder().Build(projection.Projector, queryObject.DocumentType, "document", queryObject.IsMapReduce); + queryObject.Aggregator = (LambdaExpression)Visit(projection.Aggregator); Expression result = Expression.Call( _provider, @@ -142,80 +32,12 @@ private Expression ExecuteProjection(ProjectionExpression projection) Type.EmptyTypes, Expression.Constant(queryObject, typeof(MongoQueryObject))); - return result; - } - - public static T Assign(ref T variable, T value) - { - variable = value; - return value; - } - - public static object Sequence(params object[] values) - { - return values[values.Length - 1]; - } - - private static Expression MakeAssign(ParameterExpression variable, Expression value) - { - return Expression.Call(typeof(ExecutionBuilder), "Assign", new[] { variable.Type }, variable, value); - } - - private static Expression MakeJoinKey(IList key) - { - if (key.Count == 1) - return key[0]; + if (queryObject.Aggregator != null) + result = Expression.Convert(result, queryObject.Aggregator.Body.Type); else - { - return Expression.New( - typeof(CompoundKey).GetConstructors()[0], - Expression.NewArrayInit(typeof(object), key.Select(k => (Expression)Expression.Convert(k, typeof(object))))); - } - } - - private static Expression MakeSequence(IList expressions) - { - var last = expressions[expressions.Count - 1]; - return Expression.Convert(Expression.Call(typeof(ExecutionBuilder), "Sequence", null, Expression.NewArrayInit(typeof(object), expressions)), last.Type); - } - - private class CompoundKey : IEquatable - { - private object[] _values; - private int _hashCode; - - public CompoundKey(params object[] values) - { - _values = values; - for (int i = 0, n = values.Length; i < n; i++) - { - object value = values[i]; - if (value != null) - _hashCode ^= (value.GetHashCode() + i); - } - } + result = Expression.Convert(result, typeof(IEnumerable<>).MakeGenericType(queryObject.Projector.Body.Type)); - public override int GetHashCode() - { - return _hashCode; - } - - public override bool Equals(object obj) - { - return base.Equals(obj); - } - - public bool Equals(CompoundKey other) - { - if (other == null || other._values.Length != _values.Length) - return false; - for (int i = 0, n = other._values.Length; i < n; i++) - { - if (!object.Equals(_values[i], other._values[i])) - return false; - } - return true; - } + return result; } } } \ No newline at end of file diff --git a/source/MongoDB/Linq/Expressions/ClientJoinExpression.cs b/source/MongoDB/Linq/Expressions/ClientJoinExpression.cs deleted file mode 100644 index 75ad154d..00000000 --- a/source/MongoDB/Linq/Expressions/ClientJoinExpression.cs +++ /dev/null @@ -1,45 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Collections.ObjectModel; -using System.Linq; -using System.Linq.Expressions; -using System.Text; - -namespace MongoDB.Linq.Expressions -{ - internal class ClientJoinExpression : MongoExpression - { - private readonly ReadOnlyCollection _outerKey; - private readonly ReadOnlyCollection _innerKey; - private readonly ProjectionExpression _projection; - - public ReadOnlyCollection InnerKey - { - get { return _innerKey; } - } - - public ReadOnlyCollection OuterKey - { - get { return _outerKey; } - } - - public ProjectionExpression Projection - { - get { return _projection; } - } - - public ClientJoinExpression(ProjectionExpression projection, IEnumerable outerKey, IEnumerable innerKey) - : base(MongoExpressionType.ClientJoin, projection.Type) - { - _outerKey = outerKey as ReadOnlyCollection; - if (_outerKey == null) - _outerKey = new List(outerKey).AsReadOnly(); - - _innerKey = innerKey as ReadOnlyCollection; - if (_innerKey == null) - _innerKey = new List(innerKey).AsReadOnly(); - - _projection = projection; - } - } -} \ No newline at end of file diff --git a/source/MongoDB/Linq/Expressions/JoinExpression.cs b/source/MongoDB/Linq/Expressions/JoinExpression.cs deleted file mode 100644 index 966c60fe..00000000 --- a/source/MongoDB/Linq/Expressions/JoinExpression.cs +++ /dev/null @@ -1,46 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Linq.Expressions; -using System.Text; - -namespace MongoDB.Linq.Expressions -{ - internal class JoinExpression : MongoExpression - { - private readonly JoinType _joinType; - private readonly Expression _left; - private readonly Expression _right; - private readonly Expression _condition; - - public JoinType Join - { - get { return _joinType; } - } - - public Expression Left - { - get { return _left; } - } - - public Expression Right - { - get { return _right; } - } - - public new Expression Condition - { - get { return _condition; } - } - - public JoinExpression(JoinType joinType, Expression left, Expression right, Expression condition) - : base(MongoExpressionType.Join, typeof(void)) - { - _joinType = joinType; - _left = left; - _right = right; - _condition = condition; - } - - } -} diff --git a/source/MongoDB/Linq/Expressions/JoinType.cs b/source/MongoDB/Linq/Expressions/JoinType.cs deleted file mode 100644 index f26d8833..00000000 --- a/source/MongoDB/Linq/Expressions/JoinType.cs +++ /dev/null @@ -1,16 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; - -namespace MongoDB.Linq.Expressions -{ - internal enum JoinType - { - CrossJoin, - InnerJoin, - CrossApply, - OuterApply, - LeftOuter - } -} diff --git a/source/MongoDB/Linq/Expressions/MongoExpressionComparer.cs b/source/MongoDB/Linq/Expressions/MongoExpressionComparer.cs index 7c176b37..a98ee271 100644 --- a/source/MongoDB/Linq/Expressions/MongoExpressionComparer.cs +++ b/source/MongoDB/Linq/Expressions/MongoExpressionComparer.cs @@ -48,8 +48,6 @@ protected override bool Compare(Expression a, Expression b) return CompareField((FieldExpression)a, (FieldExpression)b); case MongoExpressionType.Select: return CompareSelect((SelectExpression)a, (SelectExpression)b); - case MongoExpressionType.Join: - return CompareJoin((JoinExpression)a, (JoinExpression)b); case MongoExpressionType.Aggregate: return CompareAggregate((AggregateExpression)a, (AggregateExpression)b); case MongoExpressionType.Scalar: @@ -147,34 +145,6 @@ protected virtual bool CompareFieldDeclaration(FieldDeclaration a, FieldDeclarat return a.Name == b.Name && Compare(a.Expression, b.Expression); } - protected virtual bool CompareJoin(JoinExpression a, JoinExpression b) - { - if (a.Join != b.Join || !Compare(a.Left, b.Left)) - return false; - - if (a.Join == JoinType.CrossApply || a.Join == JoinType.OuterApply) - { - var save = _aliasScope; - try - { - _aliasScope = new ScopedDictionary(_aliasScope); - MapAliases(a.Left, b.Left); - - return Compare(a.Right, b.Right) - && Compare(a.Condition, b.Condition); - } - finally - { - _aliasScope = save; - } - } - else - { - return Compare(a.Right, b.Right) - && Compare(a.Condition, b.Condition); - } - } - protected virtual bool CompareAggregate(AggregateExpression a, AggregateExpression b) { return a.AggregateType == b.AggregateType && Compare(a.Argument, b.Argument); diff --git a/source/MongoDB/Linq/Expressions/MongoExpressionExtensions.cs b/source/MongoDB/Linq/Expressions/MongoExpressionExtensions.cs index ff2ed10a..367ef0da 100644 --- a/source/MongoDB/Linq/Expressions/MongoExpressionExtensions.cs +++ b/source/MongoDB/Linq/Expressions/MongoExpressionExtensions.cs @@ -15,17 +15,6 @@ public static SelectExpression AddField(this SelectExpression select, FieldDecla return select.SetFields(fields); } - public static ProjectionExpression AddOuterJoinTest(this ProjectionExpression projection) - { - string fieldName = projection.Source.GetAvailableFieldName("Test"); - SelectExpression newSource = projection.Source.AddField(new FieldDeclaration(fieldName, Expression.Constant(1, typeof(int?)))); - Expression newProjector = - new OuterJoinedExpression( - new FieldExpression(Expression.Constant(1, typeof(int?)), newSource.Alias, fieldName), - projection.Projector); - return new ProjectionExpression(newSource, newProjector, projection.Aggregator); - } - public static string GetAvailableFieldName(this SelectExpression select, string baseName) { string name = baseName; diff --git a/source/MongoDB/Linq/Expressions/MongoExpressionVisitor.cs b/source/MongoDB/Linq/Expressions/MongoExpressionVisitor.cs index 0f3ff63a..b77019a7 100644 --- a/source/MongoDB/Linq/Expressions/MongoExpressionVisitor.cs +++ b/source/MongoDB/Linq/Expressions/MongoExpressionVisitor.cs @@ -29,14 +29,6 @@ protected override Expression Visit(Expression exp) return VisitAggregateSubquery((AggregateSubqueryExpression)exp); case MongoExpressionType.Scalar: return VisitScalar((ScalarExpression)exp); - case MongoExpressionType.Join: - return VisitJoin((JoinExpression)exp); - case MongoExpressionType.ClientJoin: - return VisitClientJoin((ClientJoinExpression)exp); - case MongoExpressionType.OuterJoined: - return VisitOuterJoined((OuterJoinedExpression)exp); - case MongoExpressionType.NamedValue: - return VisitNamedValue((NamedValueExpression)exp); default: return base.Visit(exp); } @@ -60,16 +52,6 @@ protected virtual Expression VisitAggregateSubquery(AggregateSubqueryExpression return aggregateSubquery; } - protected virtual Expression VisitClientJoin(ClientJoinExpression clientJoin) - { - var projection = (ProjectionExpression)Visit(clientJoin.Projection); - var outerKey = VisitExpressionList(clientJoin.OuterKey); - var innerKey = VisitExpressionList(clientJoin.InnerKey); - if (projection != clientJoin.Projection && outerKey != clientJoin.OuterKey && innerKey != clientJoin.InnerKey) - return new ClientJoinExpression(projection, outerKey, innerKey); - return projection; - } - protected virtual Expression VisitCollection(CollectionExpression collection) { return collection; @@ -84,21 +66,6 @@ protected virtual Expression VisitField(FieldExpression field) return field; } - protected virtual Expression VisitJoin(JoinExpression join) - { - var left = VisitSource(join.Left); - var right = VisitSource(join.Right); - var condition = Visit(join.Condition); - if (left != join.Left && right != join.Right && condition != join.Condition) - return new JoinExpression(join.Join, left, right, condition); - return join; - } - - protected virtual Expression VisitNamedValue(NamedValueExpression namedValue) - { - return namedValue; - } - protected virtual Expression VisitProjection(ProjectionExpression projection) { var source = (SelectExpression)Visit(projection.Source); @@ -128,15 +95,6 @@ protected ReadOnlyCollection VisitOrderBy(ReadOnlyCollection public override string ToString() { - throw new NotImplementedException(); + return "queryobject"; } } } \ No newline at end of file diff --git a/source/MongoDB/Linq/MongoQueryProvider.cs b/source/MongoDB/Linq/MongoQueryProvider.cs index 02bed016..891bf29d 100644 --- a/source/MongoDB/Linq/MongoQueryProvider.cs +++ b/source/MongoDB/Linq/MongoQueryProvider.cs @@ -171,17 +171,10 @@ private ProjectionExpression Translate(Expression expression) expression = new AggregateRewriter().Rewrite(expression); expression = new RedundantFieldRemover().Remove(expression); expression = new RedundantSubqueryRemover().Remove(expression); - expression = new RedundantJoinRemover().Remove(expression); - - expression = new ClientJoinProjectionRewriter().Rewrite(expression); - expression = new RedundantFieldRemover().Remove(expression); - expression = new RedundantSubqueryRemover().Remove(expression); - expression = new RedundantJoinRemover().Remove(expression); expression = new OrderByRewriter().Rewrite(expression); expression = new RedundantFieldRemover().Remove(expression); expression = new RedundantSubqueryRemover().Remove(expression); - expression = new RedundantJoinRemover().Remove(expression); return (ProjectionExpression)expression; } diff --git a/source/MongoDB/Linq/Translators/ClientJoinProjectionRewriter.cs b/source/MongoDB/Linq/Translators/ClientJoinProjectionRewriter.cs deleted file mode 100644 index 523357c8..00000000 --- a/source/MongoDB/Linq/Translators/ClientJoinProjectionRewriter.cs +++ /dev/null @@ -1,123 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Linq.Expressions; -using System.Text; - -using MongoDB.Linq.Expressions; - -namespace MongoDB.Linq.Translators -{ - internal class ClientJoinProjectionRewriter : MongoExpressionVisitor - { - private bool _isTopLevel; - private SelectExpression _currentSelect; - private FieldMapper _fieldMapper; - - public ClientJoinProjectionRewriter() - { - _fieldMapper = new FieldMapper(); - } - - public Expression Rewrite(Expression expression) - { - _isTopLevel = true; - return Visit(expression); - } - - protected override Expression VisitProjection(ProjectionExpression projection) - { - var saveCurrentSelect = _currentSelect; - _currentSelect = projection.Source; - try - { - if (!_isTopLevel) - { - if (CanJoinOnClient(_currentSelect)) - { - var newOuterSelect = (SelectExpression)new QueryDuplicator().Duplicate(saveCurrentSelect); - var newInnerSelect = (SelectExpression)_fieldMapper.Map(projection.Source, newOuterSelect.Alias, saveCurrentSelect.Alias); - - var newInnerProjection = new ProjectionExpression(newInnerSelect, projection.Projector).AddOuterJoinTest(); - newInnerSelect = newInnerProjection.Source; - var newProjector = newInnerProjection.Projector; - - var newAlias = new Alias(); - var fieldProjection = new FieldProjector(QueryBinder.CanBeField).ProjectFields(newProjector, newAlias, newOuterSelect.Alias, newInnerSelect.Alias); - var join = new JoinExpression(JoinType.OuterApply, newOuterSelect, newInnerSelect, null); - var joinedSelect = new SelectExpression(newAlias, fieldProjection.Fields, join, null, null, null, projection.IsSingleton, null, null); - - _currentSelect = joinedSelect; - newProjector = Visit(fieldProjection.Projector); - - var outerKeys = new List(); - var innerKeys = new List(); - var fieldMapper = new FieldMapper(); - if (GetEquiJoinKeyExpressions(newInnerSelect.Where, newOuterSelect.Alias, outerKeys, innerKeys)) - { - var outerKey = outerKeys.Select(k => _fieldMapper.Map(k, saveCurrentSelect.Alias, newOuterSelect.Alias)); - var innerKey = innerKeys.Select(k => _fieldMapper.Map(k, joinedSelect.Alias, ((FieldExpression)k).Alias)); - var newProjection = new ProjectionExpression(joinedSelect, newProjector, projection.Aggregator); - return new ClientJoinExpression(newProjection, outerKey, innerKey); - } - } - } - else - _isTopLevel = false; - - return base.VisitProjection(projection); - } - finally - { - _currentSelect = saveCurrentSelect; - } - } - - protected override Expression VisitSubquery(SubqueryExpression subquery) - { - return subquery; - } - - private bool CanJoinOnClient(SelectExpression select) - { - return !select.IsDistinct - && select.GroupBy == null - && !new AggregateChecker().HasAggregates(select); - } - - private bool GetEquiJoinKeyExpressions(Expression predicate, Alias outerAlias, List outerExpressions, List innerExpressions) - { - BinaryExpression b = predicate as BinaryExpression; - if (b != null) - { - switch (predicate.NodeType) - { - case ExpressionType.And: - case ExpressionType.AndAlso: - return GetEquiJoinKeyExpressions(b.Left, outerAlias, outerExpressions, innerExpressions) - && GetEquiJoinKeyExpressions(b.Right, outerAlias, outerExpressions, innerExpressions); - case ExpressionType.Equal: - var left = b.Left as FieldExpression; - var right = b.Right as FieldExpression; - if (left != null && right != null) - { - if (left.Alias == outerAlias) - { - outerExpressions.Add(left); - innerExpressions.Add(right); - return true; - } - else if (right.Alias == outerAlias) - { - innerExpressions.Add(left); - outerExpressions.Add(right); - return true; - } - } - break; - } - } - return false; - } - } -} \ No newline at end of file diff --git a/source/MongoDB/Linq/Translators/MongoQueryObjectBuilder.cs b/source/MongoDB/Linq/Translators/MongoQueryObjectBuilder.cs index af0bf29b..aa772b10 100644 --- a/source/MongoDB/Linq/Translators/MongoQueryObjectBuilder.cs +++ b/source/MongoDB/Linq/Translators/MongoQueryObjectBuilder.cs @@ -18,6 +18,7 @@ internal MongoQueryObject Build(ProjectionExpression expression) _queryObject = new MongoQueryObject(); _queryAttributes = new QueryAttributesGatherer().Gather(expression); _queryObject.IsCount = _queryAttributes.IsCount; + _queryObject.IsMapReduce = _queryAttributes.IsMapReduce; Visit(expression); return _queryObject; } @@ -160,12 +161,6 @@ protected override Expression VisitSelect(SelectExpression select) Visit(select.Where); return select; } - - protected override Expression VisitProjection(ProjectionExpression projection) - { - VisitSource(projection.Source); - return projection; - } } } } \ No newline at end of file diff --git a/source/MongoDB/Linq/Translators/NamedValueGatherer.cs b/source/MongoDB/Linq/Translators/NamedValueGatherer.cs deleted file mode 100644 index 4a37427d..00000000 --- a/source/MongoDB/Linq/Translators/NamedValueGatherer.cs +++ /dev/null @@ -1,29 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Collections.ObjectModel; -using System.Linq; -using System.Linq.Expressions; -using System.Text; - -using MongoDB.Linq.Expressions; - -namespace MongoDB.Linq.Translators -{ - internal class NamedValueGatherer : MongoExpressionVisitor - { - private List _namedValues; - - public ReadOnlyCollection Gather(Expression expr) - { - _namedValues = new List(); - Visit(expr); - return _namedValues.AsReadOnly(); - } - - protected override Expression VisitNamedValue(NamedValueExpression value) - { - _namedValues.Add(value); - return value; - } - } -} diff --git a/source/MongoDB/Linq/Translators/QueryBinder.cs b/source/MongoDB/Linq/Translators/QueryBinder.cs index 797b57f5..7853317e 100644 --- a/source/MongoDB/Linq/Translators/QueryBinder.cs +++ b/source/MongoDB/Linq/Translators/QueryBinder.cs @@ -155,8 +155,6 @@ protected override Expression VisitMethodCall(MethodCallExpression m) else if (m.Arguments.Count == 4) return BindGroupBy(m.Arguments[0], (LambdaExpression)StripQuotes(m.Arguments[1]), (LambdaExpression)StripQuotes(m.Arguments[2]), (LambdaExpression)StripQuotes(m.Arguments[3])); break; - case "Join": - return BindJoin(m.Type, m.Arguments[0], m.Arguments[1], (LambdaExpression)StripQuotes(m.Arguments[2]), (LambdaExpression)StripQuotes(m.Arguments[3]), (LambdaExpression)StripQuotes(m.Arguments[4])); } throw new NotSupportedException(string.Format("The method '{0}' is not supported", m.Method.Name)); } @@ -359,42 +357,6 @@ protected virtual Expression BindGroupBy(Expression source, LambdaExpression key fieldProjection.Projector); } - private Expression BindJoin(Type resultType, Expression outerSource, Expression innerSource, LambdaExpression outerKey, LambdaExpression innerKey, LambdaExpression resultSelector) - { - var outerProjection = VisitSequence(outerSource); - var innerProjection = VisitSequence(innerSource); - - var join = Expression.Call( //change this to a client-side join... - typeof(Enumerable), - "Join", - new [] { outerProjection.Projector.Type, innerProjection.Projector.Type, outerKey.Body.Type, resultSelector.Body.Type }, - outerProjection, - innerProjection, - outerKey, - innerKey, - resultSelector); - - var resultExpression = Visit(resultSelector.Body); - var alias = new Alias(); - var fieldProjection = _projector.ProjectFields(resultExpression, outerProjection.Source.Alias, innerProjection.Source.Alias); - return new ProjectionExpression( - new SelectExpression(alias, fieldProjection.Fields, join, null), - fieldProjection.Projector); - //_map[outerKey.Parameters[0]] = outerProjection.Projector; - //var outerKeyExpression = Visit(outerKey.Body); - //_map[innerKey.Parameters[0]] = innerProjection.Projector; - //var innerKeyExpression = Visit(innerKey.Body); - //_map[resultSelector.Parameters[0]] = outerProjection.Projector; - //_map[resultSelector.Parameters[1]] = innerProjection.Projector; - //var resultExpression = Visit(resultSelector.Body); - //var join = new JoinExpression(JoinType.InnerJoin, outerProjection.Source, innerProjection.Source, Expression.Equal(outerKeyExpression, innerKeyExpression)); - //var alias = new Alias(); - //var fieldProjections = _projector.ProjectFields(resultExpression, alias, outerProjection.Source.Alias, innerProjection.Source.Alias); - //return new ProjectionExpression( - // new SelectExpression(alias, fieldProjections.Fields, join, null), - // fieldProjections.Projector); - } - private Expression BindOrderBy(Type resultType, Expression source, LambdaExpression orderSelector, OrderType orderType) { List thenBye = _thenBy; diff --git a/source/MongoDB/Linq/Translators/RedundantJoinRemover.cs b/source/MongoDB/Linq/Translators/RedundantJoinRemover.cs deleted file mode 100644 index aa9dbad4..00000000 --- a/source/MongoDB/Linq/Translators/RedundantJoinRemover.cs +++ /dev/null @@ -1,72 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Linq.Expressions; -using System.Text; - -using MongoDB.Linq.Expressions; -using MongoDB.Util; - -namespace MongoDB.Linq.Translators -{ - internal class RedundantJoinRemover : MongoExpressionVisitor - { - private Dictionary _map; - - public Expression Remove(Expression expression) - { - _map = new Dictionary(); - return Visit(expression); - } - - protected override Expression VisitField(FieldExpression field) - { - Alias mapped; - if (_map.TryGetValue(field.Alias, out mapped)) - return new FieldExpression(field.Expression, mapped, field.Name); - return field; - } - - protected override Expression VisitJoin(JoinExpression join) - { - var result = base.VisitJoin(join); - join = result as JoinExpression; - if (join != null) - { - var right = join.Right as AliasedExpression; - if (right != null) - { - var similarRight = (AliasedExpression)FindSimiliarRight(join.Left as JoinExpression, join); - if (similarRight != null) - { - _map.Add(right.Alias, similarRight.Alias); - return join.Left; - } - } - } - return result; - } - - private Expression FindSimiliarRight(JoinExpression join, JoinExpression compareTo) - { - if (join == null) - return null; - if (join.Join == compareTo.Join) - { - if (join.Right.NodeType == compareTo.Right.NodeType && MongoExpressionComparer.AreEqual(join.Right, compareTo.Right)) - { - if (join.Condition == compareTo.Condition) - return join.Right; - var scope = new ScopedDictionary(null); - scope.Add(((AliasedExpression)join.Right).Alias, ((AliasedExpression)compareTo.Right).Alias); - if (MongoExpressionComparer.AreEqual(null, scope, join.Condition, compareTo.Condition)) - return join.Right; - } - } - var result = FindSimiliarRight(join.Left as JoinExpression, compareTo); - if (result == null) - result = FindSimiliarRight(join.Right as JoinExpression, compareTo); - return result; - } - } -} \ No newline at end of file diff --git a/source/MongoDB/MongoDB.csproj b/source/MongoDB/MongoDB.csproj index d413289e..d408e7ef 100644 --- a/source/MongoDB/MongoDB.csproj +++ b/source/MongoDB/MongoDB.csproj @@ -121,27 +121,19 @@ - - - - - - - -