Bringing together the Apache Cassandra experts from the community and DataStax.

Want to learn? Have a question? Want to share your expertise? You are in the right place!

Not sure where to begin? Getting Started

 

question

danielleplex_185261 avatar image
danielleplex_185261 asked ·

Is it possible to trigger a custom function when a vertex is added?

Hi ,


I was wondering if it would be possible to trigger a stored procedure/custom function when adding vertices.

For example , if I add a vertex , I'd like to run a script to potentially generate new vertices. I am looking for a solution like this because of the problem explained here[1] . If i add a new vertex for address , I would like to do a full search to potentially identify new connections.

Is there any way to achieve this or should this be done outside?


[1] https://community.datastax.com/questions/2196/fuzzy-graphs-for-addresses.html

graph
1 comment
10 |1000 characters needed characters left characters exceeded

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

@danielleplex_185261 I'm out-of-pocket right now but I'll reach out internally to get you an answer. Cheers!

0 Likes 0 · ·
Cedrick Lunven avatar image
Cedrick Lunven answered ·

Hi @danielleplex_185261,

Your requests are very interesting. If I understand you well :

  1. you insert a new Vertex and expect to execute some search, find existing vertices that should be related to this new comer and create edges if relevant.
  2. The search is based on a text field like (address) and fuzzy search is expected
  3. You would like to be able to execute this behaviour at server level using function or stored procedure.

I will provide some input based on the Java driver, hope you are using it. By the way all past `dse` driver and OSS drivers are now merged as a single one started with version 4.4, here is the doc https://docs.datastax.com/en/developer/java-driver/4.4/manual/core/dse/graph/


1. Search query

a) To enable fuzzy search with DSE graph attributes you indeed need to create Solr index.

https://docs.datastax.com/en/dse/6.7/dse-dev/datastax_enterprise/graph/using/useSearchIndexes.html

Create the Index:

schema.vertexLabel('recipe').index('search').search(). by('instructions').asText(). by('name').asString().add()

Sample gremlin:

g.V().hasLabel('author').has('name', fuzzy('James Beard', 0)).values('name')


b) The query you mentioned is not pointing the partition key, it will scan multiple nodes even if you created the index. Maybe you want to execute the query as an OLAP statement and use `a....` instead of `g.` https://docs.datastax.com/en/developer/java-driver/4.4/manual/core/dse/graph/options/#available-options


2. Implementation

This is always tricky to expect triggers in Cassandra contexts (when do you start the treatment : when first replica is updated, when you have enough for quorum, when all replica are update ?). As such you should consider to do this operation (find/connect) under the hood in your application.


I would go with a query async to insert the new Vertex. (cf `executeAsync`). You will then get a `CompletionStage<AsyncGraphResultSet>`. On the `onComplete()` method you may want to do the search (olap) and connect (oltp). Using java async capabilities like `thenCombine`, `thenApply` you might be able to do it still in your application but with an asynchronous way.


Other idea but maybe less ideal because edges will not be created immediately would be to trigger a spark job using embedded GraphFrame in DSE to execute searches and create related edges ().


Let's keep updating this post.

Cedrick

2 comments Share
10 |1000 characters needed characters left characters exceeded

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

If I understood correctly, this should be done as an application outside the cluster (like a setup API for example_

1 Like 1 · ·
Cedrick Lunven avatar image Cedrick Lunven ♦ danielleplex_185261 ·

Yes, it should be done at application level.

0 Likes 0 · ·
Erick Ramirez avatar image
Erick Ramirez answered ·

@danielleplex_185261 Implementing custom triggers might be possible but there isn't an out-of-the-box solution and will require developing a custom solution which isn't straightforward (requires consulting engagement).

Hopefully it might not be necessary for your use case based on my response in your other question. Cheers!

Share
10 |1000 characters needed characters left characters exceeded

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.