0

I have a bigger problem with the batch import in OrientDB when I use Java.

My data is a collection of recordID's and tokens. For each ID exists a set of tokens but tokens can be in several ID'S.

Example:

ID Tokens

1 2,3,4

2 3,5,7

3 1,2,4

My graph should have two types of verticies: rIDClass and tokenClass. I want to give each vertex an ID corresponding to the recordID and the token. So the total number of tokenClass vertices should be the total number of unique tokens in the data. (Each token is only created once!)

How can I realize this problem? I tried the "Custom Batch Insert" from the original documentation and I tried the method "Batch Implementation", described in the blueprints documentation.

The problem at the first method is that OrientDB creates for each inserted token a separate vertex with a custom ID, which is set by the system itself.

The problem at the second method is when I try to add a vertex to the batchgraph I can't set the corresponding vertex Class and additionally I get an Exception. This is my code from the second method:

BatchGraph<OrientGraph> bgraph = new BatchGraph<OrientGraph>(graph, VertexIDType.STRING, 1);
Vertex vertex1 =  bgraph.addVertex(1);
vertex1.setProperty("uid", 1);

Maybe someone has a solution.

Vertex vertex2 = bgraph.addVertex(2);
vertex2.setProperty("uid", 2);

Edge edge1 = graph.addEdge(12, vertex1 , vertex2, "EdgeConnectClass");

And I get the following Exception:

Exception in thread "main" java.lang.ClassCastException:
com.tinkerpop.blueprints.util.wrappers.batch.BatchGraph$BatchVertex cannot be cast to com.tinkerpop.blueprints.impls.orient.OrientVertex
    at com.tinkerpop.blueprints.impls.orient.OrientBaseGraph.addEdge(OrientBaseGraph.java:612)
    at App.indexRecords3(App.java:83)
    at App.main(App.java:47)
Gayan Mettananda
  • 1,498
  • 14
  • 21
nuwuwa
  • 103
  • 9
  • [This](https://stackoverflow.com/questions/907360/explanation-of-classcastexception-in-java) might help – soufrk Jun 08 '18 at 11:41

1 Answers1

0

I don't know if I understood correctly but, if you want a schema like this:

enter image description here

try this:

Vertex vertex1 = g.addVertex("class:rIDClass");
vertex1.setProperty("uid", 1);

Vertex token2 = g.addVertex("class:tokenClass");
token2.setProperty("uid", 2);

Edge edge1 = g.addEdge("class:rIDClass", vertex1, token2, "EdgeConnectClass");

Hope it helps

Regards

Community
  • 1
  • 1
Michela Bonizzi
  • 2,622
  • 1
  • 9
  • 16
  • Thank you, but I wanted to create a batch insert, and your method is only for the normal insert. I solved the problem but not with the Batchgraph, I used the custom Batch insert from the OrientDB documentation. Attention!!!: I had to diasable transactions!!! – nuwuwa Jun 19 '18 at 16:18