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 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); }
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); }
private static void RegisterProperty(IList <GroupByPropertyNode> properties, Stack <SingleValueNode> propertyStack) { var property = propertyStack.Pop(); string propertyName = GetNodePropertyName(property); if (propertyStack.Count != 0) { // Not at the leaf, let's add to the container. var containerProperty = properties.FirstOrDefault(p => p.Name == propertyName); if (containerProperty == null) { // We do not have container yet. Create it. containerProperty = new GroupByPropertyNode(propertyName, null); properties.Add(containerProperty); } RegisterProperty(containerProperty.Children, propertyStack); } else { // It's the leaf just add. var accessNode = property as SingleValuePropertyAccessNode; properties.Add(new GroupByPropertyNode(propertyName, property, accessNode.TypeReference)); } }
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 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(); }
private void ValidateGroupByPropertyNode(GroupByPropertyNode groupByProperty, ODataUrlValidationContext validationContext) { ValidateItem(groupByProperty, validationContext); validationContext.ExpressionValidator.ValidateNode(groupByProperty.Expression); foreach (GroupByPropertyNode childTransformation in groupByProperty.ChildTransformations) { ValidateGroupByPropertyNode(childTransformation, validationContext); } }
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 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(); }
private bool CompareGroupByPropertyNode(GroupByPropertyNode node1, GroupByPropertyNode node2) { if (node1 == node2) { return(true); } if (node1 == null || node2 == null) { return(false); } return(_queryNodeComparer.Compare(node1.Expression, node2.Expression) && EnumerableComparer.Compare(node1.ChildTransformations, node2.ChildTransformations, CompareGroupByPropertyNode)); }
private void Translate(GroupByPropertyNode node) { if (node.Expression != null) { AppendExpression(node.Expression); } bool appendCommaChild = false; foreach (GroupByPropertyNode childNode in node.ChildTransformations) { appendCommaChild = AppendComma(appendCommaChild); Translate(childNode); } }
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 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 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); }