Skip to content

Commit 037f725

Browse files
committed
JCBC-1179 Add profile option to N1qlParams
Change-Id: Icbd317c44153b85ab213a42160c1152e4fe89bc9 Reviewed-on: http://review.couchbase.org/91928 Reviewed-by: Subhashni Balakrishnan <[email protected]> Tested-by: Subhashni Balakrishnan <[email protected]>
1 parent c697818 commit 037f725

File tree

3 files changed

+97
-0
lines changed

3 files changed

+97
-0
lines changed

src/integration/java/com/couchbase/client/java/N1qlQueryTest.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,4 +340,22 @@ public void shouldWorkWithPrettyFalse() {
340340
assertNotNull(result.allRows());
341341
assertNotNull(result.errors());
342342
}
343+
344+
@Test
345+
public void shouldWorkWithProfileInfoEnabled() {
346+
ctx.ignoreIfClusterUnder(Version.parseVersion("4.5.1"));
347+
N1qlQuery query = N1qlQuery.simple(
348+
select("*").fromCurrentBucket().limit(1),
349+
N1qlParams.build().profile(N1qlProfile.TIMINGS).consistency(CONSISTENCY)
350+
);
351+
352+
N1qlQueryResult result = ctx.bucket().query(query);
353+
assertEquals(1, result.allRows().size());
354+
assertTrue(result.parseSuccess());
355+
assertTrue(result.finalSuccess());
356+
assertNotNull(result.info());
357+
assertNotNull(result.allRows());
358+
assertNotNull(result.errors());
359+
assertTrue(result.profileInfo().size() > 0);
360+
}
343361
}

src/main/java/com/couchbase/client/java/query/N1qlParams.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ public class N1qlParams implements Serializable {
6464
private Map<String, Object> rawParams;
6565
private boolean pretty;
6666
private boolean readonly;
67+
private N1qlProfile profile;
6768

6869
private final Map<String, String> credentials;
6970

@@ -142,6 +143,10 @@ public void injectParams(JsonObject queryJson) {
142143
queryJson.put("readonly", true);
143144
}
144145

146+
if (this.profile != null) {
147+
queryJson.put("profile", this.profile.toString());
148+
}
149+
145150
if (this.rawParams != null) {
146151
for (Map.Entry<String, Object> entry : rawParams.entrySet()) {
147152
queryJson.put(entry.getKey(), entry.getValue());
@@ -410,6 +415,17 @@ public N1qlParams pipelineCap(int pipelineCap) {
410415
return this;
411416
}
412417

418+
/**
419+
* Specifies if there should be a profile section returned with the request results.
420+
*
421+
* @param profile the profile param {@link N1qlProfile}.
422+
* @return this {@link N1qlParams} for chaining.
423+
*/
424+
public N1qlParams profile(N1qlProfile profile) {
425+
this.profile = profile;
426+
return this;
427+
}
428+
413429
/**
414430
* Allows to specify an arbitrary, raw N1QL param.
415431
*
@@ -480,6 +496,7 @@ public boolean equals(Object o) {
480496
if (mutationState != null ? !mutationState.equals(that.mutationState) : that.mutationState != null)
481497
return false;
482498
if (!credentials.equals(that.credentials)) return false;
499+
if (profile != that.profile) return false;
483500
return rawParams != null ? rawParams.equals(that.rawParams) : that.rawParams == null;
484501
}
485502

@@ -500,6 +517,7 @@ public int hashCode() {
500517
result = 31 * result + (adhoc ? 1 : 0);
501518
result = 31 * result + (pretty ? 1 : 0);
502519
result = 31 * result + (readonly ? 1 : 0);
520+
result = 31 * result + (profile != null ? profile.hashCode() : 0);
503521
return result;
504522
}
505523

@@ -521,6 +539,9 @@ public String toString() {
521539
sb.append(", rawParams=").append(rawParams);
522540
if (!credentials.isEmpty())
523541
sb.append(", credentials=").append(credentials.size());
542+
if (profile != null) {
543+
sb.append(", profile=").append(profile.toString());
544+
}
524545
sb.append('}');
525546
return sb.toString();
526547
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/*
2+
* Copyright (c) 2018 Couchbase, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.couchbase.client.java.query;
17+
18+
/**
19+
* N1ql profile options
20+
*/
21+
public enum N1qlProfile {
22+
23+
/**
24+
* No profiling information is added to the query response.
25+
*/
26+
OFF {
27+
@Override
28+
public String toString() {
29+
return "off";
30+
}
31+
},
32+
33+
/**
34+
* The query response includes a profile section with stats and details
35+
* about various phases of the query plan and execution.
36+
* Three phase times will be included in the system:active_requests and
37+
* system:completed_requests monitoring keyspaces.
38+
*/
39+
PHASES {
40+
@Override
41+
public String toString() {
42+
return "phases";
43+
}
44+
},
45+
46+
/**
47+
* Besides the phase times, the profile section of the query response document will
48+
* include a full query plan with timing and information about the number of processed
49+
* documents at each phase. This information will be included in the system:active_requests
50+
* and system:completed_requests keyspaces.
51+
*/
52+
TIMINGS {
53+
@Override
54+
public String toString() {
55+
return "timings";
56+
}
57+
}
58+
}

0 commit comments

Comments
 (0)