typhon-project / typhonql

Typhon Query Language
Eclipse Public License 2.0
4 stars 1 forks source link

[BUG] Opposite relationships defined in DocumentDB are handled as simple relationships #67

Open meuriceloup opened 4 years ago

meuriceloup commented 4 years ago

Hi,

This is the deployed TML schema:

entity Product {
    id : String
    orders -> Order[1]
}
entity Order {
    id : String
    products -> Product."Product.orders"[1]
}

documentdb DocumentDatabase {
    collections {
        Order : Order
        Product : Product
    }
}

In this schema, there are two defined entities declared in the documentdb. In addition, a 1-1 opposite relationship is defined between both entities. However, it seems that the polystore handles this opposite relationship as two simple unrelated relationships. Scenario:

1) I executed this insert statement: insert Product {id: "p", orders: Order {id: "o"}} 2) I secondly executed this one (in the inverse sense): insert Order {id:"o2", products: Product {id: "p2"}} 3) I executed this select query: from Product p, Order o select p, o where p.orders == o

However, it only returns this:

(
  "Order":[<"Order","6a7fb7d1-ed40-4f72-838b-7a3077f4b8ad",("id":"o")>],
  "Product":[<"Product","162f73d2-ea92-4437-a6aa-e9deb00b0947",(
      "orders":<true,"6a7fb7d1-ed40-4f72-838b-7a3077f4b8ad">,
      "id":"p"
    )>]
)

it was supposed to return (o2, p2) as well, since an opposite relationship is defined. For obtaining the complete results: I had to execute this QL query:

from Product p, Order o select p, o where o.products == p || p.orders == o

I then took a look at the MongoDB structures and the stored data and, indeed, the opposite relationship seems to be handled as two different relationships... This is what the MongoDB looks:

image image

In first image, field 'Order.product' is used to store relationship (o2, p2). In second image, field 'Product.orders' is used to store relationship (o,p).

This way to handle the opposite relation seems equivalent to handling two different relationships and it causes the incomplete results when executing this QL query: from Product p, Order o select p, o where p.orders == o

DavyLandman commented 4 years ago

The code around relationships is changing this week, so I hope the bug will be gone then. We'll check again next week.

tvdstorm commented 4 years ago

Hi @meuriceloup , thanks for the report. Could you try this in the current compiler as follows:

insert Order {@id: #o}
insert Product {@id: #p, orders: #o }

and then:

insert Product {@id: #p2}
insert Order {@id: #o2, products: #p2 }

(NB: your relation names are plural, but the cardinality is single, which is a bit confusing)