コード例 #1
0
        public IEnumerator <StreamResult <T> > Stream <T>(IQueryable <T> query, out QueryHeaderInformation queryHeaderInformation)
        {
            var queryProvider = (IRavenQueryProvider)query.Provider;
            var docQuery      = queryProvider.ToDocumentQuery <T>(query.Expression);

            return(Stream(docQuery, out queryHeaderInformation));
        }
コード例 #2
0
        public void CanStreamQueryResult()
        {
            using (var store = GetDocumentStore())
            {
                var index = new Users_ByName();
                index.Execute(store);

                for (int i = 0; i < 30; i++)
                {
                    store.DatabaseCommands.Put("users/" + i, null, RavenJObject.FromObject(new User {
                        Name = "Name" + i
                    }), new RavenJObject {
                        { "Raven-Entity-Name", "Users" }
                    });
                }
                WaitForIndexing(store);

                int count = 0;
                QueryHeaderInformation queryHeaders = null;
                var reader = store.DatabaseCommands.StreamQuery(index.IndexName, new IndexQuery {
                    Query = ""
                }, out queryHeaders);
                while (reader.MoveNext())
                {
                    Assert.Equal("Name" + count, reader.Current.Value <string>("Name"));
                    count++;
                }
                Assert.Equal(30, count);
            }
        }
コード例 #3
0
        public static Negotiator WithEtagAndLastModified(this Negotiator negotiator, QueryHeaderInformation stats)
        {
            var etag = stats.IndexEtag;
            var responseLastModified = stats.IndexTimestamp;

            return(WithEtagAndLastModified(negotiator, etag, responseLastModified));
        }
コード例 #4
0
ファイル: DocumentSession.cs プロジェクト: ybdev/ravendb
        public IEnumerator <StreamResult <T> > Stream <T>(IDocumentQuery <T> query, out QueryHeaderInformation queryHeaderInformation)
        {
            var ravenQueryInspector = ((IRavenQueryInspector)query);
            var indexQuery          = ravenQueryInspector.GetIndexQuery(false);
            var enumerator          = DatabaseCommands.StreamQuery(ravenQueryInspector.IndexQueried, indexQuery, out queryHeaderInformation);

            return(YieldQuery(query, enumerator));
        }
コード例 #5
0
        public IEnumerator <RavenJObject> StreamQuery(string index, IndexQuery query,
                                                      out QueryHeaderInformation queryHeaderInfo)
        {
            var reference        = new Reference <QueryHeaderInformation>();
            var streamQueryAsync = AsyncHelpers.RunSync(() => asyncServerClient.StreamQueryAsync(index, query, reference));

            queryHeaderInfo = reference.Value;
            return(new AsyncEnumerableWrapper <RavenJObject>(streamQueryAsync));
        }
コード例 #6
0
        public IEnumerator <StreamResult <T> > Stream <T>(IDocumentQuery <T> query, out QueryHeaderInformation queryHeaderInformation)
        {
            var ravenQueryInspector = ((IRavenQueryInspector)query);
            var indexQuery          = ravenQueryInspector.GetIndexQuery(false);

            if (indexQuery.WaitForNonStaleResults || indexQuery.WaitForNonStaleResultsAsOfNow)
            {
                throw new NotSupportedException(
                          "Since Stream() does not wait for indexing (by design), streaming query with WaitForNonStaleResults is not supported.");
            }
            IncrementRequestCount();
            var enumerator = DatabaseCommands.StreamQuery(ravenQueryInspector.IndexQueried, indexQuery, out queryHeaderInformation);

            return(YieldQuery(query, enumerator));
        }
コード例 #7
0
ファイル: DocumentSession.cs プロジェクト: xinix00/ravendb
        public IEnumerator <StreamResult <T> > Stream <T>(IDocumentQuery <T> query, out QueryHeaderInformation queryHeaderInformation)
        {
            var  indexQuery = query.GetIndexQuery(false);
            bool waitForNonStaleResultsWasSetGloably = this.Advanced.DocumentStore.Conventions.DefaultQueryingConsistency == ConsistencyOptions.AlwaysWaitForNonStaleResultsAsOfLastWrite;

            if (!waitForNonStaleResultsWasSetGloably && (indexQuery.WaitForNonStaleResults || indexQuery.WaitForNonStaleResultsAsOfNow))
            {
                throw new NotSupportedException(
                          "Since Stream() does not wait for indexing (by design), streaming query with WaitForNonStaleResults is not supported.");
            }
            IncrementRequestCount();
            var enumerator = DatabaseCommands.StreamQuery(query.IndexQueried, indexQuery, out queryHeaderInformation);

            return(YieldQuery(query, enumerator));
        }
コード例 #8
0
 public IEnumerator <StreamResult <T> > Stream <T>(IDocumentQuery <T> query, out QueryHeaderInformation queryHeaderInformation)
 {
     throw new NotSupportedException("Streams are currently not supported by sharded document store");
 }
