Skip to content

Commit 470be15

Browse files
author
a-brandt
committed
issuer #47
1 parent 7b4a1e3 commit 470be15

File tree

5 files changed

+168
-53
lines changed

5 files changed

+168
-53
lines changed

ChangeLog

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ v3.1.0 (2016-09-XX)
22
* removed Methods with collectionId (long) from ArangoDriver (Id is only for internal usage)
33
* changed Revision from long to String
44
* removed Methods with documentId (long) from ArangoDriver
5+
* added profile flag to AqlQueryOptions (issue #47)
6+
* added getExtra() to DocumentCursor<> (issue #47)
57

68
v3.0.1 (2016-07-08)
79
---------------------------

src/main/java/com/arangodb/BaseCursorProxy.java

+13-3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import java.util.Iterator;
44
import java.util.List;
5+
import java.util.Map;
56

67
import com.arangodb.entity.DocumentEntity;
78

@@ -115,7 +116,7 @@ public String getRequestId() {
115116
* @return true, if the cursor can load more data from the database
116117
*/
117118
public boolean hasMore() {
118-
return baseCursor.getEntity().hasMore();
119+
return baseCursor.hasMore();
119120
}
120121

121122
/**
@@ -124,7 +125,7 @@ public boolean hasMore() {
124125
* @return the cursor identifier
125126
*/
126127
public Long getCursorId() {
127-
return baseCursor.getEntity().getCursorId();
128+
return baseCursor.getCursorId();
128129
}
129130

130131
/**
@@ -137,7 +138,16 @@ public Long getCursorId() {
137138
*
138139
*/
139140
public boolean isCached() {
140-
return baseCursor.getEntity().isCached();
141+
return baseCursor.isCached();
142+
}
143+
144+
/**
145+
* A list of extra stats returned by the query
146+
*
147+
* @return query stats
148+
*/
149+
public Map<String, Object> getExtra() {
150+
return baseCursor.getExtra();
141151
}
142152

143153
}

src/main/java/com/arangodb/CursorResult.java

+41
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import java.util.ArrayList;
2020
import java.util.Iterator;
2121
import java.util.List;
22+
import java.util.Map;
2223
import java.util.NoSuchElementException;
2324

2425
import com.arangodb.entity.CursorEntity;
@@ -175,6 +176,37 @@ public void remove() {
175176

176177
}
177178

179+
/**
180+
* Returns true if the cursor can load more data from the database
181+
*
182+
* @return true, if the cursor can load more data from the database
183+
*/
184+
public boolean hasMore() {
185+
return entity.hasMore();
186+
}
187+
188+
/**
189+
* Returns the cursor identifier
190+
*
191+
* @return the cursor identifier
192+
*/
193+
public Long getCursorId() {
194+
return entity.getCursorId();
195+
}
196+
197+
/**
198+
* a boolean flag indicating whether the query result was served from the
199+
* query cache or not. If the query result is served from the query cache,
200+
* the extra return attribute will not contain any stats sub-attribute and
201+
* no profile sub-attribute. (since ArangoDB 2.7)
202+
*
203+
* @return true, if the result is cached
204+
*
205+
*/
206+
public boolean isCached() {
207+
return entity.isCached();
208+
}
209+
178210
/**
179211
* Returns true, if there are AQL warnings
180212
*
@@ -193,4 +225,13 @@ public List<WarningEntity> getWarnings() {
193225
return entity.getWarnings();
194226
}
195227

228+
/**
229+
* A list of extra stats returned by the query
230+
*
231+
* @return query stats
232+
*/
233+
public Map<String, Object> getExtra() {
234+
return entity.getExtra();
235+
}
236+
196237
}

src/main/java/com/arangodb/util/AqlQueryOptions.java

+30
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ public class AqlQueryOptions implements OptionsInterface {
99
private Boolean fullCount;
1010
private Boolean cache;
1111
private Integer ttl;
12+
private Boolean profile;
1213

1314
/**
1415
* boolean flag that indicates whether the number of documents in the result
@@ -67,6 +68,31 @@ public AqlQueryOptions setBatchSize(Integer batchSize) {
6768
return this;
6869
}
6970

71+
/**
72+
* if set to true, then the additional query profiling information will be
73+
* returned in the extra.stats return attribute if the query result is not
74+
* served from the query cache.
75+
*
76+
* @return boolean flag
77+
*/
78+
public Boolean getProfile() {
79+
return profile;
80+
}
81+
82+
/**
83+
* if set to true, then the additional query profiling information will be
84+
* returned in the extra.stats return attribute if the query result is not
85+
* served from the query cache.
86+
*
87+
* @param profile
88+
* boolean flag
89+
* @return this
90+
*/
91+
public AqlQueryOptions setProfile(Boolean profile) {
92+
this.profile = profile;
93+
return this;
94+
}
95+
7096
/**
7197
* if set to true and the query contains a LIMIT clause, then the result
7298
* will contain an extra attribute extra with a sub-attribute fullCount.
@@ -174,6 +200,10 @@ public Map<String, Object> toMap() {
174200
optionsMp.put("fullCount", fullCount);
175201
}
176202

203+
if (profile != null) {
204+
optionsMp.put("profile", profile);
205+
}
206+
177207
// TODO add maxPlans
178208

179209
// TODO add optimizer.rules

src/test/java/com/arangodb/ArangoDriverCursorTest.java

+82-50
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818

1919
import static org.hamcrest.Matchers.is;
2020
import static org.hamcrest.Matchers.not;
21+
import static org.hamcrest.Matchers.notNullValue;
22+
import static org.hamcrest.Matchers.nullValue;
2123
import static org.hamcrest.core.StringStartsWith.startsWith;
2224
import static org.junit.Assert.assertFalse;
2325
import static org.junit.Assert.assertThat;
@@ -26,7 +28,8 @@
2628
import java.util.List;
2729
import java.util.Map;
2830

29-
import org.junit.Ignore;
31+
import org.junit.After;
32+
import org.junit.Before;
3033
import org.junit.Test;
3134

3235
import com.arangodb.entity.CursorEntity;
@@ -40,6 +43,25 @@
4043
*/
4144
public class ArangoDriverCursorTest extends BaseTest {
4245

46+
final static String collectionName = "unit_test_query_test";
47+
48+
@Before
49+
public void setup() throws ArangoException {
50+
try {
51+
driver.createCollection(collectionName);
52+
} catch (final ArangoException e) {
53+
}
54+
driver.truncateCollection(collectionName);
55+
}
56+
57+
@After
58+
public void tearDown() {
59+
try {
60+
driver.deleteCollection(collectionName);
61+
} catch (final ArangoException e) {
62+
}
63+
}
64+
4365
@Test
4466
public void test_validateQuery() throws ArangoException {
4567

@@ -56,7 +78,7 @@ public void test_validateQuery() throws ArangoException {
5678
}
5779

5880
@Test
59-
public void test_validateQuery_400_1() throws ArangoException {
81+
public void test_validateQuery_400() throws ArangoException {
6082

6183
// =じゃなくて==じゃないとダメ。文法間違いエラー
6284
try {
@@ -71,22 +93,8 @@ public void test_validateQuery_400_1() throws ArangoException {
7193

7294
}
7395

74-
@Test
75-
@Ignore
76-
public void test_validateQuery_400_2() throws ArangoException {
77-
}
78-
7996
@Test
8097
public void test_executeQuery() throws ArangoException {
81-
82-
// Collectionを作る
83-
final String collectionName = "unit_test_query_test";
84-
try {
85-
driver.createCollection(collectionName);
86-
} catch (final ArangoException e) {
87-
}
88-
driver.truncateCollection(collectionName);
89-
9098
// テストデータを作る
9199
for (int i = 0; i < 100; i++) {
92100
final TestComplexEntity01 value = new TestComplexEntity01("user_" + (i % 10), "desc" + (i % 10), i);
@@ -114,15 +122,6 @@ public void test_executeQuery() throws ArangoException {
114122

115123
@Test
116124
public void test_executeQuery_2() throws ArangoException {
117-
118-
// Collectionを作る
119-
final String collectionName = "unit_test_query_test";
120-
try {
121-
driver.createCollection(collectionName);
122-
} catch (final ArangoException e) {
123-
}
124-
driver.truncateCollection(collectionName);
125-
126125
// テストデータを作る
127126
for (int i = 0; i < 100; i++) {
128127
final TestComplexEntity01 value = new TestComplexEntity01("user_" + (i % 10), "desc" + (i % 10), i);
@@ -183,15 +182,6 @@ public void test_executeQuery_2() throws ArangoException {
183182

184183
@Test
185184
public void test_executeQueryFullCount() throws ArangoException {
186-
187-
// Collectionを作る
188-
final String collectionName = "unit_test_query_test";
189-
try {
190-
driver.createCollection(collectionName);
191-
} catch (final ArangoException e) {
192-
}
193-
driver.truncateCollection(collectionName);
194-
195185
// テストデータを作る
196186
for (int i = 0; i < 100; i++) {
197187
final TestComplexEntity01 value = new TestComplexEntity01("user_" + (i % 10), "desc" + (i % 10), i);
@@ -220,15 +210,6 @@ public void test_executeQueryFullCount() throws ArangoException {
220210

221211
@Test
222212
public void test_executeQueryUniqueResult() throws ArangoException {
223-
224-
// Collectionを作る
225-
final String collectionName = "unit_test_query_test";
226-
try {
227-
driver.createCollection(collectionName);
228-
} catch (final ArangoException e) {
229-
}
230-
driver.truncateCollection(collectionName);
231-
232213
// テストデータを作る
233214
for (int i = 0; i < 100; i++) {
234215
final TestComplexEntity01 value = new TestComplexEntity01("user_" + (i % 10), "desc" + (i % 10), i);
@@ -276,13 +257,6 @@ public void test_executeQueryUniqueResult() throws ArangoException {
276257

277258
@Test
278259
public void test_warning() throws ArangoException {
279-
final String collectionName = "unit_test_query_test";
280-
try {
281-
driver.createCollection(collectionName);
282-
} catch (final ArangoException e) {
283-
}
284-
driver.truncateCollection(collectionName);
285-
286260
driver.setDefaultDatabase(null);
287261
final String query = "return _users + 1";
288262
final Map<String, Object> bindVars = new HashMap<String, Object>();
@@ -293,4 +267,62 @@ public void test_warning() throws ArangoException {
293267
assertThat(warnings.size(), is(1));
294268
}
295269

270+
@Test
271+
public void test_CursorResult_profile() throws ArangoException {
272+
driver.setDefaultDatabase(null);
273+
final Map<String, Object> bindVars = new HashMap<String, Object>();
274+
final AqlQueryOptions aqlQueryOptions = new AqlQueryOptions();
275+
{
276+
// without profiling
277+
aqlQueryOptions.setProfile(false);
278+
final String query = "for p in _users return p._key";
279+
final CursorResult<String> cursor = driver.executeAqlQuery(query, bindVars, aqlQueryOptions, String.class);
280+
Map<String, Object> extra = cursor.getExtra();
281+
assertThat(extra, is(notNullValue()));
282+
Object object = extra.get("profile");
283+
// extra.profile has to be null
284+
assertThat(object, is(nullValue()));
285+
}
286+
{
287+
// with profiling
288+
aqlQueryOptions.setProfile(true);
289+
final String query = "for p in _users return p._id";
290+
final CursorResult<String> cursor = driver.executeAqlQuery(query, bindVars, aqlQueryOptions, String.class);
291+
Map<String, Object> extra = cursor.getExtra();
292+
assertThat(extra, is(notNullValue()));
293+
Object object = extra.get("profile");
294+
assertThat(object, is(notNullValue()));
295+
}
296+
}
297+
298+
@Test
299+
public void test_DocumentCursor_profile() throws ArangoException {
300+
driver.setDefaultDatabase(null);
301+
final Map<String, Object> bindVars = new HashMap<String, Object>();
302+
final AqlQueryOptions aqlQueryOptions = new AqlQueryOptions();
303+
{
304+
// without profiling
305+
aqlQueryOptions.setProfile(false);
306+
final String query = "for p in _users return p._key";
307+
final DocumentCursor<String> cursor = driver.executeDocumentQuery(query, bindVars, aqlQueryOptions,
308+
String.class);
309+
Map<String, Object> extra = cursor.getExtra();
310+
assertThat(extra, is(notNullValue()));
311+
Object object = extra.get("profile");
312+
// extra.profile has to be null
313+
assertThat(object, is(nullValue()));
314+
}
315+
{
316+
// with profiling
317+
aqlQueryOptions.setProfile(true);
318+
final String query = "for p in _users return p._id";
319+
final DocumentCursor<String> cursor = driver.executeDocumentQuery(query, bindVars, aqlQueryOptions,
320+
String.class);
321+
Map<String, Object> extra = cursor.getExtra();
322+
assertThat(extra, is(notNullValue()));
323+
Object object = extra.get("profile");
324+
assertThat(object, is(notNullValue()));
325+
}
326+
}
327+
296328
}

0 commit comments

Comments
 (0)