Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cached execution statistics #75

Merged
merged 3 commits into from
Jul 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/main/java/com/redislabs/redisgraph/Statistics.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ enum Label{
RELATIONSHIPS_DELETED("Relationships deleted"),
PROPERTIES_SET("Properties set"),
RELATIONSHIPS_CREATED("Relationships created"),
CACHED_EXECUTION("Cached execution"),
QUERY_INTERNAL_EXECUTION_TIME("Query internal execution time");

private final String text;
Expand Down Expand Up @@ -65,4 +66,6 @@ public static Label getEnum(String value) {
int relationshipsCreated();

int propertiesSet();

boolean cachedExecution();
}
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,15 @@ public int propertiesSet() {
return getIntValue(Label.PROPERTIES_SET);
}

/**
*
* @return The execution plan was cached on RedisGraph.
*/
@Override
public boolean cachedExecution() {
return getIntValue(Label.CACHED_EXECUTION) == 1;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
Expand Down
28 changes: 25 additions & 3 deletions src/test/java/com/redislabs/redisgraph/RedisGraphAPITest.java
Original file line number Diff line number Diff line change
Expand Up @@ -642,7 +642,6 @@ public void testContextedAPI() {
"r.place, r.since, r.doubleValue, r.boolValue, r.nullValue");
Assert.assertNotNull(resultSet);


Assert.assertEquals(0, resultSet.getStatistics().nodesCreated());
Assert.assertEquals(0, resultSet.getStatistics().nodesDeleted());
Assert.assertEquals(0, resultSet.getStatistics().labelsAdded());
Expand All @@ -651,7 +650,6 @@ public void testContextedAPI() {
Assert.assertEquals(0, resultSet.getStatistics().relationshipsDeleted());
Assert.assertNotNull(resultSet.getStatistics().getStringValue(Label.QUERY_INTERNAL_EXECUTION_TIME));


Assert.assertEquals(1, resultSet.size());
Assert.assertTrue(resultSet.hasNext());
Record record = resultSet.next();
Expand Down Expand Up @@ -947,11 +945,35 @@ record = resultSet.next();
@Test
public void test64bitnumber(){
long value = 1 << 40;
Map<String, Object> params = new HashMap<String, Object>();
Map<String, Object> params = new HashMap<>();
params.put("val", value);
ResultSet resultSet = api.query("social","CREATE (n {val:$val}) RETURN n.val", params);
Assert.assertEquals(1, resultSet.size());
Record r = resultSet.next();
Assert.assertEquals(Long.valueOf(value), r.getValue(0));
}

@Test
public void testCachedExecution() {
api.query("social", "CREATE (:N {val:1}), (:N {val:2})");

// First time should not be loaded from execution cache
Map<String, Object> params = new HashMap<>();
params.put("val", 1L);
ResultSet resultSet = api.query("social","MATCH (n:N {val:$val}) RETURN n.val", params);
Assert.assertEquals(1, resultSet.size());
Record r = resultSet.next();
Assert.assertEquals(params.get("val"), r.getValue(0));
Assert.assertFalse(resultSet.getStatistics().cachedExecution());

// Run in loop many times to make sure the query will be loaded
// from cache at least once
for (int i = 0 ; i < 64; i++){
resultSet = api.query("social","MATCH (n:N {val:$val}) RETURN n.val", params);
}
Assert.assertEquals(1, resultSet.size());
r = resultSet.next();
Assert.assertEquals(params.get("val"), r.getValue(0));
Assert.assertTrue(resultSet.getStatistics().cachedExecution());
}
}