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.
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..
I would like to know do I have to create mapping file manually or is there a way stardog studio does it automatically?
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..
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.
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:-
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)
}
After this i clicked create virtual graph which created a file under virtual graph tab with name given as "movies".
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.
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
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??
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.
Thanks alot @jess and team after doing this change it worked 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.
There was a bug causing your initial error that prevented you from establishing the connection and then creating the mapping in Studio to fully create the Virtual Graph. We'll have a fix for that out soon. But for all other data sources (and for Mongo shortly), Jess is right - you can create them fully from within Studio.