Skip to content

Commit b9e5af5

Browse files
committed
[DE-370] get query optimizer rules
1 parent e0c45e9 commit b9e5af5

File tree

8 files changed

+121
-0
lines changed

8 files changed

+121
-0
lines changed

src/main/java/com/arangodb/ArangoDB.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1044,6 +1044,13 @@ default Boolean createDatabase(String name) throws ArangoDBException {
10441044
*/
10451045
LogLevelEntity setLogLevel(LogLevelEntity entity) throws ArangoDBException;
10461046

1047+
/**
1048+
* @return the list of available rules and their respective flags
1049+
* @throws ArangoDBException
1050+
* @since ArangoDB 3.10
1051+
*/
1052+
Collection<QueryOptimizerRule> getQueryOptimizerRules() throws ArangoDBException;
1053+
10471054
/**
10481055
* <strong>Attention:</strong> Please do not use!
10491056
*

src/main/java/com/arangodb/async/ArangoDBAsync.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,12 @@ default CompletableFuture<Boolean> createDatabase(final String name) {
337337
*/
338338
CompletableFuture<LogLevelEntity> setLogLevel(final LogLevelEntity entity);
339339

340+
/**
341+
* @return the list of available rules and their respective flags
342+
* @since ArangoDB 3.10
343+
*/
344+
CompletableFuture<Collection<QueryOptimizerRule>> getQueryOptimizerRules();
345+
340346
/**
341347
* Builder class to build an instance of {@link ArangoDBAsync}.
342348
*

src/main/java/com/arangodb/async/internal/ArangoDBAsyncImpl.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
import com.arangodb.model.LogOptions;
4242
import com.arangodb.model.UserCreateOptions;
4343
import com.arangodb.model.UserUpdateOptions;
44+
import com.arangodb.velocypack.Type;
4445
import com.arangodb.velocystream.Request;
4546
import com.arangodb.velocystream.Response;
4647
import org.slf4j.Logger;
@@ -240,4 +241,11 @@ public CompletableFuture<LogLevelEntity> getLogLevel() {
240241
public CompletableFuture<LogLevelEntity> setLogLevel(final LogLevelEntity entity) {
241242
return executor.execute(setLogLevelRequest(entity), LogLevelEntity.class);
242243
}
244+
245+
@Override
246+
public CompletableFuture<Collection<QueryOptimizerRule>> getQueryOptimizerRules() throws ArangoDBException {
247+
return executor.execute(getQueryOptimizerRulesRequest(), new Type<Collection<QueryOptimizerRule>>() {
248+
}.getType());
249+
}
250+
243251
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package com.arangodb.entity;
2+
3+
/**
4+
* @since ArangoDB 3.10
5+
*/
6+
public class QueryOptimizerRule implements Entity {
7+
private String name;
8+
private Flags flags;
9+
10+
public String getName() {
11+
return name;
12+
}
13+
14+
public Flags getFlags() {
15+
return flags;
16+
}
17+
18+
public static class Flags {
19+
private Boolean hidden;
20+
private Boolean clusterOnly;
21+
private Boolean canBeDisabled;
22+
private Boolean canCreateAdditionalPlans;
23+
private Boolean disabledByDefault;
24+
private Boolean enterpriseOnly;
25+
26+
public Boolean getHidden() {
27+
return hidden;
28+
}
29+
30+
public Boolean getClusterOnly() {
31+
return clusterOnly;
32+
}
33+
34+
public Boolean getCanBeDisabled() {
35+
return canBeDisabled;
36+
}
37+
38+
public Boolean getCanCreateAdditionalPlans() {
39+
return canCreateAdditionalPlans;
40+
}
41+
42+
public Boolean getDisabledByDefault() {
43+
return disabledByDefault;
44+
}
45+
46+
public Boolean getEnterpriseOnly() {
47+
return enterpriseOnly;
48+
}
49+
}
50+
}

src/main/java/com/arangodb/internal/ArangoDBImpl.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import com.arangodb.model.UserUpdateOptions;
3939
import com.arangodb.util.ArangoCursorInitializer;
4040
import com.arangodb.util.ArangoSerialization;
41+
import com.arangodb.velocypack.Type;
4142
import com.arangodb.velocystream.Request;
4243
import com.arangodb.velocystream.Response;
4344
import org.slf4j.Logger;
@@ -269,6 +270,12 @@ public LogLevelEntity setLogLevel(final LogLevelEntity entity) throws ArangoDBEx
269270
return executor.execute(setLogLevelRequest(entity), LogLevelEntity.class);
270271
}
271272

