Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
meuriceloup opened this issue Mar 11, 2020 · 2 comments
Labels
bug Something isn't working

Comments

@meuriceloup
Copy link

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

@meuriceloup meuriceloup added the bug Something isn't working label Mar 11, 2020
@DavyLandman
Copy link
Contributor

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

@DavyLandman DavyLandman added this to the Compiled QL Queries milestone Mar 12, 2020
@tvdstorm
Copy link
Contributor

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants