Auto generation of Sequence Numbers for nodes in Cypher REST API - Neo4J - rest

I have a requirement to auto generate sequence numbers when inserting nodes into neo4j db, this sequence # will be like an id to the node and can be used to generate external url's to access that node directly from the UI.
This is similar to the auto generation of sequence property in mysql, how can we do this in neo4j via Cypher ? I did some research and found these links
Generating friendly id sequence in Neo4j
http://neo4j.com/api_docs//1.9.M05/org/neo4j/graphdb/Transaction.html
However these links are useful when I'm doing this programatically in transactional mode, in my case it's all using Cypher REST API.
Pls advise.
Thanks,
Deepesh

You can use MERGE to mimic sequences:
MERGE (s:Sequence {name:'mysequenceName'})
ON CREATE s.current = 0
ON MATCH s.current=s.current+1
WITH s.current as sequenceCounter
MATCH .... <-- your statement continues here

If your unique ID does not need to be numeric nor sequential, you can just generate and use a GUID whenever you want to create a node. You have to do this programmatically, and you should pass the value as a parameter, but there should be good libraries for GUID generation in all languages and for all platforms.

Related

Docusign REST API call: Using logical operators for search_text

I’m trying to use a REST API call to find all envelopes with subjects that are either {{cSubject_1}} OR {{cSubject_2}}.
I’m using "search_text" for filtering but I’m not sure how I should use the logical operator for “OR” for this purpose.
I would appreciate if you could help me with this.
Thanks,
Kathy
There's currently no support for this type of complex query in the search_text for The Envelopes:listStatusChanges endpoint.
The search_text allows you to have a single text item that is search across the board (recipients, subject, etc.) and is not limited to a specific meta-data. You can use other filters to filter by other means.
I would recommend storing envelope's meta-data in your application storage (or database) and using your own code to query this information if possible.

UUID as primary key - REST API guideline

In postgres I created a table:
create table examples(id uuid PRIMARY KEY DEFAULT uuid_generate_v4(),
name VARCHAR);
In order to GET all my values from table example i created an endpoint in my framework handler:
GET "/examples[/]?"
If i was using SERIAL or INT type as my PRIMARY KEY my endpoint for single example value would look like this:
GET "/examples/([0-9]+)*"
But im using UUID as primary key and i created this monster : P
GET "/examples/([0-9a-f]{8}-[0-9a-f]{4}-[4][0-9a-f]{3}-[0-9a-f][0-9a-f]{3}-[0-9a-f]{12})"
Use example:
examples/ef935fbc-8c43-4b22-b160-14124a29312e
examples/{uuid}
It works in my case but is there perhaps a better way to do it ?
Are there any good guidelines that tell how to deal with problems like this?
As far as REST is concerned, using a string representation of a UUID as part of a path segment is fine. It's just text. As REST clients just follow links provided to them by the server, it really doesn't matter what spellings are used.
Some choices are going to be easier for your routing framework to manage, but your choice of routing is an implementation detail, and not of any concern to consumers of your API.
There's nothing really wrong with using the framework for coarse grained routing, and then implementing the fine grained control yourself
GET /examples/{data}
if (isUUID(data)):
// cast the data to an id yourself, then do the right thing
if "the-other-thing" == data:
// do the other thing

How to use hbase coprocessor to implement groupby?

Recently I learned hbase coprocessor, I used endpoint to accumulate one column of hbase table.For example, the hbase table named "pendings",its family is "asset", I accumulate all the value of "asset:amount". The table has other columns,such as "asset:customer_name". The first thing I want to do is accumulate the the value of "asset:amount" group by "asset:customer_name". But I found there is not API for groupby, or I did not find it. Do you know how to implement GROUPBY or how to use the API that HBASE provides?
You should use an endpoint to do this work.
You have a sum example in this article: https://blogs.apache.org/hbase/entry/coprocessor_introduction.
What you basically need to add is to append your row key and the customer name to form your new key "MyKey". You should keep a variable of the last seen MyKey and when the current MyKey is different from the previous one, you should emit the previous one along with its sum and overwrite the previous MyKey to the current one.
You have to make sure to perform the aggregation on the client side as it is done in the example provided in the URL because you may have a customer at the edges of two different regions.
Using endpoint coprocessor can make it. All you should do is that : first define related interface(reduce) protocol extends CoprocessorPotocol, then make an implementation of it, lastly code the client-side logic.

Naming resources prior to creation using Neo4j Restful API

This is for people with knowledge on REST and Neo4j.
Is it possible to name a node before creating it in Neo4j ?
Typical Restful thing, you create a URI "XXX/db/data/node/mynode" and you want to create a node with this identifier if it is not existent in the moment.
For all that I have been researching (and testing) to the present moment, the answer is : "no it is not possible, neo4j will just always automatically give ids to the created nodes and the attempt to do create a URI and use POST to cause its creation will result in 405"
Thanks in advance.
That's correct, you can't set the id of a node. What you can do is to add some other kind of id as a property, see create node with properties. Just make sure it's indexed automatically and then you can query that index for exact matches.

Cassandra get_range_slices

I am new to Cassandra and I am having some difficulties fetching data.
I looked into the function:
list<KeySlice> get_range_slices(column_parent, predicate, range, consistency_level)
But, I do not understand what the column_parent is supposed to be.
Anybody any idea?=
Thanx,
Granit
column_parent is basicly used for indicator of ColumnFamily(but in rare cases it can indicate a supercolumn). In java you would put : new ColumnParent("Posts") there. but there should be one more parameter for namespace in get_range_slices query, I guess you are not using thrift but a client api. then you should check your client's documentation.
Edit:
the definition of ColumnParent in cassandra api :
The ColumnParent is the path to the
parent of a particular set of Columns.
It is used when selecting groups of
columns from the same ColumnFamily. In
directory structure terms, imagine
ColumnParent as ColumnPath + '/../'.
Frail is correct, but the real answer is "don't use raw Thrift, use one of the clients from http://wiki.apache.org/cassandra/ClientOptions instead."