273+
@Override
274+
public Collection<QueryOptimizerRule> getQueryOptimizerRules() throws ArangoDBException {
275+
return executor.execute(getQueryOptimizerRulesRequest(), new Type<Collection<QueryOptimizerRule>>() {
276+
}.getType());
277+
}
278+
272279
@Override
273280
public ArangoDBImpl _setCursorInitializer(final ArangoCursorInitializer cursorInitializer) {
274281
this.cursorInitializer = cursorInitializer;

src/main/java/com/arangodb/internal/InternalArangoDB.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ public abstract class InternalArangoDB<E extends ArangoExecutor> extends ArangoE
4848
private static final String PATH_API_SERVER_ID = "/_admin/server/id";
4949
private static final String PATH_ENDPOINTS = "/_api/cluster/endpoints";
5050
private static final String PATH_API_USER = "/_api/user";
51+
private static final String PATH_API_QUERY_RULES = "/_api/query/rules";
5152

5253
protected InternalArangoDB(final E executor, final ArangoSerializationFactory util, final ArangoContext context) {
5354
super(executor, util, context);
@@ -197,4 +198,8 @@ protected Request setLogLevelRequest(final LogLevelEntity entity) {
197198
.setBody(util().serialize(entity));
198199
}
199200

201+
protected Request getQueryOptimizerRulesRequest() {
202+
return request(DbName.SYSTEM, RequestType.GET, PATH_API_QUERY_RULES);
203+
}
204+
200205
}

src/test/java/com/arangodb/ArangoDBTest.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -644,6 +644,25 @@ void setAllLogLevel(ArangoDB arangoDB) {
644644
}
645645
}
646646

647+
@ParameterizedTest(name = "{index}")
648+
@MethodSource("arangos")
649+
void getQueryOptimizerRules(ArangoDB arangoDB) {
650+
assumeTrue(isAtLeastVersion(3, 10));
651+
final Collection<QueryOptimizerRule> rules = arangoDB.getQueryOptimizerRules();
652+
assertThat(rules).isNotEmpty();
653+
for (QueryOptimizerRule rule : rules) {
654+
assertThat(rule).isNotNull();
655+
assertThat(rule.getName()).isNotNull();
656+
QueryOptimizerRule.Flags flags = rule.getFlags();
657+
assertThat(flags.getHidden()).isNotNull();
658+
assertThat(flags.getClusterOnly()).isNotNull();
659+
assertThat(flags.getCanBeDisabled()).isNotNull();
660+
assertThat(flags.getCanCreateAdditionalPlans()).isNotNull();
661+
assertThat(flags.getDisabledByDefault()).isNotNull();
662+
assertThat(flags.getEnterpriseOnly()).isNotNull();
663+
}
664+
}
665+
647666
@ParameterizedTest(name = "{index}")
648667
@MethodSource("arangos")
649668
void arangoDBException(ArangoDB arangoDB) {

src/test/java/com/arangodb/async/ArangoDBTest.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -664,4 +664,23 @@ void queueTime() throws InterruptedException, ExecutionException {
664664
}
665665
}
666666

667+
@Test
668+
void getQueryOptimizerRules() throws ExecutionException, InterruptedException {
669+
assumeTrue(isAtLeastVersion(3, 10));
670+
final Collection<QueryOptimizerRule> rules = arangoDB.getQueryOptimizerRules().get();
671+
assertThat(rules).isNotEmpty();
672+
for (QueryOptimizerRule rule : rules) {
673+
assertThat(rule).isNotNull();
674+
assertThat(rule.getName()).isNotNull();
675+
QueryOptimizerRule.Flags flags = rule.getFlags();
676+
assertThat(flags.getHidden()).isNotNull();
677+
assertThat(flags.getClusterOnly()).isNotNull();
678+
assertThat(flags.getCanBeDisabled()).isNotNull();
679+
assertThat(flags.getCanCreateAdditionalPlans()).isNotNull();
680+
assertThat(flags.getDisabledByDefault()).isNotNull();
681+
assertThat(flags.getEnterpriseOnly()).isNotNull();
682+
}
683+
}
684+
685+
667686
}

0 commit comments

Comments
 (0)