Example #1
0
		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,
			};
		}
Example #2
0
        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);
            }
        }
Example #3
0
        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;
        }
Example #4
0
 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));
        }
Example #6
0
 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;
 }
Example #7
0
        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));
        }
Example #8
0
 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;
 }
Example #9
0
		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);
		}
Example #10
0
 ///<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);
 }
Example #11
0
	    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;
		}
Example #12
0
		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);
		}
Example #13
0
 ///<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);
 }
Example #14
0
 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));
 }
Example #16
0
 public static DynamicQueryMappingItem Create(string name, AggregationOperation aggregation, bool isFullTextSearch, bool isExactSearch)
 {
     return(new DynamicQueryMappingItem(name, aggregation, false, isFullTextSearch, isExactSearch));
 }
Example #17
0
 ///<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);
 }
Example #18
0
 public static AggregationOperation RemoveOptionals(this AggregationOperation operation)
 {
     return((operation & ~AggregationOperation.Distinct) & ~AggregationOperation.Dynamic);
 }
Example #19
0
        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}");
 }
Example #21
0
 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));
 }
Example #22
0
 public static SelectField CreateGroupByAggregation(QueryFieldName name, string alias, AggregationOperation aggregation)
 {
     return(new SelectField
     {
         Name = name,
         Alias = alias,
         AggregationOperation = aggregation
     });
 }
Example #23
0
        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));
 }
Example #25
0
 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;
 }
Example #27
0
 ///<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;
 }
Example #28
0
 ///<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);
 }
Example #29
0
 public static DynamicQueryMappingItem Create(QueryFieldName name, AggregationOperation aggregation)
 {
     return(new DynamicQueryMappingItem(name, aggregation, false, false, false, null));
 }