Failed to create virtual graph

Hi I'am trying to create virtual graph by connecting mongoDB from stardog studio.
My MongoDB URI:
mongodb://localhost/dbname After clicking create button I got error

Failed to create virtual graph dbname

I saw log file and it shows error
`ERROR 2019-10-10 11:20:28,587 [stardog-user-1] com.complexible.stardog.virtual.DefaultVirtualGraphRegistry:createVirtualGraph(352): Cannot initialize virtual graph mongoDB
com.complexible.stardog.plan.parser.QueryParseException: Encountered "" at line 1, column 0.
Was expecting one of:
...
"base" ...
"prefix" ...
"mapping" ...

at com.complexible.stardog.plan.parser.QueryParserImpl.parseDatasourceMappings(QueryParserImpl.java:507) ~[stardog-7.0.1.jar:?]
at com.complexible.stardog.virtual.vega.mongo.MongoMappingsParser.parseMappings(MongoMappingsParser.java:227) ~[stardog-virtual-core-7.0.1.jar:?]
at com.complexible.stardog.virtual.vega.mongo.MongoVirtualGraphFactory.create(MongoVirtualGraphFactory.java:38) ~[stardog-virtual-core-7.0.1.jar:?]
at com.complexible.stardog.virtual.vega.mongo.MongoVirtualGraphFactory.create(MongoVirtualGraphFactory.java:22) ~[stardog-virtual-core-7.0.1.jar:?]
at com.complexible.stardog.virtual.DefaultVirtualGraphRegistry.createVirtualGraph(DefaultVirtualGraphRegistry.java:349) ~[stardog-virtual-core-7.0.1.jar:?]
at com.complexible.stardog.virtual.DefaultVirtualGraphRegistry.createVirtualGraph(DefaultVirtualGraphRegistry.java:335) ~[stardog-virtual-core-7.0.1.jar:?]
at com.complexible.stardog.virtual.DefaultVirtualGraphRegistry.add(DefaultVirtualGraphRegistry.java:196) ~[stardog-virtual-core-7.0.1.jar:?]
at com.complexible.stardog.virtual.SecuredVirtualGraphRegistry.add(SecuredVirtualGraphRegistry.java:146) ~[stardog-virtual-core-7.0.1.jar:?]
at com.complexible.stardog.protocols.http.server.virtual.admin.VirtualGraphHttpService.addVG(VirtualGraphHttpService.java:391) ~[stardog-virtual-protocols-http-server-7.0.1.jar:?]
at com.complexible.stardog.protocols.http.server.virtual.admin.VirtualGraphHttpService.add(VirtualGraphHttpService.java:193) ~[stardog-virtual-protocols-http-server-7.0.1.jar:?]
at com.stardog.http.server.undertow.jaxrs.ExtractRoutes.lambda$handleIt$5(ExtractRoutes.java:192) ~[stardog-protocols-http-server-7.0.1.jar:?]
at org.apache.shiro.subject.support.SubjectRunnable.doRun(SubjectRunnable.java:120) [shiro-core-1.3.0.jar:1.3.0]
at org.apache.shiro.subject.support.SubjectRunnable.run(SubjectRunnable.java:108) [shiro-core-1.3.0.jar:1.3.0]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [?:1.8.0_222]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [?:1.8.0_222]
at java.lang.Thread.run(Thread.java:748) [?:1.8.0_222]`

Note:- I have added mongo-java-driver-3.8.2.jar to STARDOG_EXT.

Not sure if i'am missing something!!

Can you share your mapping file?

I should have mentioned I'm completely new to Stardog so i missed the mapping part.Sorry for that.. Just came to know we have to create the mapping file for our data then do a mongodb connection..

  1. I would like to know do I have to create mapping file manually or is there a way stardog studio does it automatically?

  2. If this mapping file I have to create manually can you please share some tutorial or guide as in how can i convert my json data to a mapping file and then make a mongodb connection.

I went through stardog/docs and googled but couldn't find much.

Sorry for being naive.. Just getting started with stardog..

No problem, welcome to Stardog.

Stardog will create a default mapping for relational database targets but I don't believe there is anything similar for json/graphql mappings so you'll need to create a mapping by hand.

There is this blog post https://www.stardog.com/blog/native-mongodb-support-is-here/
and the documentation that you said you looked at already https://www.stardog.com/docs/#_structured_data_virtual_graphs

I'd take a look over it again and see what you can make of it and check back here if you get stuck or need help.

We all have to start somewhere. Feel free to ask questions.

Thanks for the quick response.. I will try it out and get back.

Hi @zachary.whitley

As per our last discussion I went through few docs and webinar videos on virtual graph and tried to create simple mapping file for my sample mongodb collection..

