Sparksee Select by multiple attributes + help functions for Value.

59 views
Skip to first unread message

Ray Neiheiser

unread,
Nov 16, 2016, 12:06:34 PM11/16/16
to spar...@googlegroups.com

I'm currently trying to read a sparksee object by it's Type and by multiple attributes.

I found out I can do select:

    graph.select(attributeId, Condition.Equal, wishedValue)

and that there is a select method which has an "Objects" value. But I wasn't able to find out what it is for.

Is there a way to do something like.

graph.select(nodeTypeid, Condition.Equal, ArrayOfValues)

or do I have to check one of the properties and then run through all of them manually?



Original location: http://stackoverflow.com/questions/40634106/sparksee-select-by-multiple-attributes.

Also, is there a way to get a DataType from an Object?

Like DataType.getType(Object obj) ?

or also a Function which creates a Value for a certain Object?

I'm currently using these as utils functions but that should handled internally imo:

/**
* Returns a Value object for a certain object.
* @param obj ingoing object.
* @return outgoing value.
*/
protected static Value getValue(Object obj)
{
Value v = new Value();

switch(getDataTypeFromObject(obj))
{
case Boolean:
return v.setBoolean((Boolean) obj);
case Integer:
return v.setInteger((java.lang.Integer) obj);
case Long:
return v.setLong((java.lang.Long) obj);
case Double:
return v.setDouble((java.lang.Double) obj);
default:
return v.setString((java.lang.String) obj);
}
}

/**
* Gets a dataType from a certain object.
* @param obj the ingoing object.
* @return outgoing dataType, default a string.
*/
protected static DataType getDataTypeFromObject(Object obj)
{
if(obj instanceof Integer)
{
return Integer;
}
else if(obj instanceof Long)
{
return Long;
}
else if(obj instanceof Boolean)
{
return Boolean;
}
else if (obj instanceof Double)
{
return Double;
}

return String;
} Additionally, isn't there a way to execute createOrFindNodeType or createOrFindAttribute? This way I don't have to execute all the:
int nodeTypeId = graph.findType(storage.getId());
if (Type.InvalidType == nodeTypeId)
{
return graph.newNodeType(storage.getId());
}
return nodeTypeId; and just could: createOrFindNodeType(type)

c3po.ac

unread,
Nov 17, 2016, 8:14:08 AM11/17/16
to Sparksee
Hi,

The select operations that receive an Objects argument (like this) can be used to select only the objects from the given set that satisfy the condition. You can get the same result with an intersection between the argument Objects and the normal Select result Objects, but using the specific method may be more efficient.


Sparksee does not have a Select that receives an array of values. Depending on the values you may be able to use a different Condition to achieve the same result (with Between, Like, RexExp, ...) otherwise you will have to do all the selects and union the resulting Objects.



Your Java Object to DataType function can be useful, but in general it's not always so clear because, for example, both the long and timestamp datatypes can be used as a Long. Similar problems happen in different languages and we are trying to keep the same API for all the available languages as much as possible.

Currently there is a findOrCreateEdge and a findOrCreateObject. The equivalent methods for the schema are still pending but may be available in future versions.

Thanks for your suggestions.



El dimecres, 16 novembre de 2016 18:06:34 UTC+1, Ray Neiheiser va escriure:

Ray Neiheiser

unread,
Nov 21, 2016, 5:31:17 AM11/21/16
to Sparksee
So, if I want a Node with the following attributes: "Name = paul" "age = 23" and "height = 2"
I have to get all nodes with the name paul, all with the age 23 and alle with height 2 and then check if there is a node which is in all three sets?

The DataType function would be more of a Util for native types. If someone wants to use the special types he still shall be free to do so.

c3po.ac

unread,
Nov 21, 2016, 9:45:51 AM11/21/16
to Sparksee

Hi,


Yes, you can do something like:

obj1 = graph.select(nameAttr, Condition.Equal, value.setString("paul"));

obj2
= graph.select(ageAttr, Condition.Equal, value.setInteger(23));

obj3
= graph.select(heightAttr, Condition.Equal, value.setInteger(2));

obj4
= Objects.combineIntersection(obj1, obj2);

obj4
.intersection(obj3);



Or you could use the Select operation restricted to the given objects:

obj1 = graph.select(nameAttr, Condition.Equal, value.setString("paul"));

obj2
= graph.select(ageAttr, Condition.Equal, value.setInteger(23), obj1);

obj3
= graph.select(heightAttr, Condition.Equal, value.setInteger(2), obj2);


Best regards



El dilluns, 21 novembre de 2016 11:31:17 UTC+1, Ray Neiheiser va escriure:

Ray Neiheiser

unread,
Nov 21, 2016, 1:11:06 PM11/21/16
to Sparksee
Thanks for the answer.

Now that I have the object. How can I get other attributes, nodes etc from it?
How could I add a relationship from it, or read the timestamp?

c3po.ac

unread,
Nov 22, 2016, 5:14:10 AM11/22/16
to Sparksee

Hi,

You may want to look at the Sparksee Starting Guide.


