Skip to content

Commit 2283cb8

Browse files
DvirDukhangkorland
andauthored
cached execution statistics (#75)
* cached execution statistics * Update RedisGraphAPITest.java * Update RedisGraphAPITest.java Co-authored-by: Guy Korland <[email protected]>
1 parent 076d6fb commit 2283cb8

File tree

3 files changed

+37
-3
lines changed

3 files changed

+37
-3
lines changed

src/main/java/com/redislabs/redisgraph/Statistics.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ enum Label{
1515
RELATIONSHIPS_DELETED("Relationships deleted"),
1616
PROPERTIES_SET("Properties set"),
1717
RELATIONSHIPS_CREATED("Relationships created"),
18+
CACHED_EXECUTION("Cached execution"),
1819
QUERY_INTERNAL_EXECUTION_TIME("Query internal execution time");
1920

2021
private final String text;
@@ -65,4 +66,6 @@ public static Label getEnum(String value) {
6566
int relationshipsCreated();
6667

6768
int propertiesSet();
69+
70+
boolean cachedExecution();
6871
}

src/main/java/com/redislabs/redisgraph/impl/resultset/StatisticsImpl.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,15 @@ public int propertiesSet() {
132132
return getIntValue(Label.PROPERTIES_SET);
133133
}
134134

135+
/**
136+
*
137+
* @return The execution plan was cached on RedisGraph.
138+
*/
139+
@Override
140+
public boolean cachedExecution() {
141+
return getIntValue(Label.CACHED_EXECUTION) == 1;
142+
}
143+
135144
@Override
136145
public boolean equals(Object o) {
137146
if (this == o) return true;

src/test/java/com/redislabs/redisgraph/RedisGraphAPITest.java

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -642,7 +642,6 @@ public void testContextedAPI() {
642642
"r.place, r.since, r.doubleValue, r.boolValue, r.nullValue");
643643
Assert.assertNotNull(resultSet);
644644

645-
646645
Assert.assertEquals(0, resultSet.getStatistics().nodesCreated());
647646
Assert.assertEquals(0, resultSet.getStatistics().nodesDeleted());
648647
Assert.assertEquals(0, resultSet.getStatistics().labelsAdded());
@@ -651,7 +650,6 @@ public void testContextedAPI() {
651650
Assert.assertEquals(0, resultSet.getStatistics().relationshipsDeleted());
652651
Assert.assertNotNull(resultSet.getStatistics().getStringValue(Label.QUERY_INTERNAL_EXECUTION_TIME));
653652

654-
655653
Assert.assertEquals(1, resultSet.size());
656654
Assert.assertTrue(resultSet.hasNext());
657655
Record record = resultSet.next();
@@ -947,11 +945,35 @@ record = resultSet.next();
947945
@Test
948946
public void test64bitnumber(){
949947
long value = 1 << 40;
950-
Map<String, Object> params = new HashMap<String, Object>();
948+
Map<String, Object> params = new HashMap<>();
951949
params.put("val", value);
952950
ResultSet resultSet = api.query("social","CREATE (n {val:$val}) RETURN n.val", params);
953951
Assert.assertEquals(1, resultSet.size());
954952
Record r = resultSet.next();
955953
Assert.assertEquals(Long.valueOf(value), r.getValue(0));
956954
}
955+
956+
@Test
957+
public void testCachedExecution() {
958+
api.query("social", "CREATE (:N {val:1}), (:N {val:2})");
959+
960+
// First time should not be loaded from execution cache
961+
Map<String, Object> params = new HashMap<>();
962+
params.put("val", 1L);
963+
ResultSet resultSet = api.query("social","MATCH (n:N {val:$val}) RETURN n.val", params);
964+
Assert.assertEquals(1, resultSet.size());
965+
Record r = resultSet.next();
966+
Assert.assertEquals(params.get("val"), r.getValue(0));
967+
Assert.assertFalse(resultSet.getStatistics().cachedExecution());
968+
969+
// Run in loop many times to make sure the query will be loaded
970+
// from cache at least once
971+
for (int i = 0 ; i < 64; i++){
972+
resultSet = api.query("social","MATCH (n:N {val:$val}) RETURN n.val", params);
973+
}
974+
Assert.assertEquals(1, resultSet.size());
975+
r = resultSet.next();
976+
Assert.assertEquals(params.get("val"), r.getValue(0));
977+
Assert.assertTrue(resultSet.getStatistics().cachedExecution());
978+
}
957979
}

0 commit comments

Comments
 (0)