frmichel / morph-xr2rml

Implementation of the xR2RML mapping language and SPARQL-to-MongoDB prototype
Apache License 2.0
23 stars 5 forks source link

"Invalid query string" leads to NPE in unfoldTriplesMap #10

Open namedgraph opened 2 months ago

namedgraph commented 2 months ago

Hi. Can anyone explain whether this is a bug or am I doing smth wrong?

java.lang.NullPointerException
    at fr.unice.i3s.morph.xr2rml.mongo.engine.MorphMongoUnfolder.unfoldTriplesMap(MorphMongoUnfolder.scala:52)
    at fr.unice.i3s.morph.xr2rml.mongo.engine.MorphMongoDataTranslator.generateRDFTriples(MorphMongoDataTranslator.scala:61)
    at es.upm.fi.dia.oeg.morph.base.engine.MorphBaseDataTranslator.$anonfun$translateData_Materialization$1(MorphBaseDataTranslator.scala:55)
    at es.upm.fi.dia.oeg.morph.base.engine.MorphBaseDataTranslator.$anonfun$translateData_Materialization$1$adapted(MorphBaseDataTranslator.scala:49)
    at scala.collection.immutable.Set$Set1.foreach(Set.scala:124)
    at es.upm.fi.dia.oeg.morph.base.engine.MorphBaseDataTranslator.translateData_Materialization(MorphBaseDataTranslator.scala:49)
    at es.upm.fi.dia.oeg.morph.base.engine.MorphBaseRunner.runMaterialization(MorphBaseRunner.scala:42)
    at es.upm.fi.dia.oeg.morph.base.engine.MorphBaseRunner.run(MorphBaseRunner.scala:31)
    at fr.unice.i3s.morph.xr2rml.engine.MorphRunner$.main(MorphRunner.scala:97)
    at fr.unice.i3s.morph.xr2rml.engine.MorphRunner.main(MorphRunner.scala)

Mapping mapping_vacancies.ttl

@prefix rdfs:   <http://www.w3.org/2000/01/rdf-schema#>.
@prefix schema: <http://schema.org/> .
@prefix rr:     <http://www.w3.org/ns/r2rml#> .
@prefix xrr:    <http://i3s.unice.fr/xr2rml#> .

<#JobPostings>
    a rr:TriplesMap;
    xrr:logicalSource [
        xrr:query "db.vacancies.find({})";
    ];
    rr:subjectMap [ 
        rr:template "https://data.something.com/something/job_requisitions/{$.id}#this"; 
        rr:class schema:JobPosting;
    ];
    rr:predicateObjectMap [
        rr:predicate schema:name;
        rr:objectMap [ xrr:reference "$.title" ];
    ];
    rr:predicateObjectMap [
        rr:predicate schema:description;
        rr:objectMap [ xrr:reference "$.description" ];
    ];
    .

Running this command:

cd docker
XR2RML_CONTAINER=$(docker ps --format=='{{.Names}}' | grep "morph-xr2rml" | cut -d= -f2)
docker exec -w /xr2rml_config $XR2RML_CONTAINER \
   /bin/bash run_xr2rml.sh mapping_vacancies.ttl vacancies.ttl
namedgraph commented 2 months ago

OK, I see this error in the log now:

2024-09-13 14:31:55 ERROR [main] (MongoDBQuery.scala:76) - Invalid query string: db.vacancies.find({})

Why is the query string invalid if it works in MongoDB? Your mapping_movies.ttl example contains almost identical query string db.{{collection}}.find({})?

frmichel commented 2 months ago

Hi @namedgraph, this indeed looks surprising. I need a bit more details to investigate the issue.

Please activate the DEBUG log level, empty the log file and rerun. Then send me the log file along with the morph.properties and your mapping files. (franck.michel[at]inria.fr)

To activte the DEBUG log lebel, simply set the following lines at the end of the log4j.properties:

log4j.logger.es.upm.fi.dia.oeg.morph.base.engine.MorphBaseRunner=DEBUG
log4j.logger.fr.unice.i3s.morph.xr2rml.mongo.engine.MorphMongoDataSourceReader=DEBUG
log4j.logger.fr.unice.i3s.morph.xr2rml.mongo.engine.MorphMongoDataTranslator=DEBUG
namedgraph commented 2 months ago

I found the cause :) https://github.com/frmichel/morph-xr2rml/blob/master/morph-xr2rml-mongo/src/main/scala/fr/unice/i3s/morph/xr2rml/mongo/MongoDBQuery.scala#L76 Why is db hardcoded though?