Steps I followed:-

  1. I created a movie.sms file in which i wrote my mapping for my sample data, as follows

PREFIX : http://schema.org/
Mapping
FROM JSON {
"movies":{
"_id": "?movieId",
"title": "?name",
"year": "?year",
"cast":["?actors"],
"genres": [ "?genre" ]
}
}
TO {
?movie a :Movie;
:title ?name;
:year ?year;
:cast ?cast;
:genre ?genre .
}
WHERE {
BIND (template("http://example.com/movies/name/{movieId}") AS ?movie)
BIND (xsd:date(?year) AS ?year)
}

  1. After this i clicked create virtual graph which created a file under virtual graph tab with name given as "movies".

  2. Now i press save changes button i got an error "failed to create virtual graph".Error this time is different than the last one.. I checked my log and it says

java.lang.StackOverflowError: null ERROR 2019-10-12 17:48:13,031 [stardog-user-8] com.stardog.http.server.undertow.ErrorHandling:writeError(138): Unexpected error on the server** java.lang.StackOverflowError: null at java.util.ArrayList$ArrayListSpliterator.estimateSize(ArrayList.java:1392) ~[?:1.8.0_222] at java.util.Spliterator.getExactSizeIfKnown(Spliterator.java:408) ~[?:1.8.0_222] at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:481) ~[?:1.8.0_222] at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:472) ~[?:1.8.0_222] at java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:708) ~[?:1.8.0_222] at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234) ~[?:1.8.0_222] at java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:566) ~[?:1.8.0_222] at com.complexible.stardog.virtual.vega.json.JsonMappingArrayGrouping.getArrays(JsonMappingArrayGrouping.java:97) ~[stardog-virtual-core-7.0.1.jar:?] at com.complexible.stardog.virtual.vega.json.JsonMappingArrayGrouping.lambda$getArrays$3(JsonMappingArrayGrouping.java:100) ~[stardog-virtual-core-7.0.1.jar:?] at java.util.stream.ReferencePipeline$7$1.accept(ReferencePipeline.java:269) ~[?:1.8.0_222] at java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1382) ~[?:1.8.0_222] at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:482) ~[?:1.8.0_222]

Not sure if this is because i was not able to create mapping file properly or is it something else?
Need support.

Have uploaded my sample json data file which is present on mongodb.

movies.json (809 Bytes)

Congratulations, I think you may have your first bug report. :slight_smile:

What version of Stardog are you running?

Stardog version is 7.0.1

This may or may not fix your issue, but it looks like :cast ?cast; in your TO clause should be :cast ?actors;.

1 Like

Thanks @jason for pointing it out.. I changed it but still i got the same error.. I am attaching the log file.. stardog.log (97.6 KB) Please have a look

@zachary.whitley @jason

I have few doubts apart from above mentioned error, just to make sure I have not missed anything.
I saw in docs for RDBMS virtual graph we have to give jdbc properties like
jdbc.url=jdbc:mysql://localhost/music jdbc.username=admin jdbc.password=admin jdbc.driver=com.mysql.jdbc.Driver
I was wondering if such kind of properties are not required for mongodb as in Stardog studio i see option only for mongodb.uri !!

One more thing i want to clarify is, I saw a command in docs to add a new virtual graph
stardog-admin virtual add dept.properties dept.ttl

Is it required to add virtual graph through terminal(using above command) even if we are using Stardog Studio to create the graph??

@zachary.whitley @jason

This BIND expression is your issue. You cannot use the same variable in both the source and target. You should use a different target variable, eg BIND(xsd:date(?year) as ?yearDate), and use that in the mapping. That said, if it's just a year, it cannot be cast to a date.

Regarding the properties file, you can include the MongoDB username and password in the URI. There's an example in the docs.

When creating a virtual graph in Stardog Studio, it is not required to do anything additional from the command line.

Jess

1 Like

I forgot to mention that it's possible to do the cast in the target of the mapping like so:

    :boxOffice "?boxOffice"^^xsd:integer ;

Thanks alot @jess and team after doing this change it worked :slight_smile: i am able to create the graph, it shows me a success message.

Regarding mongodb connection I have done as suggested in docs

mongodb://localhost/DbName

Note:- My mongodb and stardog are running on a remote server where as my studio is running on a local machine (local machine and remote server are connected via VPN) . Stardog Studio is connected to the server.

After this i ran a simple query of SELECT.. But i see empty result with a message successfully executed query.. How can i be sure my stardog studio is connected to mongodb. When i execute a query I checked stardog logs also but nothing gets printed there.

It would be great if you can help resolve this

Can you share the query that is not returning any results? What is the name of your virtual graph?

It worked @jess may there was some network issue.. Thanks a lot stardog team for the support..