[Developers] multiple create unless_exists in one query

Arthur van Hoff AVH at zing.net
Thu Dec 20 15:53:46 UTC 2007


Hi JG,

The problem is a I have a complex write query that writes Internet Radio
streams which each have a stream format, which are often the same. I ran
into a case where the same stream format got created multiple times. I
could not figure out how that could happen until I realized that this
can happen if you create multiple new objects with the same name in the
same query even when using "create":"unless_exists". In my opinion this
is a bug. 

It will be very difficult to ensure that all child objects exist before
I use "create":"unless_exists" (and it kind of defeats the purpose). I
would rather have it create one object and have any subsequent
"create":"unless_exists" in the same query refer to the newly created
object.

Below is an even simpler example that illustrates the problem using
"create":"unless_exists" at the top level. It creates multiple foo2s if
no foo2 existed. Perhaps this can be fixed so that both cases produces a
single foo2, which seems the most natural outcome.

"query": [{
    "type": "/user/avh/default_domain/foo",
    "name": "foo2",
    "create":"unless_exists",
    "id":null
},{
    "type": "/user/avh/default_domain/foo",
    "name": "foo2",
    "create":"unless_exists",
    "id":null
}]

Result:

{
  "status": "200 OK", 
  "code": "/api/status/ok", 
  "result": [
    {
      "create": "created", 
      "type": "/user/avh/default_domain/foo", 
      "id": "/guid/9202a8c04000641f8000000006e601a4", 
      "name": "foo2"
    }, 
    {
      "create": "created", 
      "type": "/user/avh/default_domain/foo", 
      "id": "/guid/9202a8c04000641f8000000006e601a8", 
      "name": "foo2"
    }
  ]
}

You can try this query in the sandbox.

Have fun,

    Arthur van Hoff


	
-----Original Message-----
From: developers-bounces at freebase.com
[mailto:developers-bounces at freebase.com] On Behalf Of John Giannandrea
Sent: Thursday, December 20, 2007 12:56 AM
To: For discussions about MQL,Freebase API and apps built on Freebase
Subject: Re: [Developers] multiple create unless_exists in one query



Arthur,
Im not sure I understand the query here. Can you post the real example?
You normally only need the "create": "unless_exists" clause at the  
toplevel, not in the inner clauses.
You are making foo1.  Does bar1 already exist?
MQL write will try and find a matching clause and then link to it.    
If bar1 didnt exist the it would have to create two of them, which I  
agree is not what you want.
-jg


On Dec 19, 2007, at 11:01 PM, Arthur van Hoff wrote:

> Hi,
>
> I wrote a query that created multiple reference to the same object  
> using "create":"unless_exists".
> Unfortunately, the object did not yet exist, so to my surprise it  
> created multiple objects, not just one.
> Had the object already existed, the right thing would have happened.  
> Is that a feature or a bug?
>
> Here is a simple example:
>
> "query":{
>     "foobar": [{
>         "name": "bar1",
>         "type": "/user/avh/default_domain/bar",
>         "create": "unless_exists"
>     },{
>         "name": "bar1",
>         "type": "/user/avh/default_domain/bar",
>         "create": "unless_exists"
>     }],
>     "create": "unless_exists",
>     "type": "/user/avh/default_domain/foo",
>     "name": "foo1"
> }
>
> The result is:
>
> {
>   "status": "200 OK",
>   "code": "/api/status/ok",
>   "result": {
>     "foobar": [
>       {
>         "create": "created",
>         "type": "/user/avh/default_domain/bar",
>         "name": "bar1"
>       },
>       {
>         "create": "created",
>         "type": "/user/avh/default_domain/bar",
>         "name": "bar1"
>       }
>     ],
>     "create": "created",
>     "type": "/user/avh/default_domain/foo",
>     "name": "foo1"
>   }
> }
>
> I expected this to result in one "bar1", but surprisingly I got two.
> I am not sure how to work around this.
>
> Have fun,
>
>     Arthur van Hoff
>
> ___________________________________________
> Arthur van Hoff, Dell-ZING, CTO Software and Services.
> W: 650-267-2413, F: 650-267-2498, M: 650-283-0842
>
> _______________________________________________
> Developers mailing list
> Developers at freebase.com
> http://lists.freebase.com/mailman/listinfo/developers

_______________________________________________
Developers mailing list
Developers at freebase.com
http://lists.freebase.com/mailman/listinfo/developers


More information about the Developers mailing list