Skip to content
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
12 changes: 6 additions & 6 deletions src/main/java/com/redislabs/redisgraph/graph_entities/Edge.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ public class Edge extends GraphEntity {

//members
private String relationshipType;
private int source;
private int destination;
private long source;
private long destination;


//getters & setters
Expand All @@ -34,30 +34,30 @@ public void setRelationshipType(String relationshipType) {
/**
* @return The id of the source node
*/
public int getSource() {
public long getSource() {
return source;
}

/**
* @param source - The id of the source node to be set
*/
public void setSource(int source) {
public void setSource(long source) {
this.source = source;
}

/**
*
* @return the id of the destination node
*/
public int getDestination() {
public long getDestination() {
return destination;
}

/**
*
* @param destination - The id of the destination node to be set
*/
public void setDestination(int destination) {
public void setDestination(long destination) {
this.destination = destination;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,90 +8,78 @@
* A graph entity has an id and a set of properties. The properties are mapped and accessed by their names.
*/
public abstract class GraphEntity {



//members

protected int id;
protected long id;
protected final Map<String, Property> propertyMap = new HashMap<>();


//setters & getters

/**
*
* @return entity id
*/
public int getId() {
public long getId() {
return id;
}

/**
*
* @param id - entity id to be set
*/
public void setId(int id) {
public void setId(long id) {
this.id = id;
}


/**
* Adds a property to the entity, by composing name, type and value to a property object
*
* @param name
* @param value
*/
public void addProperty(String name, Object value){

public void addProperty(String name, Object value) {
addProperty(new Property(name, value));

}

/**
*
* @return Entity's property names, as a Set
*/
public Set<String> getEntityPropertyNames(){
public Set<String> getEntityPropertyNames() {
return propertyMap.keySet();
}

/**
* Add a property to the entity
*
* @param property
*/
public void addProperty (Property property){
public void addProperty(Property property) {


propertyMap.put(property.getName(), property);
}

/**
*
* @return number of properties
*/
public int getNumberOfProperties(){
public int getNumberOfProperties() {
return propertyMap.size();
}


/**
*
* @param propertyName - property name as lookup key (String)
* @return property object, or null if key is not found
*/
public Property getProperty(String propertyName){
public Property getProperty(String propertyName) {
return propertyMap.get(propertyName);
}


/**
*
* @param name - the name of the property to be removed
*/
public void removeProperty(String name){

public void removeProperty(String name) {
propertyMap.remove(name);

}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ public class Property <T> {

//members
private String name;

private T value;


Expand Down Expand Up @@ -66,14 +65,19 @@ public void setValue(T value) {
this.value = value;
}

private boolean valueEquals(Object value1, Object value2) {
if(value1 instanceof Integer) value1 = Long.valueOf(((Integer) value1).longValue());
if(value2 instanceof Integer) value2 = Long.valueOf(((Integer) value2).longValue());
return Objects.equals(value1, value2);
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof Property)) return false;
Property property = (Property) o;
return Objects.equals(name, property.name) &&
Objects.equals(value, property.value);
valueEquals(value, property.value);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ private Node deserializeNode(List<Object> rawNodeData) {
* @param rawEntityId raw representation of entity id to be set to the graph entity
*/
private void deserializeGraphEntityId(GraphEntity graphEntity, Object rawEntityId) {
int id = ((Long) rawEntityId).intValue();
long id = (Long) rawEntityId;
graphEntity.setId(id);
}

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

edge.setSource((int) (long) rawEdgeData.get(2));
edge.setDestination((int) (long) rawEdgeData.get(3));
edge.setSource( (long) rawEdgeData.get(2));
edge.setDestination( (long) rawEdgeData.get(3));

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

Expand Down Expand Up @@ -233,7 +233,7 @@ private Object deserializeScalar(List<Object> rawScalarData) {
case VALUE_DOUBLE:
return Double.parseDouble(SafeEncoder.encode((byte[]) obj));
case VALUE_INTEGER:
return ((Long) obj).intValue();
return (Long) obj;
case VALUE_STRING:
return SafeEncoder.encode((byte[]) obj);
case VALUE_ARRAY:
Expand Down
51 changes: 32 additions & 19 deletions src/test/java/com/redislabs/redisgraph/RedisGraphAPITest.java
Original file line number Diff line number Diff line change
Expand Up @@ -298,8 +298,8 @@ public void testRecord(){
"r.place", "r.since", "r.doubleValue", "r.boolValue", "r.nullValue"), record.keys());

Assert.assertEquals(Arrays.asList(expectedNode, expectedEdge,
name, age, doubleValue, true, null,
place, since, doubleValue, false, null),
name, (long)age, doubleValue, true, null,
place, (long)since, doubleValue, false, null),
record.values());

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

Assert.assertEquals( "roi", record.getString(2));
Assert.assertEquals( "32", record.getString(3));
Assert.assertEquals( 32L, ((Integer)(record.getValue(3))).longValue());
Assert.assertEquals( 32L, ((Integer)record.getValue("a.age")).longValue());
Assert.assertEquals( 32L, ((Long)record.getValue(3)).longValue());
Assert.assertEquals( 32L, ((Long)record.getValue("a.age")).longValue());
Assert.assertEquals( "roi", record.getString("a.name"));
Assert.assertEquals( "32", record.getString("a.age"));

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

//test for update in local cache
Expand Down Expand Up @@ -530,7 +530,7 @@ public void testMultiExec(){

// Redis incr command
Assert.assertEquals(Long.class, results.get(3).getClass());
Assert.assertEquals((long)2, results.get(3));
Assert.assertEquals(2L, results.get(3));

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

Assert.assertEquals(Arrays.asList(expectedNode, expectedEdge,
name, age, doubleValue, true, null,
place, since, doubleValue, false, null),
name, (long)age, doubleValue, true, null,
place, (long)since, doubleValue, false, null),
record.values());

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

Assert.assertEquals("roi", record.getString(2));
Assert.assertEquals("32", record.getString(3));
Assert.assertEquals(32L, ((Integer) (record.getValue(3))).longValue());
Assert.assertEquals(32L, ((Integer) record.getValue("a.age")).longValue());
Assert.assertEquals(32L, ((Long) (record.getValue(3))).longValue());
Assert.assertEquals(32L, ((Long) record.getValue("a.age")).longValue());
Assert.assertEquals("roi", record.getString("a.name"));
Assert.assertEquals("32", record.getString("a.age"));
}
Expand Down Expand Up @@ -741,7 +741,7 @@ public void testArraySupport() {
expectedANode.addLabel("person");
Property aNameProperty = new Property("name", "a");
Property aAgeProperty = new Property("age", 32);
Property aListProperty = new Property("array", Arrays.asList(0,1,2));
Property aListProperty = new Property("array", Arrays.asList(0L, 1L, 2L));
expectedANode.addProperty(aNameProperty);
expectedANode.addProperty(aAgeProperty);
expectedANode.addProperty(aListProperty);
Expand All @@ -752,7 +752,7 @@ public void testArraySupport() {
expectedBNode.addLabel("person");
Property bNameProperty = new Property("name", "b");
Property bAgeProperty = new Property("age", 30);
Property bListProperty = new Property("array", Arrays.asList(3,4,5));
Property bListProperty = new Property("array", Arrays.asList(3L, 4L, 5L));
expectedBNode.addProperty(bNameProperty);
expectedBNode.addProperty(bAgeProperty);
expectedBNode.addProperty(bListProperty);
Expand Down Expand Up @@ -786,7 +786,7 @@ public void testArraySupport() {


List x = record.getValue("x");
Assert.assertEquals(Arrays.asList(0,1,2), x);
Assert.assertEquals(Arrays.asList(0L, 1L, 2L), x);

// test collect
resultSet = api.query("social", "MATCH(n) return collect(n) as x");
Expand Down Expand Up @@ -825,11 +825,11 @@ record = resultSet.next();
// check record
Assert.assertEquals(3, resultSet.size());

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

}

Expand Down Expand Up @@ -881,14 +881,16 @@ public void testPath(){
@Test
public void testParameters(){
Object[] parameters = {1, 2.3, true, false, null, "str", Arrays.asList(1,2,3), new Integer[]{1,2,3}};
Map<String, Object> param = new HashMap<>();
Object[] expected_anwsers = {1L, 2.3, true, false, null, "str", Arrays.asList(1L, 2L, 3L), new Long[]{1L, 2L, 3L}};
Map<String, Object> params = new HashMap<>();
for (int i=0; i < parameters.length; i++) {
Object expected = parameters[i];
param.put("param", expected);
ResultSet resultSet = api.query("social", "RETURN $param", param);
Object param = parameters[i];
params.put("param", param);
ResultSet resultSet = api.query("social", "RETURN $param", params);
Assert.assertEquals(1, resultSet.size());
Record r = resultSet.next();
Object o = r.getValue(0);
Object expected = expected_anwsers[i];
if(i == parameters.length-1) {
expected = Arrays.asList((Object[])expected);
}
Expand Down Expand Up @@ -941,4 +943,15 @@ record = resultSet.next();
Assert.assertNull(record.getValue(0));

}

@Test
public void test64bitnumber(){
long value = 1 << 40;
Map<String, Object> params = new HashMap<String, Object>();
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));
}
}