From 3ba17f1c87f90cfb3a08bef66a5463a830b2a9e7 Mon Sep 17 00:00:00 2001 From: Kevin Darby Date: Thu, 12 Dec 2019 18:19:08 -0500 Subject: [PATCH] allow disk in query --- .../spark_historical/Notebooks/roll.ipynb | 38 ++++++++++++++++--- src/client/spark_historical/Query/Query.cs | 7 ++-- 2 files changed, 36 insertions(+), 9 deletions(-) diff --git a/src/client/spark_historical/Notebooks/roll.ipynb b/src/client/spark_historical/Notebooks/roll.ipynb index b517dabb1..e54b5d4a2 100644 --- a/src/client/spark_historical/Notebooks/roll.ipynb +++ b/src/client/spark_historical/Notebooks/roll.ipynb @@ -112,7 +112,7 @@ }, { "cell_type": "code", - "execution_count": 11, + "execution_count": 5, "metadata": { "scrolled": true }, @@ -131,7 +131,7 @@ }, { "cell_type": "code", - "execution_count": 12, + "execution_count": 6, "metadata": { "scrolled": true }, @@ -144,7 +144,7 @@ }, { "cell_type": "code", - "execution_count": 13, + "execution_count": 7, "metadata": {}, "outputs": [], "source": [ @@ -220,7 +220,7 @@ }, { "cell_type": "code", - "execution_count": 14, + "execution_count": 8, "metadata": {}, "outputs": [], "source": [ @@ -234,11 +234,37 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 9, "metadata": { "scrolled": true }, - "outputs": [], + "outputs": [ + { + "ename": "Unhandled Exception", + "evalue": "Command aggregate failed: Sort exceeded memory limit of 104857600 bytes, but did not opt in to external sorting. Aborting operation. Pass allowDiskUse:true to opt in..", + "output_type": "error", + "traceback": [ + "Unhandled Exception", + "Command aggregate failed: Sort exceeded memory limit of 104857600 bytes, but did not opt in to external sorting. Aborting operation. Pass allowDiskUse:true to opt in..", + " at MongoDB.Driver.Linq.MongoQueryProviderImpl`1.Execute(Expression expression)", + " at MongoDB.Driver.Linq.MongoQueryableImpl`2.GetEnumerator()", + " at bts.history.Query.stream_data[T,U](IEnumerable`1[] datastream, Func`3 function)+MoveNext() in c:\\code\\bts\\spark\\src\\client\\spark_historical\\Query\\Query.cs:line 70", + " at System.Linq.Enumerable.SelectEnumerableIterator`2.MoveNext()", + " at System.Linq.Enumerable.WhereEnumerableIterator`1.MoveNext()", + " at System.Linq.Enumerable.EnumerablePartition`1.MoveNext()", + " at Microsoft.DotNet.Interactive.Rendering.HtmlFormatter`1.<>c__DisplayClass7_0.b__4(T instance, TextWriter writer)", + " at Microsoft.DotNet.Interactive.Rendering.HtmlFormatter`1.Format(T instance, TextWriter writer)", + " at Microsoft.DotNet.Interactive.Rendering.TypeFormatter`1.Microsoft.DotNet.Interactive.Rendering.ITypeFormatter.Format(Object instance, TextWriter writer)", + " at Microsoft.DotNet.Interactive.Rendering.Formatter`1.FormatTo(T obj, TextWriter writer, String mimeType)", + " at Microsoft.DotNet.Interactive.Rendering.Formatter.FormatTo[T](T obj, TextWriter writer, String mimeType)", + " at Microsoft.DotNet.Interactive.Rendering.Formatter.ToDisplayString(Object obj, String mimeType)", + " at Microsoft.DotNet.Interactive.Kernel.display(Object value, String mimeType)", + " at Submission#10.<>d__0.MoveNext()", + "--- End of stack trace from previous location where exception was thrown ---", + " at Microsoft.CodeAnalysis.Scripting.ScriptExecutionState.RunSubmissionsAsync[TResult](ImmutableArray`1 precedingExecutors, Func`2 currentExecutor, StrongBox`1 exceptionHolderOpt, Func`2 catchExceptionOpt, CancellationToken cancellationToken)" + ] + } + ], "source": [ "var fill_model = new FIFOModel(new Bucket(20_000, 20_001));\n", "var stream = run_algo(algo_type, fill_model, algo_params,\n", diff --git a/src/client/spark_historical/Query/Query.cs b/src/client/spark_historical/Query/Query.cs index 5c1084193..ba65eeda6 100644 --- a/src/client/spark_historical/Query/Query.cs +++ b/src/client/spark_historical/Query/Query.cs @@ -35,15 +35,16 @@ namespace bts.history public IMongoQueryable queryable(string collection) { var coll = _db.GetCollection(collection); - IMongoQueryable res = coll.AsQueryable(); + IMongoQueryable res = queryable(coll); return res; } - public IMongoQueryable queryable(IMongoCollection collection) => collection.AsQueryable(); + public IMongoQueryable queryable(IMongoCollection collection) => + collection.AsQueryable(new AggregateOptions { AllowDiskUse = true } ); public IMongoQueryable timeseries(IMongoCollection collection, DateTime begin, DateTime end, bool use_sending_time = true) where H : IHasTimestamp { - IMongoQueryable res = collection.AsQueryable(); + IMongoQueryable res = queryable(collection); Expression> timeexpr = null; begin = begin.ToUniversalTime(); end = end.ToUniversalTime();