コード例 #9
0
ファイル: QueryActions.cs プロジェクト: tryadiadi/ravendb
            public void Init()
            {
                highlightings     = new Dictionary <string, Dictionary <string, string[]> >();
                scoreExplanations = new Dictionary <string, string>();
                Func <IndexQueryResult, object> tryRecordHighlightingAndScoreExplanation = queryResult =>
                {
                    if (queryResult.Highligtings != null && (queryResult.Key != null || queryResult.HighlighterKey != null))
                    {
                        highlightings.Add(queryResult.Key ?? queryResult.HighlighterKey, queryResult.Highligtings);
                    }
                    if ((queryResult.Key != null || queryResult.ReduceVal != null) && queryResult.ScoreExplanation != null)
                    {
                        scoreExplanations.Add(queryResult.Key ?? queryResult.ReduceVal, queryResult.ScoreExplanation);
                    }
                    return(null);
                };

                stale          = false;
                indexTimestamp = Tuple.Create(DateTime.MinValue, Etag.Empty);
                resultEtag     = Etag.Empty;
                nonAuthoritativeInformation = false;

                if (string.IsNullOrEmpty(query.ResultsTransformer) == false &&
                    (query.FieldsToFetch == null || query.FieldsToFetch.Length == 0))
                {
                    query.FieldsToFetch = new[] { Constants.AllFields };
                }

                duration  = Stopwatch.StartNew();
                idsToLoad = new HashSet <string>(StringComparer.OrdinalIgnoreCase);

                var viewGenerator = database.IndexDefinitionStorage.GetViewGenerator(indexName);
                var index         = database.IndexDefinitionStorage.GetIndexDefinition(indexName);

                if (viewGenerator == null)
                {
                    throw new IndexDoesNotExistsException("Could not find index named: " + indexName);
                }

                resultEtag = database.Indexes.GetIndexEtag(index.Name, null, query.ResultsTransformer);

                stale = actions.Staleness.IsIndexStale(index.IndexId, query.Cutoff, query.CutoffEtag);

                if (stale == false && query.Cutoff == null && query.CutoffEtag == null)
                {
                    var indexInstance = database.IndexStorage.GetIndexInstance(indexName);
                    stale = stale || (indexInstance != null && indexInstance.IsMapIndexingInProgress);
                }

                if (stale &&
                    actions.Staleness.IsIndexStaleByTask(index.IndexId, query.Cutoff) == false &&
                    actions.Staleness.IsReduceStale(index.IndexId) == false)
                {
                    var forEntityNames  = viewGenerator.ForEntityNames.ToList();
                    var lastIndexedEtag = actions.Indexing.GetIndexStats(index.IndexId).LastIndexedEtag;

                    if (database.LastCollectionEtags.HasEtagGreaterThan(forEntityNames, lastIndexedEtag) == false)
                    {
                        stale = false;
                    }
                }

                indexTimestamp = actions.Staleness.IndexLastUpdatedAt(index.IndexId);
                var indexFailureInformation = actions.Indexing.GetFailureRate(index.IndexId);

                if (indexFailureInformation.IsInvalidIndex)
                {
                    throw new IndexDisabledException(indexFailureInformation);
                }
                docRetriever = new DocumentRetriever(database.Configuration, actions, database.ReadTriggers, database.InFlightTransactionalState, query.TransformerParameters, idsToLoad);
                var fieldsToFetch = new FieldsToFetch(query,
                                                      viewGenerator.ReduceDefinition == null
                                                ? Constants.DocumentIdFieldName
                                                : Constants.ReduceKeyFieldName);
                Func <IndexQueryResult, bool> shouldIncludeInResults =
                    result => docRetriever.ShouldIncludeResultInQuery(result, index, fieldsToFetch, ShouldSkipDuplicateChecking);
                var indexQueryResults = database.IndexStorage.Query(indexName, query, shouldIncludeInResults, fieldsToFetch, database.IndexQueryTriggers, cancellationToken);

                indexQueryResults = new ActiveEnumerable <IndexQueryResult>(indexQueryResults);

                if (query.ShowTimings)
                {
                    indexQueryResults = new TimedEnumerable <IndexQueryResult>(indexQueryResults, timeInMilliseconds => executionTimes[QueryTimings.Lucene] = timeInMilliseconds);
                }

                var docs = from queryResult in indexQueryResults
                           let doc = docRetriever.RetrieveDocumentForQuery(queryResult, index, fieldsToFetch, ShouldSkipDuplicateChecking)
                                     where doc != null
                                     let _ = nonAuthoritativeInformation |= (doc.NonAuthoritativeInformation ?? false)
                                                                            let __ = tryRecordHighlightingAndScoreExplanation(queryResult)
                                                                                     select doc;

                transformerErrors = new List <string>();
                results           = database
                                    .Queries
                                    .GetQueryResults(query, viewGenerator, docRetriever, docs, transformerErrors,
                                                     timeInMilliseconds => executionTimes[QueryTimings.LoadDocuments]    = timeInMilliseconds,
                                                     timeInMilliseconds => executionTimes[QueryTimings.TransformResults] = timeInMilliseconds,
                                                     query.ShowTimings, cancellationToken);

                Header = new QueryHeaderInformation
                {
                    Index          = indexName,
                    IsStale        = stale,
                    ResultEtag     = resultEtag,
                    IndexTimestamp = indexTimestamp.Item1,
                    IndexEtag      = indexTimestamp.Item2,
                    TotalResults   = query.TotalSize.Value
                };
            }