public Enumerator(DocumentDatabase database, DocumentsStorage documents, FieldsToFetch fieldsToFetch, string collection, bool isAllDocsCollection, IndexQueryServerSide query, QueryTimingsScope queryTimings, DocumentsOperationContext context, IncludeDocumentsCommand includeDocumentsCommand, IncludeCompareExchangeValuesCommand includeCompareExchangeValuesCommand, Reference <int> totalResults, string startAfterId, Reference <long> alreadySeenIdsCount, DocumentFields fields) { _documents = documents; _fieldsToFetch = fieldsToFetch; _collection = collection; _isAllDocsCollection = isAllDocsCollection; _query = query; _context = context; _totalResults = totalResults; _totalResults.Value = 0; _startAfterId = startAfterId; _alreadySeenIdsCount = alreadySeenIdsCount; _fields = fields; if (_fieldsToFetch.IsDistinct) { _alreadySeenProjections = new HashSet <ulong>(); } _resultsRetriever = new MapQueryResultRetriever(database, query, queryTimings, documents, context, fieldsToFetch, includeDocumentsCommand, includeCompareExchangeValuesCommand); (_ids, _startsWith) = ExtractIdsFromQuery(query, context); }
public Enumerator(DocumentDatabase database, DocumentsStorage documents, FieldsToFetch fieldsToFetch, string collection, bool isAllDocsCollection, IndexQueryServerSide query, DocumentsOperationContext context, IncludeDocumentsCommand includeDocumentsCommand, Reference <int> totalResults) { _documents = documents; _fieldsToFetch = fieldsToFetch; _collection = collection; _isAllDocsCollection = isAllDocsCollection; _query = query; _context = context; _totalResults = totalResults; _totalResults.Value = 0; if (_fieldsToFetch.IsDistinct) { _alreadySeenProjections = new HashSet <ulong>(); } _ids = ExtractIdsFromQuery(query); if (_ids != null && _ids.Count > BooleanQuery.MaxClauseCount) { throw new BooleanQuery.TooManyClauses(); } _sort = ExtractSortFromQuery(query); _resultsRetriever = new MapQueryResultRetriever(database, query, documents, context, fieldsToFetch, includeDocumentsCommand); }
public CollectionQueryEnumerable(DocumentsStorage documents, FieldsToFetch fieldsToFetch, string collection, IndexQueryServerSide query, DocumentsOperationContext context) { _documents = documents; _fieldsToFetch = fieldsToFetch; _collection = collection; _isAllDocsCollection = collection == Constants.Indexing.AllDocumentsCollection; _query = query; _context = context; }
public CollectionQueryEnumerable(DocumentDatabase database, DocumentsStorage documents, FieldsToFetch fieldsToFetch, string collection, IndexQueryServerSide query, DocumentsOperationContext context, IncludeDocumentsCommand includeDocumentsCommand, Reference <int> totalResults) { _database = database; _documents = documents; _fieldsToFetch = fieldsToFetch; _collection = collection; _isAllDocsCollection = collection == Constants.Documents.Collections.AllDocumentsCollection; _query = query; _context = context; _includeDocumentsCommand = includeDocumentsCommand; _totalResults = totalResults; }
public Enumerator(DocumentsStorage documents, FieldsToFetch fieldsToFetch, string collection, bool isAllDocsCollection, IndexQueryServerSide query, DocumentsOperationContext context) { _documents = documents; _fieldsToFetch = fieldsToFetch; _collection = collection; _isAllDocsCollection = isAllDocsCollection; _query = query; _context = context; if (_fieldsToFetch.IsDistinct) { _alreadySeenProjections = new HashSet <ulong>(); } _ids = ExtractIdsFromQuery(query); _sort = ExtractSortFromQuery(query); }
public CollectionQueryEnumerable(DocumentDatabase database, DocumentsStorage documents, FieldsToFetch fieldsToFetch, string collection, IndexQueryServerSide query, QueryTimingsScope queryTimings, DocumentsOperationContext context, IncludeDocumentsCommand includeDocumentsCommand, IncludeRevisionsCommand includeRevisionsCommand, IncludeCompareExchangeValuesCommand includeCompareExchangeValuesCommand, Reference <int> totalResults, Reference <int> scannedResults, Reference <long> skippedResults, CancellationToken token) { _database = database; _documents = documents; _fieldsToFetch = fieldsToFetch; _collection = collection; _isAllDocsCollection = collection == Constants.Documents.Collections.AllDocumentsCollection; _query = query; _queryTimings = queryTimings; _context = context; _includeDocumentsCommand = includeDocumentsCommand; _includeRevisionsCommand = includeRevisionsCommand; _includeCompareExchangeValuesCommand = includeCompareExchangeValuesCommand; _totalResults = totalResults; _token = token; _scannedResults = scannedResults; _skippedResults = skippedResults; }
public void RegisterTimeSeriesFields(IndexQueryServerSide query, FieldsToFetch fields) { if (query.IsFromStudio == false || fields.AnyTimeSeries == false) { return; } foreach (var field in fields.Fields) { if (field.Value.IsTimeSeries) { TimeSeriesFields ??= new List <string>(); if (fields.SingleBodyOrMethodWithNoAlias) { // in this case, we have an empty array, which indicate // that we lifted the expression return; } TimeSeriesFields.Add(field.Key); } } }
public Enumerator(DocumentDatabase database, DocumentsStorage documents, FieldsToFetch fieldsToFetch, string collection, bool isAllDocsCollection, IndexQueryServerSide query, QueryTimingsScope queryTimings, DocumentsOperationContext context, IncludeDocumentsCommand includeDocumentsCommand, IncludeRevisionsCommand includeRevisionsCommand, IncludeCompareExchangeValuesCommand includeCompareExchangeValuesCommand, Reference <int> totalResults, Reference <int> scannedResults, string startAfterId, Reference <long> alreadySeenIdsCount, DocumentFields fields, Reference <long> skippedResults, CancellationToken token) { _documents = documents; _fieldsToFetch = fieldsToFetch; _collection = collection; _isAllDocsCollection = isAllDocsCollection; _query = query; _queryTimings = queryTimings; _context = context; _totalResults = totalResults; _scannedResults = scannedResults; _totalResults.Value = 0; _startAfterId = startAfterId; _alreadySeenIdsCount = alreadySeenIdsCount; _fields = fields; _skippedResults = skippedResults; _token = token; if (_fieldsToFetch.IsDistinct) { _alreadySeenProjections = new HashSet <ulong>(); } _resultsRetriever = new MapQueryResultRetriever(database, query, queryTimings, documents, context, fieldsToFetch, includeDocumentsCommand, includeCompareExchangeValuesCommand, includeRevisionsCommand); (_ids, _startsWith) = ExtractIdsFromQuery(query, context); if (_query.Metadata.FilterScript != null) { var key = new FilterKey(_query.Metadata); _releaseFilterScriptRunner = database.Scripts.GetScriptRunner(key, readOnly: true, patchRun: out _filterScriptRun); } }
private async Task <TResult> ExecuteQuery <TResult>(TResult final, IndexQueryServerSide query, DocumentsOperationContext documentsContext, long?existingResultEtag, OperationCancelToken token) where TResult : QueryResultServerSide <Document> { try { if (Database.ServerStore.Configuration.Core.FeaturesAvailability == FeaturesAvailability.Stable) { FeaturesAvailabilityException.Throw("Graph Queries"); } using (QueryRunner.MarkQueryAsRunning(Constants.Documents.Indexing.DummyGraphIndexName, query, token)) using (var timingScope = new QueryTimingsScope()) { var qr = await GetQueryResults(query, documentsContext, existingResultEtag, token); if (qr.NotModified) { final.NotModified = true; return(final); } var q = query.Metadata.Query; //TODO: handle order by, load, clauses IncludeDocumentsCommand idc = null; if (q.Select == null && q.SelectFunctionBody.FunctionText == null) { HandleResultsWithoutSelect(documentsContext, qr.Matches, final); } else if (q.Select != null) { //TODO : investigate fields to fetch var fieldsToFetch = new FieldsToFetch(query, null); idc = new IncludeDocumentsCommand(Database.DocumentsStorage, documentsContext, query.Metadata.Includes, fieldsToFetch.IsProjection); var resultRetriever = new GraphQueryResultRetriever( q.GraphQuery, Database, query, timingScope, Database.DocumentsStorage, documentsContext, fieldsToFetch, idc); HashSet <ulong> alreadySeenProjections = null; if (q.IsDistinct) { alreadySeenProjections = new HashSet <ulong>(); } foreach (var match in qr.Matches) { if (match.Empty) { continue; } var result = resultRetriever.ProjectFromMatch(match, documentsContext); // ReSharper disable once PossibleNullReferenceException if (q.IsDistinct && alreadySeenProjections.Add(result.DataHash) == false) { continue; } final.AddResult(result); } } if (idc == null) { idc = new IncludeDocumentsCommand(Database.DocumentsStorage, documentsContext, query.Metadata.Includes, isProjection: false); } if (query.Metadata.Includes?.Length > 0) { foreach (var result in final.Results) { idc.Gather(result); } } idc.Fill(final.Includes); final.TotalResults = final.Results.Count; if (query.Limit != null || query.Offset != null) { final.CappedMaxResults = Math.Min( query.Limit ?? int.MaxValue, final.TotalResults - (query.Offset ?? 0) ); } final.IsStale = qr.QueryPlan.IsStale; final.ResultEtag = qr.QueryPlan.ResultEtag; return(final); } } catch (OperationCanceledException oce) { throw new OperationCanceledException($"Database:{Database} Query:{query.Metadata.Query} has been cancelled ", oce); } }