diff options
author | Will Holley <willholley@gmail.com> | 2017-08-21 15:06:03 +0100 |
---|---|---|
committer | Will Holley <willholley@gmail.com> | 2017-09-04 08:14:14 +0100 |
commit | ad292208f878786583f82fc328ef27c0d7dac033 (patch) | |
tree | 6b0711466e38a6552934b77175f9941b4b6ceac3 | |
parent | 1bbb24454197c971126596731d0a05255338abe8 (diff) | |
download | couchdb-ad292208f878786583f82fc328ef27c0d7dac033.tar.gz |
include mrview options in _explain result
_explain previously returned the options passed in by the user but
not those modified at execution time by Mango. Now we include
index-specific options (mrargs for map/reduce indexes) in the output,
allowing us to see e.g. when include_docs was used.
-rw-r--r-- | src/mango/src/mango_cursor_view.erl | 45 | ||||
-rw-r--r-- | src/mango/test/02-basic-find-test.py | 13 |
2 files changed, 38 insertions, 20 deletions
diff --git a/src/mango/src/mango_cursor_view.erl b/src/mango/src/mango_cursor_view.erl index 2dcf1c71b..b292704c3 100644 --- a/src/mango/src/mango_cursor_view.erl +++ b/src/mango/src/mango_cursor_view.erl @@ -56,18 +56,31 @@ create(Db, Indexes, Selector, Opts) -> explain(Cursor) -> #cursor{ - index = Idx, - ranges = Ranges + opts = Opts } = Cursor, - case Ranges of - [empty] -> - [{range, empty}]; - _ -> - [{range, {[ - {start_key, mango_idx:start_key(Idx, Ranges)}, - {end_key, mango_idx:end_key(Idx, Ranges)} - ]}}] - end. + + BaseArgs = base_args(Cursor), + Args = apply_opts(Opts, BaseArgs), + [{mrargs, {[ + {include_docs, Args#mrargs.include_docs}, + {view_type, Args#mrargs.view_type}, + {reduce, Args#mrargs.reduce}, + {start_key, Args#mrargs.start_key}, + {end_key, Args#mrargs.end_key}, + {direction, Args#mrargs.direction}, + {stable, Args#mrargs.stable}, + {update, Args#mrargs.update} + ]}}]. + + +base_args(#cursor{index = Idx} = Cursor) -> + #mrargs{ + view_type = map, + reduce = false, + start_key = mango_idx:start_key(Idx, Cursor#cursor.ranges), + end_key = mango_idx:end_key(Idx, Cursor#cursor.ranges), + include_docs = true + }. execute(#cursor{db = Db, index = Idx, execution_stats = Stats} = Cursor0, UserFun, UserAcc) -> @@ -81,16 +94,10 @@ execute(#cursor{db = Db, index = Idx, execution_stats = Stats} = Cursor0, UserFu % empty indicates unsatisfiable ranges, so don't perform search {ok, UserAcc}; _ -> - BaseArgs = #mrargs{ - view_type = map, - reduce = false, - start_key = mango_idx:start_key(Idx, Cursor#cursor.ranges), - end_key = mango_idx:end_key(Idx, Cursor#cursor.ranges), - include_docs = true - }, + BaseArgs = base_args(Cursor), #cursor{opts = Opts, bookmark = Bookmark} = Cursor, Args0 = apply_opts(Opts, BaseArgs), - Args = mango_json_bookmark:update_args(Bookmark, Args0), + Args = mango_json_bookmark:update_args(Bookmark, Args0), UserCtx = couch_util:get_value(user_ctx, Opts, #user_ctx{}), DbOpts = [{user_ctx, UserCtx}], Result = case mango_idx:def(Idx) of diff --git a/src/mango/test/02-basic-find-test.py b/src/mango/test/02-basic-find-test.py index e634ce9fe..699166e28 100644 --- a/src/mango/test/02-basic-find-test.py +++ b/src/mango/test/02-basic-find-test.py @@ -14,7 +14,6 @@ import mango - class BasicFindTests(mango.UserDocsTests): def test_bad_selector(self): @@ -264,3 +263,15 @@ class BasicFindTests(mango.UserDocsTests): ] }) assert len(docs) == 0 + + def test_explain_view_args(self): + explain = self.db.find({ + "age":{"$gt": 0} + }, fields=["manager"], + explain=True) + assert explain["mrargs"]["stable"] == False + assert explain["mrargs"]["update"] == True + assert explain["mrargs"]["reduce"] == False + assert explain["mrargs"]["start_key"] == [0] + assert explain["mrargs"]["end_key"] == [{}] + assert explain["mrargs"]["include_docs"] == True |