コード例 #1
0
        public async Task <RiakStreamedMapReduceResult> StreamMapReduce(RiakMapReduceQuery query)
        {
            var request  = query.ToMessage();
            var response = _connection
                           .PbcWriteStreamRead <RpbMapRedReq, RpbMapRedResp>(_endPoint, request, r => !r.done);

            return(new RiakStreamedMapReduceResult(response));
        }
コード例 #2
0
        public void BuildingMapReducePhaseWithVaueTypeArgumentProducesCorrectResult()
        {
            var query = new RiakMapReduceQuery()
                        .Inputs("animals")
                        .ReduceJs(c => c.Name("Riak.reduceSlice").Keep(true).Argument("slartibartfast"));

            var request = query.ToMessage();

            request.request.ShouldEqual(MrJobWithValueTypeArgument.ToRiakString());
        }
コード例 #3
0
        public void BuildingMapReducePhaseWithObjectArgumentProducesCorrectResult()
        {
            var query = new RiakMapReduceQuery()
                        .Inputs("animals")
                        .ReduceJs(c => c.Name("Riak.reduceSlice").Keep(true).Argument(new { reduce_phase_only_1 = true }));

            var request = query.ToMessage();

            request.request.ShouldEqual(MrJobWithObjectArgument.ToRiakString());
        }
コード例 #4
0
        public void BuildingComplexMapReduceJobsWithTheApiProducesTheCorrectCommand()
        {
            var query = new RiakMapReduceQuery()
                        .Inputs("animals")
                        .MapJs(m => m.Source("function(o) { if (o.key.indexOf('spider') != -1) return [1]; return []; }"))
                        .ReduceJs(r => r.Name("Riak.reduceSum").Keep(true));

            var request = query.ToMessage();

            request.request.ShouldEqual(ComplexMrJobText.ToRiakString());
        }
コード例 #5
0
        public void BuildingSimpleMapReduceJobsWithTimeoutProducesTheCorrectCommand()
        {
            var query = new RiakMapReduceQuery(100200)
                        .Inputs("animals")
                        .MapJs(m => m.Source("function(v) { return [v]; }").Keep(true));

            var request = query.ToMessage();

            request.content_type.ShouldEqual(MrContentType.ToRiakString());
            request.request.ShouldEqual(MrJobWithTimeoutText.ToRiakString());
        }
コード例 #6
0
        public void BuildingSimpleMapReduceJobsWithTheApiProducesByteArrays()
        {
            var query = new RiakMapReduceQuery()
                        .Inputs("animals")
                        .MapJs(m => m.Source("function(v) { return [v]; }").Keep(true));

            var request = query.ToMessage();

            request.content_type.ShouldEqual(MrContentType.ToRiakString());
            request.request.ShouldEqual(MrJobText.ToRiakString());
        }
コード例 #7
0
        public void QueryingDollarKeyDoesNotAppendBinIndexSuffix()
        {
            var query = new RiakMapReduceQuery()
                        .Inputs(RiakIndex.Range(new RiakIndexId("animals", "$key"), "0", "zzzzz"));

            var request       = query.ToMessage();
            var requestString = request.request.FromRiakString();

            requestString.Contains("$key").ShouldBeTrue();
            requestString.Contains("$key_bin").ShouldBeFalse();
        }
コード例 #8
0
        public void BuildingMapReducePhaseWithArgumentsArrayProducesCorrectResult()
        {
            var query = new RiakMapReduceQuery {
                ContentType = MrContentType
            }
            .Inputs("animals")
            .ReduceJs(c => c.Name("Riak.reduceSlice").Keep(true).Argument(new [] { 1, 10 }));

            var request = query.ToMessage();

            request.request.ShouldEqual(MrJobWithArgumentsArray.ToRiakString());
        }
コード例 #9
0
        public RiakResult <RiakStreamedMapReduceResult> StreamMapReduce(RiakMapReduceQuery query)
        {
            var request  = query.ToMessage();
            var response = UseDelayedConnection((conn, onFinish) =>
                                                conn.PbcWriteStreamRead <RpbMapRedReq, RpbMapRedResp>(request, r => r.IsSuccess && !r.Value.Done, onFinish));

            if (response.IsSuccess)
            {
                return(RiakResult <RiakStreamedMapReduceResult> .Success(new RiakStreamedMapReduceResult(response.Value)));
            }
            return(RiakResult <RiakStreamedMapReduceResult> .Error(response.ResultCode, response.ErrorMessage));
        }
コード例 #10
0
        public RiakResult <RiakMapReduceResult> MapReduce(RiakMapReduceQuery query)
        {
            var request  = query.ToMessage();
            var response = UseConnection(conn => conn.PbcWriteRead <RpbMapRedReq, RpbMapRedResp>(request, r => r.IsSuccess && !r.Value.done));

            if (response.IsSuccess)
            {
                return(RiakResult <RiakMapReduceResult> .Success(new RiakMapReduceResult(response.Value)));
            }

            return(RiakResult <RiakMapReduceResult> .Error(response.ResultCode, response.ErrorMessage, response.NodeOffline));
        }
コード例 #11
0
        public void BuildingComplexMapReduceJobsWithFiltersProducesTheCorrectCommand()
        {
#pragma warning disable 618
            var query = new RiakMapReduceQuery()
                        .Inputs("animals")
                        .Filter(f => f.Matches("spider"))
                        .MapJs(m => m.Source("function(o) { return [1]; }"))
                        .ReduceJs(r => r.Name("Riak.reduceSum").Keep(true));
#pragma warning restore 618

            var request = query.ToMessage();
            request.request.ShouldEqual(ComplexMrJobWithFilterText.ToRiakString());
        }
コード例 #12
0
        public Task <RiakResult <RiakMapReduceResult> > MapReduce(RiakMapReduceQuery query)
        {
            var request = query.ToMessage();

            return(UseConnection(conn => conn.PbcWriteRead <RpbMapRedReq, RpbMapRedResp>(request, r => r.IsSuccess && !r.Value.done))
                   .ContinueWith((Task <RiakResult <IEnumerable <RiakResult <RpbMapRedResp> > > > finishedTask) => {
                var result = finishedTask.Result;
                if (result.IsSuccess)
                {
                    return RiakResult <RiakMapReduceResult> .Success(new RiakMapReduceResult(result.Value));
                }
                return RiakResult <RiakMapReduceResult> .Error(result.ResultCode, result.ErrorMessage, result.NodeOffline);
            }));
        }
コード例 #13
0
        public void BuildingComplexMapReduceJobsWithFiltersProducesTheCorrectCommand()
        {
            var query = new RiakMapReduceQuery
            {
                ContentType = MrContentType
            }
            .Inputs("animals")
            //.Filter(new Matches<string>("spider"))
            .Filter(f => f.Matches("spider"))
            .MapJs(m => m.Source("function(o) { return [1]; }"))
            .ReduceJs(r => r.Name("Riak.reduceSum").Keep(true));

            var request = query.ToMessage();

            request.request.ShouldEqual(ComplexMrJobWithFilterText.ToRiakString());
        }