The section 6 will give you a simple example of how to iterate the Objects to get the node ids and get an attribute from a specific node, while the section 5 will show you how to create an edge between two nodes and the section 4 will be useful to understand the schema of the example.


Best regards



El dilluns, 21 novembre de 2016 19:11:06 UTC+1, Ray Neiheiser va escriure:

Ray Neiheiser

unread,
Nov 23, 2016, 4:38:35 AM11/23/16
to spar...@googlegroups.com
Thanks.

Is there a way to get a node or edge without their type?
Like "getAllNodes" or "getAllNodesWithAttributeX=y" ?

Like "Get all Nodes with timestamp November 8th" ?

c3po.ac

unread,
Nov 23, 2016, 7:53:47 AM11/23/16
to Sparksee

Hi,


There are four types of attributes in Sparksee: specific to type, specific to node, specific to edge and global. In the first case, the attribute will be created for a specific node or edge type, thus when you perform a select for that attribute it will only return nodes or edges of that certain type and you must then search for the specific attribute id of each type and perform a union of all the objects obtained.


For the second and third cases, the attribute created can be used on any node or any edge and it's not tied to a specific type, this will be indicated by using "Type.NodesType" or "Type.EdgesType" depending if you want to create an attribute for all your nodes or an attribute for all your edges. Finally, for the global attributes, they can be used for any node and edge, thus not tied to neither edge/node nor the type.

Please read more information about the attributes here.


Best regards

El dimecres, 23 novembre de 2016 10:38:35 UTC+1, Ray Neiheiser va escriure:

Ray Neiheiser

unread,
Nov 23, 2016, 4:54:47 PM11/23/16
to Sparksee
Thanks for the quick answers.
Is it also possible to get an edge without defining its type?
Only found it with "select" for nodes but select only gets nodes right? Else how would I be able to diferentiate between them.

c3po.ac

unread,
Nov 24, 2016, 8:25:09 AM11/24/16
to Sparksee

Hi,

The kind of objects returned in a Select depend on the type of attribute used:

If you use a specific to type attribute, it will only return objects of that type (wich can be a specific Node Type or a specific Edge Type) so you already know in advance if the result will be a set of nodes or edges.

If you use a NodesType attribute, the result will be a set of nodes, but they may belong to different node types.

If you use an EdgesType attribute, the result will be a set of edges, but they may belong to different edge types.

If the attribute is Global, the result will be a set that can contain both nodes and edges of any type.

Nevertheless, you can always use the "Graph.getObjectType" method to find the type from an object identifier, the "Graph.getType" method to find information about the type and the "Type.getObjectType" to find out if it's an "ObjectType.Node" or an "ObjectType.Edge".

Best regards

El dimecres, 23 novembre de 2016 22:54:47 UTC+1, Ray Neiheiser va escriure:

Ray Neiheiser

unread,
Nov 24, 2016, 12:09:24 PM11/24/16
to Sparksee
Ahh thanks a lot.

I got some problems atm with creating session:

java.lang.RuntimeException: [SPARKSEE: 33] Exceeded license limits.
at com.sparsity.sparkseejavawrapJNI.sparksee_gdb_Database_newSession(Native Method)
at com.sparsity.sparksee.gdb.Database.newSession(Database.java:56)
at main.java.com.bag.server.database.SparkseeDatabaseAccess.applyUpdate(SparkseeDatabaseAccess.java:301)
at main.java.com.bag.operations.UpdateOperation.apply(UpdateOperation.java:34)
at main.java.com.bag.server.TestServer.executeCommit(TestServer.java:189)
at main.java.com.bag.server.TestServer.appExecuteBatch(TestServer.java:137)
at bftsmart.tom.server.defaultservices.DefaultRecoverable.executeBatch(DefaultRecoverable.java:87)
at bftsmart.tom.server.defaultservices.DefaultRecoverable.executeBatch(DefaultRecoverable

This happens here:

Session sess = db.newSession();

c3po.ac

unread,
Nov 25, 2016, 5:47:40 AM11/25/16
to Sparksee

Hi,

The free download version only allows one single session at a time, so you should close the previous one before trying to open a new one. If you are going to need concurrent sessions, please go ahead and request a license through our website, choosing the one that best fits your situation (Researcho or Development) filling in the form.

Best Regards



El dijous, 24 novembre de 2016 18:09:24 UTC+1, Ray Neiheiser va escriure:

Ray Neiheiser

unread,
Nov 25, 2016, 1:02:24 PM11/25/16
to Sparksee
Ahh understood, thanks. Already applied for a research licence.
Since I'm going to have my project on github I can't put the key inside the java config and have to use a separate config file. 
How do I load the config from a file in sparksee?
Didn't find anything in the guide.

c3po.ac

unread,
Nov 28, 2016, 7:11:31 AM11/28/16
to Sparksee

HI,

The Sparksee settings will be automatically loaded if a file with the name "sparksee.cfg" is present in the working directory or you can load any file using the "SparkseeProperties.load" method before creating the SparkseeConfig object. More details can be found here.

Best regards



El divendres, 25 novembre de 2016 19:02:24 UTC+1, Ray Neiheiser va escriure:
Reply all
Reply to author
Forward
0 new messages