private JsonDocument RetrieveDocumentInternal( IndexQueryResult queryResult, HashSet<string> loadedIds, IEnumerable<string> fieldsToFetch, IndexDefinition indexDefinition, AggregationOperation aggregationOperation) { if (queryResult.Projection == null) { // duplicate document, filter it out if (loadedIds.Add(queryResult.Key) == false) return null; return GetDocumentWithCaching(queryResult.Key); } if (fieldsToFetch != null) { if (indexDefinition.IsMapReduce == false) { bool hasStoredFields = false; foreach (var fieldToFetch in fieldsToFetch) { FieldStorage value; if (indexDefinition.Stores.TryGetValue(fieldToFetch, out value) == false && value != FieldStorage.No) continue; hasStoredFields = true; } if (hasStoredFields == false) { // duplicate document, filter it out if (loadedIds.Add(queryResult.Key) == false) return null; } } if (aggregationOperation != AggregationOperation.None) { var aggOpr = aggregationOperation & ~AggregationOperation.Dynamic; fieldsToFetch = fieldsToFetch.Concat(new[] {aggOpr.ToString()}); } var fieldsToFetchFromDocument = fieldsToFetch.Where(fieldToFetch => queryResult.Projection.Property(fieldToFetch) == null); var doc = GetDocumentWithCaching(queryResult.Key); if (doc != null) { var result = doc.DataAsJson.SelectTokenWithRavenSyntax(fieldsToFetchFromDocument.ToArray()); foreach (var property in result.Properties()) { if(property.Value == null || property.Value.Type == JTokenType.Null) continue; queryResult.Projection[property.Name] = property.Value; } } } return new JsonDocument { Key = queryResult.Key, Projection = queryResult.Projection, }; }
public FieldsToFetch(string[] fieldsToFetch, AggregationOperation aggregationOperation, string additionalField) { this.additionalField = additionalField; if (fieldsToFetch != null) { this.fieldsToFetch = new HashSet <string>(fieldsToFetch); FetchAllStoredFields = this.fieldsToFetch.Remove(Constants.AllFields); } this.aggregationOperation = aggregationOperation.RemoveOptionals(); if (this.aggregationOperation != AggregationOperation.None) { EnsureHasField(this.aggregationOperation.ToString()); } IsDistinctQuery = aggregationOperation.HasFlag(AggregationOperation.Distinct) && fieldsToFetch != null && fieldsToFetch.Length > 0; IsProjection = fieldsToFetch != null && fieldsToFetch.Length != 0; if (IsProjection && IsDistinctQuery == false) { EnsureHasField(additionalField); } }
public void SetAggregation(AggregationOperation op) { OrderBy.Clear(); switch (op) { case AggregationOperation.Count: SelectAggregation = "COUNT"; break; case AggregationOperation.Max: SelectAggregation = "MAX"; break; case AggregationOperation.Min: SelectAggregation = "MIN"; break; case AggregationOperation.Sum: SelectAggregation = "SUM"; break; case AggregationOperation.Average: SelectAggregation = "AVG"; break; default: throw new ArgumentOutOfRangeException(nameof(op), op, null); } AggregationOperation = op; }
private DynamicQueryMappingItem(string name, AggregationOperation aggregationOperation, bool isSpecifiedInWhere, bool isFullTextSearch, bool isExactSearch) { Name = name; AggregationOperation = aggregationOperation; IsSpecifiedInWhere = isSpecifiedInWhere; IsFullTextSearch = isFullTextSearch; IsExactSearch = isExactSearch; }
public static DynamicQueryMappingItem Create(QueryFieldName name, AggregationOperation aggregation, Dictionary <QueryFieldName, WhereField> whereFields) { if (whereFields.TryGetValue(name, out var whereField)) { return(new DynamicQueryMappingItem(name, aggregation, GroupByArrayBehavior.NotApplicable, true, whereField.IsFullTextSearch, whereField.IsExactSearch, whereField.Spatial)); } return(new DynamicQueryMappingItem(name, aggregation, GroupByArrayBehavior.NotApplicable, false, false, false, null)); }
private DynamicQueryMappingItem(QueryFieldName name, AggregationOperation aggregationOperation, bool isSpecifiedInWhere, bool isFullTextSearch, bool isExactSearch, AutoSpatialOptions spatial) { Name = name; AggregationOperation = aggregationOperation; IsSpecifiedInWhere = isSpecifiedInWhere; IsFullTextSearch = isFullTextSearch; IsExactSearch = isExactSearch; Spatial = spatial; }
public static DynamicQueryMappingItem Create(string name, AggregationOperation aggregation, Dictionary <string, WhereField> whereFields) { if (whereFields.TryGetValue(name, out var whereField)) { return(new DynamicQueryMappingItem(name, aggregation, true, whereField.IsFullTextSearch, whereField.IsExactSearch)); } return(new DynamicQueryMappingItem(name, aggregation, false, false, false)); }
private DynamicQueryMappingItem( QueryFieldName name, AggregationOperation aggregationOperation, GroupByArrayBehavior groupByArrayBehavior, bool isSpecifiedInWhere, bool isFullTextSearch, bool isExactSearch, bool hasHighlighting, AutoSpatialOptions spatial) { Name = name; AggregationOperation = aggregationOperation; GroupByArrayBehavior = groupByArrayBehavior; HasHighlighting = hasHighlighting; IsSpecifiedInWhere = isSpecifiedInWhere; IsFullTextSearch = isFullTextSearch; IsExactSearch = isExactSearch; Spatial = spatial; }
public FieldsToFetch(string[] fieldsToFetch, AggregationOperation aggregationOperation, string additionalField) { this.additionalField = additionalField; if (fieldsToFetch != null) { this.fieldsToFetch = new HashSet<string>(fieldsToFetch); FetchAllStoredFields = this.fieldsToFetch.Remove(Constants.AllFields); } this.aggregationOperation = aggregationOperation.RemoveOptionals(); if (this.aggregationOperation != AggregationOperation.None) EnsureHasField(this.aggregationOperation.ToString()); IsDistinctQuery = aggregationOperation.HasFlag(AggregationOperation.Distinct) && fieldsToFetch != null && fieldsToFetch.Length > 0; IsProjection = this.fieldsToFetch != null && this.fieldsToFetch.Count > 0; if(IsProjection && IsDistinctQuery == false) EnsureHasField(additionalField); }
///<summary> /// Instruct the index to group by the specified fields using the specified aggregation operation ///</summary> /// <remarks> /// This is only valid on dynamic indexes queries /// </remarks> public IDocumentQuery <T> GroupBy(AggregationOperation aggregationOperation, params string[] fieldsToGroupBy) { ApplyForAll(x => x.GroupBy(aggregationOperation, fieldsToGroupBy)); return(this); }
public bool ShouldIncludeResultInQuery(IndexQueryResult arg, IndexDefinition indexDefinition, string[] fieldsToFetch, AggregationOperation aggregationOperation) { var doc = RetrieveDocumentInternal(arg, loadedIdsForFilter, fieldsToFetch, indexDefinition, aggregationOperation); if (doc == null) return false; doc = ProcessReadVetoes(doc, null, ReadOperation.Query); return doc != null; }
public JsonDocument RetrieveDocumentForQuery(IndexQueryResult queryResult, IndexDefinition indexDefinition, string[] fieldsToFetch, AggregationOperation aggregationOperation) { var doc = RetrieveDocumentInternal(queryResult, loadedIdsForRetrieval, fieldsToFetch, indexDefinition, aggregationOperation); return ExecuteReadTriggers(doc, null, ReadOperation.Query); }
///<summary> /// Instruct the index to group by the specified fields using the specified aggregation operation ///</summary> ///<remarks> /// This is only valid on dynamic indexes queries ///</remarks> public IAsyncDocumentQuery <T> GroupBy <TValue>(AggregationOperation aggregationOperation, params Expression <Func <T, TValue> >[] groupPropertySelectors) { GroupBy(aggregationOperation, groupPropertySelectors.Select(GetMemberQueryPath).ToArray()); return(this); }
public static DynamicQueryMappingItem Create(string name, AggregationOperation aggregation) { return(new DynamicQueryMappingItem(name, aggregation, false, false, false)); }
public static DynamicQueryMappingItem Create(QueryFieldName name, AggregationOperation aggregation) { return(new DynamicQueryMappingItem(name, aggregation, GroupByArrayBehavior.NotApplicable, false, false, false, null)); }
public static DynamicQueryMappingItem Create(string name, AggregationOperation aggregation, bool isFullTextSearch, bool isExactSearch) { return(new DynamicQueryMappingItem(name, aggregation, false, isFullTextSearch, isExactSearch)); }
///<summary> /// Instruct the index to group by the specified fields using the specified aggregation operation ///</summary> ///<remarks> /// This is only valid on dynamic indexes queries ///</remarks> public IDocumentQuery <T> GroupBy <TValue>(AggregationOperation aggregationOperation, params Expression <Func <T, TValue> >[] groupPropertySelectors) { GroupBy(aggregationOperation, groupPropertySelectors.Select(x => x.GetPropertyName()).ToArray()); return(this); }
public static AggregationOperation RemoveOptionals(this AggregationOperation operation) { return((operation & ~AggregationOperation.Distinct) & ~AggregationOperation.Dynamic); }
public bool ShouldIncludeResultInQuery(IndexQueryResult arg, IndexDefinition indexDefinition, string[] fieldsToFetch, AggregationOperation aggregationOperation) { var doc = RetrieveDocumentInternal(arg, loadedIdsForFilter, fieldsToFetch, indexDefinition, aggregationOperation); if (doc == null) { return(false); } doc = ProcessReadVetoes(doc, null, ReadOperation.Query); return(doc != null); }
private static void ThrowUnknownAggregationOperation(AggregationOperation operation) { throw new InvalidOperationException($"Unknown aggregation operation defined: {operation}"); }
public JsonDocument RetrieveDocumentForQuery(IndexQueryResult queryResult, IndexDefinition indexDefinition, string[] fieldsToFetch, AggregationOperation aggregationOperation) { return(ExecuteReadTriggers(ProcessReadVetoes( RetrieveDocumentInternal(queryResult, loadedIdsForRetrieval, fieldsToFetch, indexDefinition, aggregationOperation), null, ReadOperation.Query), null, ReadOperation.Query)); }
public static SelectField CreateGroupByAggregation(QueryFieldName name, string alias, AggregationOperation aggregation) { return(new SelectField { Name = name, Alias = alias, AggregationOperation = aggregation }); }
private JsonDocument RetrieveDocumentInternal( IndexQueryResult queryResult, HashSet <string> loadedIds, IEnumerable <string> fieldsToFetch, IndexDefinition indexDefinition, AggregationOperation aggregationOperation) { if (queryResult.Projection == null) { // duplicate document, filter it out if (loadedIds.Add(queryResult.Key) == false) { return(null); } return(GetDocumentWithCaching(queryResult.Key)); } if (fieldsToFetch != null) { if (indexDefinition.IsMapReduce == false) { bool hasStoredFields = false; foreach (var fieldToFetch in fieldsToFetch) { FieldStorage value; if (indexDefinition.Stores.TryGetValue(fieldToFetch, out value) == false && value != FieldStorage.No) { continue; } hasStoredFields = true; } if (hasStoredFields == false) { // duplicate document, filter it out if (loadedIds.Add(queryResult.Key) == false) { return(null); } } } if (aggregationOperation != AggregationOperation.None) { var aggOpr = aggregationOperation & ~AggregationOperation.Dynamic; fieldsToFetch = fieldsToFetch.Concat(new[] { aggOpr.ToString() }); } var fieldsToFetchFromDocument = fieldsToFetch.Where(fieldToFetch => queryResult.Projection.Property(fieldToFetch) == null); var doc = GetDocumentWithCaching(queryResult.Key); if (doc != null) { var result = doc.DataAsJson.SelectTokenWithRavenSyntax(fieldsToFetchFromDocument.ToArray()); foreach (var property in result.Properties()) { if (property.Value == null || property.Value.Type == JTokenType.Null) { continue; } queryResult.Projection[property.Name] = property.Value; } } } return(new JsonDocument { Key = queryResult.Key, Projection = queryResult.Projection, }); }
public static DynamicQueryMappingItem Create(QueryFieldName name, AggregationOperation aggregation, bool isFullTextSearch, bool isExactSearch, AutoSpatialOptions spatial) { return(new DynamicQueryMappingItem(name, aggregation, GroupByArrayBehavior.NotApplicable, false, isFullTextSearch, isExactSearch, spatial)); }
public static SelectField CreateGroupByAggregation(string name, string alias, AggregationOperation aggregation) { return new SelectField { Name = name, Alias = alias, AggregationOperation = aggregation }; }
public void SetAggregation(AggregationOperation aggregation) { AggregationOperation = aggregation; }
///<summary> /// Instruct the index to group by the specified fields using the specified aggregation operation ///</summary> ///<remarks> /// This is only valid on dynamic indexes queries ///</remarks> public void GroupBy(AggregationOperation aggregationOperation, params string[] fieldsToGroupBy) { groupByFields = fieldsToGroupBy; aggregationOp = aggregationOperation; }
///<summary> /// Instruct the index to group by the specified fields using the specified aggregation operation ///</summary> /// <remarks> /// This is only valid on dynamic indexes queries /// </remarks> IAsyncDocumentQuery <T> IDocumentQueryBase <T, IAsyncDocumentQuery <T> > .GroupBy(AggregationOperation aggregationOperation, params string[] fieldsToGroupBy) { GroupBy(aggregationOperation, fieldsToGroupBy); return(this); }
public static DynamicQueryMappingItem Create(QueryFieldName name, AggregationOperation aggregation) { return(new DynamicQueryMappingItem(name, aggregation, false, false, false, null)); }