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] Problem with join between entities stored in different containers #118

Open
meuriceloup opened this issue Jan 28, 2021 · 4 comments
Open
Labels
bug Something isn't working

Comments

@meuriceloup
Copy link

Hi guys,

By testing random QL queries, I'm facing with strange errors:
I would like to execute a join between two entities stored in different containers (one in MariaDB and the other one in MongoDB) but it returns an error...

This is my (reduced) schema:

entity "User" {
	"id" : string[32]
	"name" : string[32]
	"paymentsDetails" : string
	"comments" -> "Comment"[0..*]
	"address" -> "UserAddress"[0..1]
}

entity UserAddress {
	streetName: string[32]
	streetNumber: bigint
	zipcode: string[32]
	city: string[32]
	country: string[32]
	user -> "User"."User.address"[0..1]
}

relationaldb RelationalDatabase {
   tables {
      table {
      	"User" : "User"
      }
   }
}

documentdb DocumentDatabase{
	collections{
			UserAddress : UserAddress
	}
}

This is my query:

from User u, UserAddress ua
select u.id
where u.address == ua

And this is the returned error:

typhonql-server_1           | REQ: from User u, UserAddress ua
typhonql-server_1           | select u.id
typhonql-server_1           | where u.address == ua
typhonql-server_1           | NORMALIZED: from User u, UserAddress ua select u.id where u.address == ua
typhonql-server_1           | ORDER: [<mongodb(),"DocumentDatabase">,<sql(),"RelationalDatabase">]
typhonql-server_1           | PLACEMENTS: {<<mongodb(),"DocumentDatabase">,"UserAddress">,<<mongodb(),"DocumentDatabase">,"User">,<<mongodb(),"DocumentDatabase">,"Comment">,<<sql(),"RelationalDatabase">,"Products">,<<sql(),"RelationalDatabase">,"Suppliers">,<<sql(),"RelationalDatabase">,"CustomerDemographics">,<<sql(),"RelationalDatabase">,"Order_Details">,<<sql(),"RelationalDatabase">,"Shippers">,<<sql(),"RelationalDatabase">,"Region">,<<sql(),"RelationalDatabase">,"Customers">,<<sql(),"RelationalDatabase">,"Territories">,<<sql(),"RelationalDatabase">,"Categories">,<<sql(),"RelationalDatabase">,"Orders">,<<sql(),"RelationalDatabase">,"Employees">}
typhonql-server_1           | Warning: calling function with extra unknown keyword argument: log
typhonql-server_1           | COMPILING2Mongo: from User u, UserAddress ua select u.id where u.address == ua
typhonql-server_1           | 16:31:21.201 [qtp402405659-12] ERROR engineering.swat.typhonql.server.QLRestServer - Failed to handle response
typhonql-server_1           | org.rascalmpl.interpreter.control_exceptions.Throw: |lib://typhonql/src/lang/typhonql/mongodb/Query2Mongo.rsc|:468,81: "Only dynamic parameters can be used as expressions in query docs, not ua.@id"
typhonql-server_1           |   at org.rascalmpl.interpreter.control_exceptions.ControlException.reallyFillInStackTrace(ControlException.java:42) ~[rascal-0.18.2.jar:?]
typhonql-server_1           |   at org.rascalmpl.interpreter.control_exceptions.Throw.fillInStackTrace(Throw.java:138) ~[rascal-0.18.2.jar:?]
typhonql-server_1           |   at java.lang.Throwable.<init>(Throwable.java:266) ~[?:1.8.0_275]
typhonql-server_1           |   at java.lang.Exception.<init>(Exception.java:66) ~[?:1.8.0_275]

Did I miss something? Thanks in advance

@meuriceloup meuriceloup added the bug Something isn't working label Jan 28, 2021
@meuriceloup
Copy link
Author

In the meantime, I replaced the relationship [0..1] to [0..1] defined between User and UserAddress by a [1] to [1] relation.
The error surprinsingly disappeared...

This problem is not blocking for me since I can slightly change the schema with 1 to 1 relation ;-)

@tvdstorm
Copy link
Contributor

Excellent, I'll leave the issue open, but now we can narrow it down easier. Thanks.

@tvdstorm
Copy link
Contributor

tvdstorm commented Feb 2, 2021

I did some digging, and cannot really reproduce. This is the log and compiled result (with the above TyphonML model), which looks ok:

REQ: from User u, UserAddress ua select u.@id where u.address == ua
NORMALIZED: from User u, UserAddress ua select u.@id where u.address == ua
ORDER: [<sql(),"RelationalDatabase">,<mongodb(),"DocumentDatabase">]
PLACEMENTS: {<<mongodb(),"DocumentDatabase">,"UserAddress">,<<sql(),"RelationalDatabase">,"User">}
COMPILING2SQL: from User u, #ignored(UserAddress ua) select u.@id where #needed(u.address == ua)
COMPILING2Mongo: from #dynamic(User u), UserAddress ua select #done(u.@id) where u.address == ua
Script: script([
    step(
      "RelationalDatabase",
      sql(executeQuery("RelationalDatabase","select `u`.`User.@id` as `u.User.@id`, `junction_address$0`.`UserAddress.user` as `u.User.address` \nfrom `User` as `u` left outer join `User.address-UserAddress.user` as `junction_address$0` on (`junction_address$0`.`User.address`) = (`u`.`User.@id`)\n;")),
      (),
      signature=[
        <"RelationalDatabase","u","User",["@id"]>,
        <"RelationalDatabase","u","User",["address"]>
      ]),
    step(
      "DocumentDatabase",
      mongo(find("DocumentDatabase","UserAddress","{\"_id\": \"${u_address_0}\"}","{\"_id\": 1}")),
      ("u_address_0":field("RelationalDatabase","u","User","address")),
      signature=[]),
    read([<"RelationalDatabase","u","User",["@id"]>])
  ])

@tvdstorm
Copy link
Contributor

tvdstorm commented Feb 2, 2021

Btw, just noticed you use id and not @id in the query, but this doesn't change the behavior on my machine.

tvdstorm added a commit that referenced this issue Feb 2, 2021
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

2 participants