private bool CompareGroupBy(GroupByTransformationNode transformation1, GroupByTransformationNode transformation2) { if (transformation1 == transformation2) { return(true); } if (transformation1 == null || transformation2 == null) { return(false); } if (!_queryNodeComparer.Compare(transformation1.Source, transformation2.Source)) { return(false); } if (!CompareAggregate(transformation1.ChildTransformations as AggregateTransformationNode, transformation2.ChildTransformations as AggregateTransformationNode)) { return(false); } if (!EnumerableComparer.Compare(transformation1.GroupingProperties, transformation2.GroupingProperties, CompareGroupByPropertyNode)) { return(false); } return(true); }
public void BindApplyWitGroupByWithComplexShouldReturnApplyClause() { IEnumerable <QueryToken> tokens = _parser.ParseApply("groupby((MyAddress/City))"); MetadataBinder metadataBiner = new MetadataBinder(_bindingState); ApplyBinder binder = new ApplyBinder(metadataBiner.Bind, _bindingState); ApplyClause actual = binder.BindApply(tokens); Assert.NotNull(actual); actual.Transformations.Should().HaveCount(1); List <TransformationNode> transformations = actual.Transformations.ToList(); GroupByTransformationNode groupBy = transformations[0] as GroupByTransformationNode; groupBy.Should().NotBeNull(); groupBy.Kind.Should().Be(TransformationNodeKind.GroupBy); groupBy.GroupingProperties.Should().NotBeNull(); groupBy.GroupingProperties.Should().HaveCount(1); groupBy.ChildTransformations.Should().BeNull(); List <GroupByPropertyNode> groupingProperties = groupBy.GroupingProperties.ToList(); GroupByPropertyNode addressNode = groupingProperties[0]; addressNode.Name.Should().Be("MyAddress"); addressNode.Expression.Should().BeNull(); addressNode.ChildTransformations.Should().HaveCount(1); GroupByPropertyNode cityNode = addressNode.ChildTransformations[0]; cityNode.Name.Should().Be("City"); cityNode.Expression.Should().NotBeNull(); cityNode.ChildTransformations.Should().BeEmpty(); }
public void BindApplyWitGroupByWithDeepComplexShouldReturnApplyClause() { IEnumerable <QueryToken> tokens = _parser.ParseApply("groupby((MyAddress/NextHome/City))"); MetadataBinder metadataBiner = new MetadataBinder(_bindingState); ApplyBinder binder = new ApplyBinder(metadataBiner.Bind, _bindingState); ApplyClause actual = binder.BindApply(tokens); Assert.NotNull(actual); var transformation = Assert.Single(actual.Transformations); GroupByTransformationNode groupBy = Assert.IsType <GroupByTransformationNode>(transformation); Assert.Equal(TransformationNodeKind.GroupBy, groupBy.Kind); Assert.NotNull(groupBy.GroupingProperties); Assert.Null(groupBy.ChildTransformations); GroupByPropertyNode addressNode = Assert.Single(groupBy.GroupingProperties); Assert.Equal("MyAddress", addressNode.Name); Assert.Null(addressNode.Expression); GroupByPropertyNode nextHomeNode = Assert.Single(addressNode.ChildTransformations); Assert.Equal("NextHome", nextHomeNode.Name); Assert.Null(nextHomeNode.Expression); GroupByPropertyNode cityNode = Assert.Single(nextHomeNode.ChildTransformations); Assert.Equal("City", cityNode.Name); Assert.NotNull(cityNode.Expression); Assert.Empty(cityNode.ChildTransformations); }
public void BindApplyWithExpandReturnApplyClause() { IEnumerable <QueryToken> tokens = _parser.ParseApply( "expand(MyPaintings, filter(FrameColor eq 'Red'))/groupby((LifeTime),aggregate(MyPaintings($count as Count)))"); BindingState state = new BindingState(_configuration); MetadataBinder metadataBiner = new MetadataBinder(_bindingState); ApplyBinder binder = new ApplyBinder(metadataBiner.Bind, _bindingState, V4configuration, new ODataPathInfo(HardCodedTestModel.GetPersonType(), HardCodedTestModel.GetPeopleSet())); ApplyClause actual = binder.BindApply(tokens); Assert.NotNull(actual); Assert.Equal(2, actual.Transformations.Count()); ExpandTransformationNode expand = Assert.IsType <ExpandTransformationNode>(actual.Transformations.First()); Assert.NotNull(expand.ExpandClause); ExpandedNavigationSelectItem expandItem = Assert.IsType <ExpandedNavigationSelectItem>(Assert.Single(expand.ExpandClause.SelectedItems)); Assert.Equal("Paintings", expandItem.NavigationSource.Name); Assert.NotNull(expandItem.FilterOption); GroupByTransformationNode groupBy = Assert.IsType <GroupByTransformationNode>(actual.Transformations.Last()); Assert.Single(groupBy.GroupingProperties); AggregateTransformationNode aggregate = Assert.IsType <AggregateTransformationNode>(groupBy.ChildTransformations); Assert.IsType <EntitySetAggregateExpression>(Assert.Single(aggregate.AggregateExpressions)); }
public void BindApplyWitGroupByWithDeepNavigationShouldReturnApplyClause() { IEnumerable <QueryToken> tokens = _parser.ParseApply("groupby((MyDog/FastestOwner/FirstName))"); MetadataBinder metadataBiner = new MetadataBinder(_bindingState); ApplyBinder binder = new ApplyBinder(metadataBiner.Bind, _bindingState); ApplyClause actual = binder.BindApply(tokens); Assert.NotNull(actual); TransformationNode transformation = Assert.Single(actual.Transformations); GroupByTransformationNode groupBy = Assert.IsType <GroupByTransformationNode>(transformation); Assert.Equal(TransformationNodeKind.GroupBy, groupBy.Kind); Assert.NotNull(groupBy.GroupingProperties); Assert.Null(groupBy.ChildTransformations); GroupByPropertyNode dogNode = Assert.Single(groupBy.GroupingProperties); Assert.Equal("MyDog", dogNode.Name); Assert.Null(dogNode.Expression); GroupByPropertyNode ownerNode = Assert.Single(dogNode.ChildTransformations); Assert.Equal("FastestOwner", ownerNode.Name); Assert.Null(ownerNode.Expression); GroupByPropertyNode nameNode = Assert.Single(ownerNode.ChildTransformations); Assert.Equal("FirstName", nameNode.Name); Assert.NotNull(nameNode.Expression); Assert.Empty(nameNode.ChildTransformations); }
public void BindApplyWitMultipleTokensShouldReturnApplyClause() { IEnumerable <QueryToken> tokens = _parser.ParseApply( "groupby((ID, SSN, LifeTime))/aggregate(LifeTime with sum as TotalLife)/groupby((TotalLife))/aggregate(TotalLife with sum as TotalTotalLife)"); BindingState state = new BindingState(_configuration); MetadataBinder metadataBiner = new MetadataBinder(_bindingState); ApplyBinder binder = new ApplyBinder(metadataBiner.Bind, _bindingState); ApplyClause actual = binder.BindApply(tokens); actual.Should().NotBeNull(); actual.Transformations.Should().HaveCount(4); List <TransformationNode> transformations = actual.Transformations.ToList(); GroupByTransformationNode firstGroupBy = transformations[0] as GroupByTransformationNode; firstGroupBy.Should().NotBeNull(); TransformationNode firstAggregate = transformations[1] as AggregateTransformationNode; firstAggregate.Should().NotBeNull(); TransformationNode scecondGroupBy = transformations[2] as GroupByTransformationNode; scecondGroupBy.Should().NotBeNull(); AggregateTransformationNode scecondAggregate = transformations[3] as AggregateTransformationNode; scecondAggregate.Should().NotBeNull(); }
public void BindApplyWithEntitySetAggregationReturnApplyClause() { IEnumerable <QueryToken> tokens = _parser.ParseApply( "groupby((LifeTime),aggregate(MyPaintings($count as Count)))"); BindingState state = new BindingState(_configuration); MetadataBinder metadataBiner = new MetadataBinder(_bindingState); ApplyBinder binder = new ApplyBinder(metadataBiner.Bind, _bindingState); ApplyClause actual = binder.BindApply(tokens); actual.Should().NotBeNull(); actual.Transformations.Should().HaveCount(1); GroupByTransformationNode groupBy = actual.Transformations.First() as GroupByTransformationNode; groupBy.Should().NotBeNull(); groupBy.GroupingProperties.Should().HaveCount(1); AggregateTransformationNode aggregate = groupBy.ChildTransformations as AggregateTransformationNode; aggregate.Should().NotBeNull(); aggregate.AggregateExpressions.Should().HaveCount(1); EntitySetAggregateExpression entitySetAggregate = aggregate.AggregateExpressions.First() as EntitySetAggregateExpression; entitySetAggregate.Should().NotBeNull(); }
public void BindApplyWitGroupByWithNavigationShouldReturnApplyClause() { IEnumerable <QueryToken> tokens = _parser.ParseApply("groupby((MyDog/City))"); ApplyBinder binder = new ApplyBinder(FakeBindMethods.BindMethodReturnsPersonDogNameNavigation, _bindingState); ApplyClause actual = binder.BindApply(tokens); actual.Should().NotBeNull(); actual.Transformations.Should().HaveCount(1); List <TransformationNode> transformations = actual.Transformations.ToList(); GroupByTransformationNode groupBy = transformations[0] as GroupByTransformationNode; groupBy.Should().NotBeNull(); groupBy.Kind.Should().Be(TransformationNodeKind.GroupBy); groupBy.GroupingProperties.Should().NotBeNull(); groupBy.GroupingProperties.Should().HaveCount(1); List <GroupByPropertyNode> groupingProperties = groupBy.GroupingProperties.ToList(); GroupByPropertyNode dogNode = groupingProperties[0]; dogNode.Expression.Should().BeNull(); dogNode.Name.Should().Be("MyDog"); dogNode.ChildTransformations.Should().HaveCount(1); GroupByPropertyNode nameNode = dogNode.ChildTransformations[0]; dogNode.Name.Should().Be("MyDog"); nameNode.Expression.Should().BeSameAs(FakeBindMethods.FakePersonDogNameNode); groupBy.ChildTransformations.Should().BeNull(); }
public void BindApplyWitGroupByShouldReturnApplyClause() { IEnumerable <QueryToken> tokens = _parser.ParseApply("groupby((UnitPrice, SalePrice))"); ApplyBinder binder = new ApplyBinder(FakeBindMethods.BindSingleComplexProperty, _bindingState); ApplyClause actual = binder.BindApply(tokens); actual.Should().NotBeNull(); actual.Transformations.Should().HaveCount(1); List <TransformationNode> transformations = actual.Transformations.ToList(); GroupByTransformationNode groupBy = transformations[0] as GroupByTransformationNode; groupBy.Should().NotBeNull(); groupBy.Kind.Should().Be(TransformationNodeKind.GroupBy); groupBy.GroupingProperties.Should().NotBeNull(); groupBy.GroupingProperties.Should().HaveCount(2); List <GroupByPropertyNode> groupingProperties = groupBy.GroupingProperties.ToList(); VerifyIsFakeSingleValueNode(groupingProperties[0].Expression); VerifyIsFakeSingleValueNode(groupingProperties[1].Expression); groupBy.ChildTransformations.Should().BeNull(); }
private void Translate(GroupByTransformationNode transformation) { bool appendComma = false; foreach (GroupByPropertyNode node in transformation.GroupingProperties) { if (appendComma) { AppendComma(appendComma); } else { appendComma = true; query.Append(ExpressionConstants.SymbolOpenParen); } Translate(node); } if (appendComma) { query.Append(ExpressionConstants.SymbolClosedParen); } if (transformation.ChildTransformations != null) { AppendComma(true); Translate(transformation.ChildTransformations); } }
public void BindApplyWitGroupByWithComplexAndNavigationShouldReturnApplyClause() { IEnumerable <QueryToken> tokens = _parser.ParseApply("groupby((MyAddress/PostBoxPainting/Artist))"); MetadataBinder metadataBiner = new MetadataBinder(_bindingState); ApplyBinder binder = new ApplyBinder(metadataBiner.Bind, _bindingState); ApplyClause actual = binder.BindApply(tokens); Assert.NotNull(actual); var transformation = Assert.Single(actual.Transformations); GroupByTransformationNode groupBy = Assert.IsType <GroupByTransformationNode>(transformation); Assert.Equal(TransformationNodeKind.GroupBy, groupBy.Kind); Assert.Null(groupBy.ChildTransformations); Assert.NotNull(groupBy.GroupingProperties); GroupByPropertyNode addressNode = Assert.Single(groupBy.GroupingProperties); Assert.Equal("MyAddress", addressNode.Name); Assert.Null(addressNode.Expression); GroupByPropertyNode postBoxPaintingNode = Assert.Single(addressNode.ChildTransformations); Assert.Equal("PostBoxPainting", postBoxPaintingNode.Name); Assert.Null(postBoxPaintingNode.Expression); GroupByPropertyNode artistNode = Assert.Single(postBoxPaintingNode.ChildTransformations); Assert.Equal("Artist", artistNode.Name); Assert.NotNull(artistNode.Expression); Assert.Empty(artistNode.ChildTransformations); }
public void BindApplyWitGroupByWithNavigationShouldReturnApplyClause() { IEnumerable <QueryToken> tokens = _parser.ParseApply("groupby((MyDog/City))"); ApplyBinder binder = new ApplyBinder(FakeBindMethods.BindMethodReturnsPersonDogColorNavigation, _bindingState); ApplyClause actual = binder.BindApply(tokens); Assert.NotNull(actual); GroupByTransformationNode groupBy = Assert.IsType <GroupByTransformationNode>(Assert.Single(actual.Transformations)); Assert.Equal(TransformationNodeKind.GroupBy, groupBy.Kind); Assert.NotNull(groupBy.GroupingProperties); Assert.Null(groupBy.ChildTransformations); GroupByPropertyNode dogNode = Assert.Single(groupBy.GroupingProperties); Assert.Null(dogNode.Expression); Assert.Equal("MyDog", dogNode.Name); Assert.NotNull(dogNode.ChildTransformations); List <GroupByPropertyNode> groupingProperties = groupBy.GroupingProperties.ToList(); Assert.Null(groupBy.ChildTransformations); GroupByPropertyNode colorNode = Assert.Single(dogNode.ChildTransformations); Assert.Equal("Color", colorNode.Name); Assert.Same(FakeBindMethods.FakePersonDogColorNode, colorNode.Expression); Assert.Empty(colorNode.ChildTransformations); }
private MethodCallExpression ApplyGroupBy(Expression source, GroupByTransformationNode transformation) { Type sourceType = OeExpressionHelper.GetCollectionItemType(source.Type); ParameterExpression sourceParameter = Expression.Parameter(sourceType); var visitor = CreateVisitor(sourceParameter); var expressions = new List <Expression>(); foreach (GroupByPropertyNode node in transformation.GroupingProperties) { if (node.ChildTransformations != null && node.ChildTransformations.Count > 0) { if (node.ChildTransformations.Count > 1) { throw new NotSupportedException(); } GroupByPropertyNode childNode = node.ChildTransformations[0]; String propertyName = node.Name + "_" + childNode.Name; Expression e = visitor.TranslateNode(childNode.Expression); expressions.Add(e); _aggProperties.Add(CreateEdmProperty(_visitor.EdmModel, e.Type, propertyName, true)); } else { Expression e = visitor.TranslateNode(node.Expression); expressions.Add(e); _aggProperties.Add(CreateEdmProperty(_visitor.EdmModel, e.Type, node.Name, true)); } } NewExpression newExpression = OeExpressionHelper.CreateTupleExpression(expressions); LambdaExpression lambda = Expression.Lambda(newExpression, sourceParameter); MethodInfo groupByMethodInfo = OeMethodInfoHelper.GetGroupByMethodInfo(sourceType, newExpression.Type); MethodCallExpression groupByCall = Expression.Call(groupByMethodInfo, source, lambda); var aggTransformation = (AggregateTransformationNode)transformation.ChildTransformations; if (aggTransformation == null) { expressions.Clear(); sourceType = OeExpressionHelper.GetCollectionItemType(groupByCall.Type); sourceParameter = Expression.Parameter(sourceType); expressions.Add(Expression.Property(sourceParameter, nameof(IGrouping <Object, Object> .Key))); newExpression = OeExpressionHelper.CreateTupleExpression(expressions); MethodInfo selectMethodInfo = OeMethodInfoHelper.GetSelectMethodInfo(sourceType, newExpression.Type); lambda = Expression.Lambda(newExpression, sourceParameter); return(Expression.Call(selectMethodInfo, groupByCall, lambda)); } return(ApplyAggregate(groupByCall, aggTransformation)); }
public void BindApplyWitGroupByWithAggregateShouldReturnApplyClause() { IEnumerable <QueryToken> tokens = _parser.ParseApply("groupby((UnitPrice, SalePrice), aggregate(UnitPrice with sum as TotalPrice))"); ApplyBinder binder = new ApplyBinder(FakeBindMethods.BindSingleComplexProperty, _bindingState); ApplyClause actual = binder.BindApply(tokens); Assert.NotNull(actual); GroupByTransformationNode groupBy = Assert.IsType <GroupByTransformationNode>(Assert.Single(actual.Transformations)); Assert.NotNull(groupBy.ChildTransformations); }
public void BindApplyWitGroupByWithNavigationAndDeepComplexAndNavigationShouldReturnApplyClause() { IEnumerable <QueryToken> tokens = _parser.ParseApply("groupby((MyFavoritePainting/ArtistAddress/NextHome/PostBoxPainting/Artist))"); MetadataBinder metadataBiner = new MetadataBinder(_bindingState); ApplyBinder binder = new ApplyBinder(metadataBiner.Bind, _bindingState); ApplyClause actual = binder.BindApply(tokens); actual.Should().NotBeNull(); actual.Transformations.Should().HaveCount(1); List <TransformationNode> transformations = actual.Transformations.ToList(); GroupByTransformationNode groupBy = transformations[0] as GroupByTransformationNode; groupBy.Should().NotBeNull(); groupBy.Kind.Should().Be(TransformationNodeKind.GroupBy); groupBy.GroupingProperties.Should().NotBeNull(); groupBy.GroupingProperties.Should().HaveCount(1); groupBy.ChildTransformations.Should().BeNull(); List <GroupByPropertyNode> groupingProperties = groupBy.GroupingProperties.ToList(); GroupByPropertyNode favoritePaintingNode = groupingProperties[0]; favoritePaintingNode.Name.Should().Be("MyFavoritePainting"); favoritePaintingNode.Expression.Should().BeNull(); favoritePaintingNode.ChildTransformations.Should().HaveCount(1); GroupByPropertyNode artistAddressNode = favoritePaintingNode.ChildTransformations[0]; artistAddressNode.Name.Should().Be("ArtistAddress"); artistAddressNode.Expression.Should().BeNull(); artistAddressNode.ChildTransformations.Should().HaveCount(1); GroupByPropertyNode nextHomeNode = artistAddressNode.ChildTransformations[0]; nextHomeNode.Name.Should().Be("NextHome"); nextHomeNode.Expression.Should().BeNull(); nextHomeNode.ChildTransformations.Should().HaveCount(1); GroupByPropertyNode postBoxPaintingNode = nextHomeNode.ChildTransformations[0]; postBoxPaintingNode.Name.Should().Be("PostBoxPainting"); postBoxPaintingNode.Expression.Should().BeNull(); postBoxPaintingNode.ChildTransformations.Should().HaveCount(1); GroupByPropertyNode artistNode = postBoxPaintingNode.ChildTransformations[0]; artistNode.Name.Should().Be("Artist"); artistNode.Expression.Should().NotBeNull(); artistNode.ChildTransformations.Should().BeEmpty(); }
public void BindApplyWitGroupByWithAggregateShouldReturnApplyClause() { IEnumerable <QueryToken> tokens = _parser.ParseApply("groupby((UnitPrice, SalePrice), aggregate(UnitPrice with sum as TotalPrice))"); ApplyBinder binder = new ApplyBinder(FakeBindMethods.BindSingleComplexProperty, _bindingState); ApplyClause actual = binder.BindApply(tokens); actual.Should().NotBeNull(); actual.Transformations.Should().HaveCount(1); List <TransformationNode> transformations = actual.Transformations.ToList(); GroupByTransformationNode groupBy = transformations[0] as GroupByTransformationNode; TransformationNode aggregate = groupBy.ChildTransformations; aggregate.Should().NotBeNull(); }
public void BindApplyWitGroupByWithDeepNavigationAndComplexShouldReturnApplyClause() { IEnumerable <QueryToken> tokens = _parser.ParseApply("groupby((MyDog/LionWhoAteMe/LionHeartbeat/Frequency))"); MetadataBinder metadataBiner = new MetadataBinder(_bindingState); ApplyBinder binder = new ApplyBinder(metadataBiner.Bind, _bindingState); ApplyClause actual = binder.BindApply(tokens); actual.Should().NotBeNull(); actual.Transformations.Should().HaveCount(1); List <TransformationNode> transformations = actual.Transformations.ToList(); GroupByTransformationNode groupBy = transformations[0] as GroupByTransformationNode; groupBy.Should().NotBeNull(); groupBy.Kind.Should().Be(TransformationNodeKind.GroupBy); groupBy.GroupingProperties.Should().NotBeNull(); groupBy.GroupingProperties.Should().HaveCount(1); groupBy.ChildTransformations.Should().BeNull(); List <GroupByPropertyNode> groupingProperties = groupBy.GroupingProperties.ToList(); GroupByPropertyNode dogNode = groupingProperties[0]; dogNode.Name.Should().Be("MyDog"); dogNode.Expression.Should().BeNull(); dogNode.ChildTransformations.Should().HaveCount(1); GroupByPropertyNode lionNode = dogNode.ChildTransformations[0]; lionNode.Name.Should().Be("LionWhoAteMe"); lionNode.Expression.Should().BeNull(); lionNode.ChildTransformations.Should().HaveCount(1); GroupByPropertyNode heartBeatNode = lionNode.ChildTransformations[0]; heartBeatNode.Name.Should().Be("LionHeartbeat"); heartBeatNode.Expression.Should().BeNull(); heartBeatNode.ChildTransformations.Should().HaveCount(1); GroupByPropertyNode frequencyNode = heartBeatNode.ChildTransformations[0]; frequencyNode.Name.Should().Be("Frequency"); frequencyNode.Expression.Should().NotBeNull(); frequencyNode.ChildTransformations.Should().BeEmpty(); }
public void BindApplyWithExpandReturnApplyClause() { IEnumerable <QueryToken> tokens = _parser.ParseApply( "expand(MyPaintings, filter(FrameColor eq 'Red'))/groupby((LifeTime),aggregate(MyPaintings($count as Count)))"); BindingState state = new BindingState(_configuration); MetadataBinder metadataBiner = new MetadataBinder(_bindingState); ApplyBinder binder = new ApplyBinder(metadataBiner.Bind, _bindingState, V4configuration, new ODataPathInfo(HardCodedTestModel.GetPersonType(), HardCodedTestModel.GetPeopleSet())); ApplyClause actual = binder.BindApply(tokens); actual.Should().NotBeNull(); actual.Transformations.Should().HaveCount(2); ExpandTransformationNode expand = actual.Transformations.First() as ExpandTransformationNode; expand.Should().NotBeNull(); expand.ExpandClause.Should().NotBeNull(); expand.ExpandClause.SelectedItems.Should().HaveCount(1); ExpandedNavigationSelectItem expandItem = expand.ExpandClause.SelectedItems.First() as ExpandedNavigationSelectItem; expandItem.Should().NotBeNull(); expandItem.NavigationSource.Name.ShouldBeEquivalentTo("Paintings"); expandItem.FilterOption.Should().NotBeNull(); GroupByTransformationNode groupBy = actual.Transformations.Last() as GroupByTransformationNode; groupBy.Should().NotBeNull(); groupBy.GroupingProperties.Should().HaveCount(1); AggregateTransformationNode aggregate = groupBy.ChildTransformations as AggregateTransformationNode; aggregate.Should().NotBeNull(); aggregate.AggregateExpressions.Should().HaveCount(1); EntitySetAggregateExpression entitySetAggregate = aggregate.AggregateExpressions.First() as EntitySetAggregateExpression; entitySetAggregate.Should().NotBeNull(); }
public void BindApplyWitGroupByWithDeepNavigationShouldReturnApplyClause() { IEnumerable <QueryToken> tokens = _parser.ParseApply("groupby((MyDog/FastestOwner/FirstName))"); MetadataBinder metadataBiner = new MetadataBinder(_bindingState); ApplyBinder binder = new ApplyBinder(metadataBiner.Bind, _bindingState); ApplyClause actual = binder.BindApply(tokens); actual.Should().NotBeNull(); actual.Transformations.Should().HaveCount(1); List <TransformationNode> transformations = actual.Transformations.ToList(); GroupByTransformationNode groupBy = transformations[0] as GroupByTransformationNode; groupBy.Should().NotBeNull(); groupBy.Kind.Should().Be(TransformationNodeKind.GroupBy); groupBy.GroupingProperties.Should().NotBeNull(); groupBy.GroupingProperties.Should().HaveCount(1); groupBy.ChildTransformations.Should().BeNull(); List <GroupByPropertyNode> groupingProperties = groupBy.GroupingProperties.ToList(); GroupByPropertyNode dogNode = groupingProperties[0]; dogNode.Name.Should().Be("MyDog"); dogNode.Expression.Should().BeNull(); dogNode.ChildTransformations.Should().HaveCount(1); GroupByPropertyNode ownerNode = dogNode.ChildTransformations[0]; ownerNode.Name.Should().Be("FastestOwner"); ownerNode.Expression.Should().BeNull(); ownerNode.ChildTransformations.Should().HaveCount(1); GroupByPropertyNode nameNode = ownerNode.ChildTransformations[0]; nameNode.Name.Should().Be("FirstName"); nameNode.Expression.Should().NotBeNull(); nameNode.ChildTransformations.Should().BeEmpty(); }
public void BindApplyWitGroupByShouldReturnApplyClause() { IEnumerable <QueryToken> tokens = _parser.ParseApply("groupby((UnitPrice, SalePrice))"); ApplyBinder binder = new ApplyBinder(FakeBindMethods.BindSingleComplexProperty, _bindingState); ApplyClause actual = binder.BindApply(tokens); Assert.NotNull(actual); GroupByTransformationNode groupBy = Assert.IsType <GroupByTransformationNode>(Assert.Single(actual.Transformations)); Assert.Equal(TransformationNodeKind.GroupBy, groupBy.Kind); Assert.NotNull(groupBy.GroupingProperties); Assert.Equal(2, groupBy.GroupingProperties.Count()); List <GroupByPropertyNode> groupingProperties = groupBy.GroupingProperties.ToList(); VerifyIsFakeSingleValueNode(groupingProperties[0].Expression); VerifyIsFakeSingleValueNode(groupingProperties[1].Expression); Assert.Null(groupBy.ChildTransformations); }
public void BindApplyWitGroupByWithDeepNavigationAndComplexShouldReturnApplyClause() { IEnumerable <QueryToken> tokens = _parser.ParseApply("groupby((MyDog/LionWhoAteMe/LionHeartbeat/Frequency))"); MetadataBinder metadataBiner = new MetadataBinder(_bindingState); ApplyBinder binder = new ApplyBinder(metadataBiner.Bind, _bindingState); ApplyClause actual = binder.BindApply(tokens); Assert.NotNull(actual); var transformation = Assert.Single(actual.Transformations); GroupByTransformationNode groupBy = Assert.IsType <GroupByTransformationNode>(transformation); Assert.Equal(TransformationNodeKind.GroupBy, groupBy.Kind); Assert.Null(groupBy.ChildTransformations); Assert.NotNull(groupBy.GroupingProperties); GroupByPropertyNode dogNode = Assert.Single(groupBy.GroupingProperties); Assert.Equal("MyDog", dogNode.Name); Assert.Null(dogNode.Expression); GroupByPropertyNode lionNode = Assert.Single(dogNode.ChildTransformations); Assert.Equal("LionWhoAteMe", lionNode.Name); Assert.Null(lionNode.Expression); GroupByPropertyNode heartBeatNode = Assert.Single(lionNode.ChildTransformations); Assert.Equal("LionHeartbeat", heartBeatNode.Name); Assert.Null(heartBeatNode.Expression); GroupByPropertyNode frequencyNode = Assert.Single(heartBeatNode.ChildTransformations); Assert.Equal("Frequency", frequencyNode.Name); Assert.NotNull(frequencyNode.Expression); Assert.Empty(frequencyNode.ChildTransformations); }
public void BindVirtualPropertiesAfterCollapseReturnsApplyClause() { IEnumerable <QueryToken> tokens = _parser.ParseApply( "groupby((ID))/aggregate($count as Count)"); BindingState state = new BindingState(_configuration); MetadataBinder metadataBiner = new MetadataBinder(_bindingState); ApplyBinder binder = new ApplyBinder(metadataBiner.Bind, _bindingState); ApplyClause actual = binder.BindApply(tokens); actual.Should().NotBeNull(); actual.Transformations.Should().HaveCount(2); GroupByTransformationNode groupby = actual.Transformations.First() as GroupByTransformationNode; groupby.Should().NotBeNull(); AggregateTransformationNode aggregate = actual.Transformations.Last() as AggregateTransformationNode; aggregate.Should().NotBeNull(); aggregate.AggregateExpressions.Should().HaveCount(1); aggregate.AggregateExpressions.Single().As <AggregateExpression>().Method.ShouldBeEquivalentTo(AggregationMethod.VirtualPropertyCount); }
public void BindApplyWithEntitySetAggregationReturnApplyClause() { IEnumerable <QueryToken> tokens = _parser.ParseApply( "groupby((LifeTime),aggregate(MyPaintings($count as Count)))"); BindingState state = new BindingState(_configuration); MetadataBinder metadataBiner = new MetadataBinder(_bindingState); ApplyBinder binder = new ApplyBinder(metadataBiner.Bind, _bindingState); ApplyClause actual = binder.BindApply(tokens); Assert.NotNull(actual); Assert.NotNull(actual.Transformations); GroupByTransformationNode groupBy = Assert.IsType <GroupByTransformationNode>(Assert.Single(actual.Transformations)); Assert.NotNull(groupBy.GroupingProperties); AggregateTransformationNode aggregate = Assert.IsType <AggregateTransformationNode>(groupBy.ChildTransformations); Assert.NotNull(aggregate.AggregateExpressions); Assert.IsType <EntitySetAggregateExpression>(Assert.Single(aggregate.AggregateExpressions)); }
public QueryGrouping Parse() { GroupByTransformationNode gnode = null; foreach (var x in node.Transformations) { if (x.Kind == TransformationNodeKind.GroupBy) { gnode = x as GroupByTransformationNode; break; } } if (gnode == null) { return(null); } List <string> properties = null; List <short> types = null; foreach (var x in gnode.GroupingProperties) { PropertyInfo lastProperty; var property = buildPropertyAccess(x.Expression as SingleValuePropertyAccessNode, out lastProperty); if (property == null) { continue; } if (properties == null) { properties = new List <string>(); } if (types == null) { types = new List <short>(); } properties.Add(property); types.Add(getType(lastProperty)); } if (properties == null) { return(null); } var aggregations = new List <QueryAggregation>(); QueryGrouping result = new QueryGrouping { Keys = properties, Aggregations = aggregations, DateTimeTypes = types }; if (gnode.ChildTransformations == null || gnode.ChildTransformations.Kind != TransformationNodeKind.Aggregate) { return(result); } foreach (var x in (gnode.ChildTransformations as AggregateTransformationNode).Expressions) { if (x.Expression == null && x.Method != AggregationMethod.CountDistinct) { continue; } string property = null; if (x.Expression != null) { property = buildPropertyAccess(x.Expression as SingleValuePropertyAccessNode); if (property == null) { continue; } } aggregations.Add(new QueryAggregation { Operator = getTransformation(x.Method), Property = property, Alias = x.Alias, IsCount = x.Method == AggregationMethod.CountDistinct }); } return(result); }