namedgraph commented 2 months ago

Sorry I should have mentioned that my actual DB is not called db but seed.

namedgraph commented 2 months ago

I've replaced the query with xrr:query "db.vacancies.find({})"; (not sure how it's supposed to resolve to seed? But that's another issue) and now I get:

com.mongodb.MongoSecurityException: Exception authenticating
    at com.mongodb.internal.connection.NativeAuthenticator.authenticate(NativeAuthenticator.java:48)
    at com.mongodb.internal.connection.InternalStreamConnectionInitializer.authenticateAll(InternalStreamConnectionInitializer.java:156)
    at com.mongodb.internal.connection.InternalStreamConnectionInitializer.initialize(InternalStreamConnectionInitializer.java:63)
    at com.mongodb.internal.connection.InternalStreamConnection.open(InternalStreamConnection.java:129)
    at com.mongodb.internal.connection.UsageTrackingInternalConnection.open(UsageTrackingInternalConnection.java:50)
    at com.mongodb.internal.connection.DefaultConnectionPool$PooledConnection.open(DefaultConnectionPool.java:398)
    at com.mongodb.internal.connection.DefaultConnectionPool.get(DefaultConnectionPool.java:115)
    at com.mongodb.internal.connection.DefaultConnectionPool.get(DefaultConnectionPool.java:101)
    at com.mongodb.internal.connection.DefaultServer.getConnection(DefaultServer.java:92)
    at com.mongodb.binding.ClusterBinding$ClusterBindingConnectionSource.getConnection(ClusterBinding.java:126)
    at com.mongodb.operation.FindOperation$1.call(FindOperation.java:728)
    at com.mongodb.operation.FindOperation$1.call(FindOperation.java:725)
    at com.mongodb.operation.OperationHelper.withReadConnectionSource(OperationHelper.java:463)
    at com.mongodb.operation.FindOperation.execute(FindOperation.java:725)
    at com.mongodb.operation.FindOperation.execute(FindOperation.java:89)
    at com.mongodb.client.internal.MongoClientDelegate$DelegateOperationExecutor.execute(MongoClientDelegate.java:196)
    at com.mongodb.client.internal.MongoClientDelegate$DelegateOperationExecutor.execute(MongoClientDelegate.java:177)
    at com.mongodb.DBCursor.initializeCursor(DBCursor.java:989)
    at com.mongodb.DBCursor.hasNext(DBCursor.java:172)
    at org.jongo.MongoCursor.hasNext(MongoCursor.java:38)
    at scala.collection.convert.Wrappers$JIteratorWrapper.hasNext(Wrappers.scala:43)
    at scala.collection.Iterator.foreach(Iterator.scala:943)
    at scala.collection.Iterator.foreach$(Iterator.scala:943)
    at scala.collection.AbstractIterator.foreach(Iterator.scala:1431)
    at scala.collection.generic.Growable.$plus$plus$eq(Growable.scala:62)
    at scala.collection.generic.Growable.$plus$plus$eq$(Growable.scala:53)
    at scala.collection.mutable.ListBuffer.$plus$plus$eq(ListBuffer.scala:184)
    at scala.collection.mutable.ListBuffer.$plus$plus$eq(ListBuffer.scala:47)
    at scala.collection.TraversableOnce.to(TraversableOnce.scala:348)
    at scala.collection.TraversableOnce.to$(TraversableOnce.scala:346)
    at scala.collection.AbstractIterator.to(Iterator.scala:1431)
    at scala.collection.TraversableOnce.toList(TraversableOnce.scala:332)
    at scala.collection.TraversableOnce.toList$(TraversableOnce.scala:332)
    at scala.collection.AbstractIterator.toList(Iterator.scala:1431)
    at fr.unice.i3s.morph.xr2rml.mongo.engine.MorphMongoDataSourceReader.execute(MorphMongoDataSourceReader.scala:69)
    at fr.unice.i3s.morph.xr2rml.mongo.engine.MorphMongoDataSourceReader.executeQueryAndIterator(MorphMongoDataSourceReader.scala:103)
    at fr.unice.i3s.morph.xr2rml.mongo.engine.MorphMongoDataTranslator.generateRDFTriples(MorphMongoDataTranslator.scala:65)
    at es.upm.fi.dia.oeg.morph.base.engine.MorphBaseDataTranslator.$anonfun$translateData_Materialization$1(MorphBaseDataTranslator.scala:55)
    at es.upm.fi.dia.oeg.morph.base.engine.MorphBaseDataTranslator.$anonfun$translateData_Materialization$1$adapted(MorphBaseDataTranslator.scala:49)
    at scala.collection.immutable.Set$Set1.foreach(Set.scala:124)
    at es.upm.fi.dia.oeg.morph.base.engine.MorphBaseDataTranslator.translateData_Materialization(MorphBaseDataTranslator.scala:49)
    at es.upm.fi.dia.oeg.morph.base.engine.MorphBaseRunner.runMaterialization(MorphBaseRunner.scala:42)
    at es.upm.fi.dia.oeg.morph.base.engine.MorphBaseRunner.run(MorphBaseRunner.scala:31)
    at fr.unice.i3s.morph.xr2rml.engine.MorphRunner$.main(MorphRunner.scala:97)
    at fr.unice.i3s.morph.xr2rml.engine.MorphRunner.main(MorphRunner.scala)
