RMLio / rmlmapper-java

The RMLMapper executes RML rules to generate high quality Linked Data from multiple originally (semi-)structured data sources
http://rml.io
MIT License
147 stars 61 forks source link

Exception is thrown when JSONPath encounters null #103

Closed mielvds closed 3 years ago

mielvds commented 3 years ago

When a JSONPath encounters a null value, the mapper crashes.

16:40:47.846 [main] DEBUG b.u.rml.records.JSONRecordFactory   .getRecords(40) - No document found for data.json. Creating new one
16:40:47.870 [main] DEBUG c.j.j.internal.path.CompiledPath    .evaluate(47) - Evaluating path: $[*]
16:40:47.876 [main] DEBUG c.j.j.internal.path.CompiledPath    .evaluate(47) - Evaluating path: $[0]['custom_fields'][?]['value']
16:40:47.877 [main] DEBUG c.j.j.internal.path.CompiledPath    .evaluate(47) - Evaluating path: @['label']
16:40:47.882 [main] DEBUG c.j.j.internal.path.CompiledPath    .evaluate(47) - Evaluating path: $[0]['name']
16:40:47.883 [main] DEBUG c.j.j.internal.path.CompiledPath    .evaluate(47) - Evaluating path: $[1]['custom_fields'][?]['value']
16:40:47.883 [main] DEBUG c.j.j.internal.path.CompiledPath    .evaluate(47) - Evaluating path: @['label']
16:40:47.883 [main] ERROR be.ugent.rml.cli.Main               .main(312) - null

Example to reproduce:

[
  {
    "id": "001",
    "name": "x",
    "custom_fields": [
      {
        "value": "OR-12345",
        "label": "OR-ID"
      }
    ]
  },
  {
    "id": "002",
    "name": "y",
    "custom_fields": [
      {
        "value": null,
        "label": "OR-ID"
      }
    ]
  },
  {
    "id": "003",
    "name": "z",
    "custom_fields": [
      {
        "value": "OR-1011",
        "label": "OR-ID"
      }
    ]
  }
]
@prefix rr:         <http://www.w3.org/ns/r2rml#> .
@prefix foaf:       <http://xmlns.com/foaf/0.1/> .
@prefix ex:         <http://example.com/> .
@prefix xsd:        <http://www.w3.org/2001/XMLSchema#> .
@prefix rml:        <http://semweb.mmlab.be/ns/rml#> .
@prefix ql:         <http://semweb.mmlab.be/ns/ql#> .
@prefix org:        <http://www.w3.org/ns/org#> .
@prefix skos:       <http://www.w3.org/2004/02/skos/core#> .
@prefix dc:         <http://purl.org/dc/terms/> .
@base               <http://example.org/tm/> .

<json>
  a rr:TriplesMap;

  rml:logicalSource [
    rml:source "data.json";
    rml:referenceFormulation ql:JSONPath;
    rml:iterator "$[*]"
  ];
  rr:subjectMap [
    rr:template "http://example.org/{custom_fields[?(@.label=='OR-ID')].value}";
    rr:class org:Organization
  ]; 
  rr:predicateObjectMap [ 
    rr:predicate skos:altLabel; 
    rr:objectMap [ rml:reference "name"; rr:language "nl" ]
  ].
DylanVanAssche commented 3 years ago

Hi @mielvds !

Thanks for your detailed report! We can reproduce the issue and we're working on a fix.

pheyvaer commented 3 years ago

@mielvds This should be fixed in the latest release (v4.9.4). Can you check if it works for you too?

no-response[bot] commented 3 years ago

This issue has been automatically closed because there has been no response to our request for more information from the original author. With only the information that is currently in the issue, we don't have enough information to take action. Please reach out if you have or find the answers we need so that we can investigate further.

mielvds commented 3 years ago

yes fixed!