Skip to content

Commit e2c7e0a

Browse files
DvirDukhangkorland
andauthored
changed returned integer values to be long. (#73)
* changed returned integer values to be long. entities values and ids are long * Update RedisGraphAPITest.java Co-authored-by: Guy Korland <[email protected]>
1 parent d62f0c7 commit e2c7e0a

File tree

5 files changed

+59
-54
lines changed

5 files changed

+59
-54
lines changed

src/main/java/com/redislabs/redisgraph/graph_entities/Edge.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ public class Edge extends GraphEntity {
1010

1111
//members
1212
private String relationshipType;
13-
private int source;
14-
private int destination;
13+
private long source;
14+
private long destination;
1515

1616

1717
//getters & setters
@@ -34,30 +34,30 @@ public void setRelationshipType(String relationshipType) {
3434
/**
3535
* @return The id of the source node
3636
*/
37-
public int getSource() {
37+
public long getSource() {
3838
return source;
3939
}
4040

4141
/**
4242
* @param source - The id of the source node to be set
4343
*/
44-
public void setSource(int source) {
44+
public void setSource(long source) {
4545
this.source = source;
4646
}
4747

4848
/**
4949
*
5050
* @return the id of the destination node
5151
*/
52-
public int getDestination() {
52+
public long getDestination() {
5353
return destination;
5454
}
5555

5656
/**
5757
*
5858
* @param destination - The id of the destination node to be set
5959
*/
60-
public void setDestination(int destination) {
60+
public void setDestination(long destination) {
6161
this.destination = destination;
6262
}
6363

src/main/java/com/redislabs/redisgraph/graph_entities/GraphEntity.java

Lines changed: 11 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -8,90 +8,78 @@
88
* A graph entity has an id and a set of properties. The properties are mapped and accessed by their names.
99
*/
1010
public abstract class GraphEntity {
11-
12-
13-
1411
//members
15-
16-
protected int id;
12+
protected long id;
1713
protected final Map<String, Property> propertyMap = new HashMap<>();
1814

1915

2016
//setters & getters
2117

2218
/**
23-
*
2419
* @return entity id
2520
*/
26-
public int getId() {
21+
public long getId() {
2722
return id;
2823
}
2924

3025
/**
31-
*
3226
* @param id - entity id to be set
3327
*/
34-
public void setId(int id) {
28+
public void setId(long id) {
3529
this.id = id;
3630
}
3731

3832

3933
/**
4034
* Adds a property to the entity, by composing name, type and value to a property object
35+
*
4136
* @param name
4237
* @param value
4338
*/
44-
public void addProperty(String name, Object value){
45-
39+
public void addProperty(String name, Object value) {
4640
addProperty(new Property(name, value));
47-
4841
}
4942

5043
/**
51-
*
5244
* @return Entity's property names, as a Set
5345
*/
54-
public Set<String> getEntityPropertyNames(){
46+
public Set<String> getEntityPropertyNames() {
5547
return propertyMap.keySet();
5648
}
5749

5850
/**
5951
* Add a property to the entity
52+
*
6053
* @param property
6154
*/
62-
public void addProperty (Property property){
55+
public void addProperty(Property property) {
6356

6457

6558
propertyMap.put(property.getName(), property);
6659
}
6760

6861
/**
69-
*
7062
* @return number of properties
7163
*/
72-
public int getNumberOfProperties(){
64+
public int getNumberOfProperties() {
7365
return propertyMap.size();
7466
}
7567

7668

7769
/**
78-
*
7970
* @param propertyName - property name as lookup key (String)
8071
* @return property object, or null if key is not found
8172
*/
82-
public Property getProperty(String propertyName){
73+
public Property getProperty(String propertyName) {
8374
return propertyMap.get(propertyName);
8475
}
8576

8677

8778
/**
88-
*
8979
* @param name - the name of the property to be removed
9080
*/
91-
public void removeProperty(String name){
92-
81+
public void removeProperty(String name) {
9382
propertyMap.remove(name);
94-
9583
}
9684

9785
@Override

src/main/java/com/redislabs/redisgraph/graph_entities/Property.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ public class Property <T> {
1111

1212
//members
1313
private String name;
14-
1514
private T value;
1615

1716

@@ -66,14 +65,19 @@ public void setValue(T value) {
6665
this.value = value;
6766
}
6867

68+
private boolean valueEquals(Object value1, Object value2) {
69+
if(value1 instanceof Integer) value1 = Long.valueOf(((Integer) value1).longValue());
70+
if(value2 instanceof Integer) value2 = Long.valueOf(((Integer) value2).longValue());
71+
return Objects.equals(value1, value2);
72+
}
6973

7074
@Override
7175
public boolean equals(Object o) {
7276
if (this == o) return true;
7377
if (!(o instanceof Property)) return false;
7478
Property property = (Property) o;
7579
return Objects.equals(name, property.name) &&
76-
Objects.equals(value, property.value);
80+
valueEquals(value, property.value);
7781
}
7882

7983
@Override

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ private Node deserializeNode(List<Object> rawNodeData) {
161161
* @param rawEntityId raw representation of entity id to be set to the graph entity
162162
*/
163163
private void deserializeGraphEntityId(GraphEntity graphEntity, Object rawEntityId) {
164-
int id = ((Long) rawEntityId).intValue();
164+
long id = (Long) rawEntityId;
165165
graphEntity.setId(id);
166166
}
167167

@@ -183,8 +183,8 @@ private Edge deserializeEdge(List<Object> rawEdgeData) {
183183
redisGraph);
184184
edge.setRelationshipType(relationshipType);
185185

186-
edge.setSource((int) (long) rawEdgeData.get(2));
187-
edge.setDestination((int) (long) rawEdgeData.get(3));
186+
edge.setSource( (long) rawEdgeData.get(2));
187+
edge.setDestination( (long) rawEdgeData.get(3));
188188

189189
deserializeGraphEntityProperties(edge, (List<List<Object>>) rawEdgeData.get(4));
190190

@@ -233,7 +233,7 @@ private Object deserializeScalar(List<Object> rawScalarData) {
233233
case VALUE_DOUBLE:
234234
return Double.parseDouble(SafeEncoder.encode((byte[]) obj));
235235
case VALUE_INTEGER:
236-
return ((Long) obj).intValue();
236+
return (Long) obj;
237237
case VALUE_STRING:
238238
return SafeEncoder.encode((byte[]) obj);
239239
case VALUE_ARRAY:

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

Lines changed: 32 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -298,8 +298,8 @@ public void testRecord(){
298298
"r.place", "r.since", "r.doubleValue", "r.boolValue", "r.nullValue"), record.keys());
299299

300300
Assert.assertEquals(Arrays.asList(expectedNode, expectedEdge,
301-
name, age, doubleValue, true, null,
302-
place, since, doubleValue, false, null),
301+
name, (long)age, doubleValue, true, null,
302+
place, (long)since, doubleValue, false, null),
303303
record.values());
304304

305305
Node a = record.getValue("a");
@@ -309,8 +309,8 @@ public void testRecord(){
309309

310310
Assert.assertEquals( "roi", record.getString(2));
311311
Assert.assertEquals( "32", record.getString(3));
312-
Assert.assertEquals( 32L, ((Integer)(record.getValue(3))).longValue());
313-
Assert.assertEquals( 32L, ((Integer)record.getValue("a.age")).longValue());
312+
Assert.assertEquals( 32L, ((Long)record.getValue(3)).longValue());
313+
Assert.assertEquals( 32L, ((Long)record.getValue("a.age")).longValue());
314314
Assert.assertEquals( "roi", record.getString("a.name"));
315315
Assert.assertEquals( "32", record.getString("a.age"));
316316

@@ -372,7 +372,7 @@ public void testMultiThread(){
372372
Record record = resultSet.next();
373373
Assert.assertFalse(resultSet.hasNext());
374374
Assert.assertEquals(Arrays.asList("a", "r", "a.age"), record.keys());
375-
Assert.assertEquals(Arrays.asList(expectedNode, expectedEdge, 32), record.values());
375+
Assert.assertEquals(Arrays.asList(expectedNode, expectedEdge, 32L), record.values());
376376
}
377377

378378
//test for update in local cache
@@ -530,7 +530,7 @@ public void testMultiExec(){
530530

531531
// Redis incr command
532532
Assert.assertEquals(Long.class, results.get(3).getClass());
533-
Assert.assertEquals((long)2, results.get(3));
533+
Assert.assertEquals(2L, results.get(3));
534534

535535
// Redis get command
536536
Assert.assertEquals(String.class, results.get(4).getClass());
@@ -676,8 +676,8 @@ public void testContextedAPI() {
676676
"r.place", "r.since", "r.doubleValue", "r.boolValue", "r.nullValue"), record.keys());
677677

678678
Assert.assertEquals(Arrays.asList(expectedNode, expectedEdge,
679-
name, age, doubleValue, true, null,
680-
place, since, doubleValue, false, null),
679+
name, (long)age, doubleValue, true, null,
680+
place, (long)since, doubleValue, false, null),
681681
record.values());
682682

683683
Node a = record.getValue("a");
@@ -687,8 +687,8 @@ public void testContextedAPI() {
687687

688688
Assert.assertEquals("roi", record.getString(2));
689689
Assert.assertEquals("32", record.getString(3));
690-
Assert.assertEquals(32L, ((Integer) (record.getValue(3))).longValue());
691-
Assert.assertEquals(32L, ((Integer) record.getValue("a.age")).longValue());
690+
Assert.assertEquals(32L, ((Long) (record.getValue(3))).longValue());
691+
Assert.assertEquals(32L, ((Long) record.getValue("a.age")).longValue());
692692
Assert.assertEquals("roi", record.getString("a.name"));
693693
Assert.assertEquals("32", record.getString("a.age"));
694694
}
@@ -741,7 +741,7 @@ public void testArraySupport() {
741741
expectedANode.addLabel("person");
742742
Property aNameProperty = new Property("name", "a");
743743
Property aAgeProperty = new Property("age", 32);
744-
Property aListProperty = new Property("array", Arrays.asList(0,1,2));
744+
Property aListProperty = new Property("array", Arrays.asList(0L, 1L, 2L));
745745
expectedANode.addProperty(aNameProperty);
746746
expectedANode.addProperty(aAgeProperty);
747747
expectedANode.addProperty(aListProperty);
@@ -752,7 +752,7 @@ public void testArraySupport() {
752752
expectedBNode.addLabel("person");
753753
Property bNameProperty = new Property("name", "b");
754754
Property bAgeProperty = new Property("age", 30);
755-
Property bListProperty = new Property("array", Arrays.asList(3,4,5));
755+
Property bListProperty = new Property("array", Arrays.asList(3L, 4L, 5L));
756756
expectedBNode.addProperty(bNameProperty);
757757
expectedBNode.addProperty(bAgeProperty);
758758
expectedBNode.addProperty(bListProperty);
@@ -786,7 +786,7 @@ public void testArraySupport() {
786786

787787

788788
List x = record.getValue("x");
789-
Assert.assertEquals(Arrays.asList(0,1,2), x);
789+
Assert.assertEquals(Arrays.asList(0L, 1L, 2L), x);
790790

791791
// test collect
792792
resultSet = api.query("social", "MATCH(n) return collect(n) as x");
@@ -825,11 +825,11 @@ record = resultSet.next();
825825
// check record
826826
Assert.assertEquals(3, resultSet.size());
827827

828-
for (int i = 0; i < 3; i++) {
828+
for (long i = 0; i < 3; i++) {
829829
Assert.assertTrue(resultSet.hasNext());
830830
record = resultSet.next();
831831
Assert.assertEquals(Arrays.asList("x"), record.keys());
832-
Assert.assertEquals(i, (int) record.getValue("x"));
832+
Assert.assertEquals(i, (long)record.getValue("x"));
833833

834834
}
835835

@@ -881,14 +881,16 @@ public void testPath(){
881881
@Test
882882
public void testParameters(){
883883
Object[] parameters = {1, 2.3, true, false, null, "str", Arrays.asList(1,2,3), new Integer[]{1,2,3}};
884-
Map<String, Object> param = new HashMap<>();
884+
Object[] expected_anwsers = {1L, 2.3, true, false, null, "str", Arrays.asList(1L, 2L, 3L), new Long[]{1L, 2L, 3L}};
885+
Map<String, Object> params = new HashMap<>();
885886
for (int i=0; i < parameters.length; i++) {
886-
Object expected = parameters[i];
887-
param.put("param", expected);
888-
ResultSet resultSet = api.query("social", "RETURN $param", param);
887+
Object param = parameters[i];
888+
params.put("param", param);
889+
ResultSet resultSet = api.query("social", "RETURN $param", params);
889890
Assert.assertEquals(1, resultSet.size());
890891
Record r = resultSet.next();
891892
Object o = r.getValue(0);
893+
Object expected = expected_anwsers[i];
892894
if(i == parameters.length-1) {
893895
expected = Arrays.asList((Object[])expected);
894896
}
@@ -941,4 +943,15 @@ record = resultSet.next();
941943
Assert.assertNull(record.getValue(0));
942944

943945
}
946+
947+
@Test
948+
public void test64bitnumber(){
949+
long value = 1 << 40;
950+
Map<String, Object> params = new HashMap<String, Object>();
951+
params.put("val", value);
952+
ResultSet resultSet = api.query("social","CREATE (n {val:$val}) RETURN n.val", params);
953+
Assert.assertEquals(1, resultSet.size());
954+
Record r = resultSet.next();
955+
Assert.assertEquals(Long.valueOf(value), r.getValue(0));
956+
}
944957
}

0 commit comments

Comments
 (0)