Caused by: com.mongodb.MongoCommandException: Command failed with error 352 (UnsupportedOpQueryCommand): 'Unsupported OP_QUERY command: getnonce. The client driver may require an upgrade. For more details see https://dochub.mongodb.org/core/legacy-opcode-removal' on server host.docker.internal:27921. The full response is {"ok": 0.0, "errmsg": "Unsupported OP_QUERY command: getnonce. The client driver may require an upgrade. For more details see https://dochub.mongodb.org/core/legacy-opcode-removal", "code": 352, "codeName": "UnsupportedOpQueryCommand"}
    at com.mongodb.internal.connection.ProtocolHelper.getCommandFailureException(ProtocolHelper.java:175)
    at com.mongodb.internal.connection.InternalStreamConnection.receiveCommandMessageResponse(InternalStreamConnection.java:303)
    at com.mongodb.internal.connection.InternalStreamConnection.sendAndReceive(InternalStreamConnection.java:259)
    at com.mongodb.internal.connection.CommandHelper.sendAndReceive(CommandHelper.java:83)
    at com.mongodb.internal.connection.CommandHelper.executeCommand(CommandHelper.java:33)
    at com.mongodb.internal.connection.NativeAuthenticator.authenticate(NativeAuthenticator.java:39)
    ... 44 more
namedgraph commented 2 months ago

I've tried upgrading mongo-java-driver in morph-xr2rml-mongo to 3.12.14 but then I'm not able to run mvn clean install:

[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary for morph-xr2rml parent project 1.3.2-SNAPSHOT:
[INFO] 
[INFO] morph-xr2rml parent project ........................ SUCCESS [  0.127 s]
[INFO] morph-core ......................................... FAILURE [  1.746 s]
[INFO] morph-xr2rml-lang .................................. SKIPPED
[INFO] morph-base ......................................... SKIPPED
[INFO] morph-xr2rml-mongo ................................. SKIPPED
[INFO] morph-xr2rml-rdb ................................... SKIPPED
[INFO] morph-xr2rml-dist .................................. SKIPPED
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  1.944 s
[INFO] Finished at: 2024-09-16T10:59:44+02:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal on project morph-core: Could not resolve dependencies for project fr.unice.i3s:morph-core:jar:1.3.2-SNAPSHOT: Failed to collect dependencies at zql:zql:jar:0.1: Failed to read artifact descriptor for zql:zql:jar:0.1: The following artifacts could not be resolved: zql:zql:pom:0.1 (present, but unavailable): Could not transfer artifact zql:zql:pom:0.1 from/to codelds (https://code.lds.org/nexus/content/groups/main-repo): code.ldschurch.org: nodename nor servname provided, or not known: Unknown host code.ldschurch.org: nodename nor servname provided, or not known -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/DependencyResolutionException
[ERROR] 
[ERROR] After correcting the problems, you can resume the build with the command
[ERROR]   mvn <args> -rf :morph-core

Looks like the project needs some upgrades...

frmichel commented 2 months ago

Hi, I would not recommend to update the mongo driver, I've never tried this and I suspect you'll get into other compatibility issues. I can try to recompile without the restriction about "db.". I'll let you know.

namedgraph commented 2 months ago

@frmichel can we make sure first that the project builds? :) Maybe the db is not an issue.

The docker-compose setup is pretty weird too :) I can try to make a PR.