Skip to content

d2rq:condition not being applied at all !! #172

domguard opened this Issue Jun 19, 2012 · 3 comments

2 participants


This is a cleaner version of the bug described in issue #144 that we're seeing everywhere
It's also a part of the bug described in the issue #171

I'm just trying to add a property given a dr2q:condition, out of the classic "is not null" condition
If you try the above example, you'll see that resource 2 gets the property even if does not satisfies the condition

You can verify this via SNORQL or via the linked data interface,

Am I missing something here about d2rq:condition usage, or is it a bug ?

Here is some simple data :

    "id" int2 NOT NULL,
    "category" varchar(20) NOT NULL,
    "value" varchar(20) NOT NULL

INSERT INTO "data" VALUES ('1', '04 78 56 89 56', 'tel');
INSERT INTO "data" VALUES ('2', '', 'email');

Then mapping used (just change your db credentials) :

@prefix map: <file:/d2r/mapping.ttl#> .
@prefix db: <> .
@prefix vocab: <http://localhost:2020/vocab/resource/> .
@prefix rdf: <> .
@prefix rdfs: <> .
@prefix xsd: <> .
@prefix d2rq: <> .
@prefix jdbc: <> .
@prefix d2r: <> .
@prefix ess:  <> .
@prefix v: <> .

<> a d2r:Server;
    rdfs:label "Test";
    d2r:port 2020;
    d2r:baseURI <http://localhost:2020/>;
    d2r:autoReloadMapping true;
    d2r:limitPerClassMap false;   # to display everything within the interfac, default is 50

map:database a d2rq:Database;
    d2rq:jdbcDriver "org.postgresql.Driver";
    d2rq:jdbcDSN "jdbc:postgresql://localhost:5432/d2r_test";
    d2rq:username "postgres";
    d2rq:password "xxxxx";

# A contact class is created if value is not empty
map:contact a d2rq:ClassMap;
    d2rq:dataStorage map:database;
    d2rq:uriPattern "contact/";
    d2rq:class ess:Contact;
    d2rq:condition "data.value <> ''"
map:contact_value a d2rq:PropertyBridge;
    d2rq:belongsToClassMap map:contact;
    d2rq:property rdf:value;
    d2rq:column "data.value";

# Another RDF type is added upon a condition based on the 'category' db field    
map:tel_type a d2rq:PropertyBridge;
    d2rq:belongsToClassMap map:contact;
    d2rq:property rdf:type;
    d2rq:constantValue v:Tel;
    d2rq:condition "data.category = 'tel'";

The fact that the conditional property is rdf:type is not important, it happens with any property

Trying to add aliases in the propertyBridge declaration like in :

map:tel_type a d2rq:PropertyBridge;
    d2rq:belongsToClassMap map:contact;
    d2rq:property rdf:type;
    d2rq:constantValue v:Tel;
    d2rq:alias "data AS data_alias";
    d2rq:condition "data_alias.category = 'tel'";

...does not solve the problem.
Rather it adds another errors, the repetition of the rdf:type triples in the XML (not turtle) dump and SPARQL store (but this can be discussed later)

Thanks for your help...


In other contexts, d2rq:condition works as expected.
For example, we use the same pattern (an additional) class but with an additional d2rq:join statement, it works :

map:exchange_method_gift a d2rq:PropertyBridge;
    d2rq:belongsToClassMap map:exchange;
    d2rq:property rdf:type;
    d2rq:constantValue ess:Gift;
    d2rq:alias "coop_local_exchange_methods AS exchange_method_Gift";
    d2rq:condition "exchange_method_Gift.exchangemethod_id = 2";
    d2rq:join " = exchange_method_Gift.exchange_id";
D2RQ member
cygri commented Jun 20, 2012

Thanks for the detailed test case, I will try to work out what's going on.


Trying to understand the SQL output,
I just removed the first d2rq:condition, the one in the classMap about the blank value to not pollute the query

    ("data"."id" = 2 AND ("data"."category" = 'tel')) AS expre9788344, 
    "data"."id" = 2 AS expr32 
FROM "data" 
    "data"."id" = 2 OR 
    ("data"."id" = 2 AND "data"."value" IS NOT NULL) OR 
    ("data"."id" = 2 AND ("data"."category" = 'tel'))

lauching this in PGSQL console, the resulting row shows :

which means that the first expression - that looks as the implementation of the d2rq:condition I'm trying to isolate - was evaluated as "False", which is correct as this row does not have a "tel" category
But the "v:Tel" type is still appended to this resource, so the bug may lie after in the code

I can't interpret the WHERE part :

  • the second line talks about a NOT NULL value, but as I said I had removed this condition (double-checked, strange...)
  • why all these "OR" ? I don't know how D2R treats this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.