[Developers] multiple create unless_exists in one query

Arthur van Hoff AVH at zing.net
Thu Dec 20 17:22:46 UTC 2007


Hi Kurt,

Although I understand that I can re-write my code, make it significantly
more complex and less efficient, in order to work around this bug, that
does not seem the right answer to me. This is something that Freebase
should solve for me. 

Why can't the write operation check whether the same object is created
multiple times in a request? That would seem a quite simple and fast. It
also avoids programmer errors, and it does not burden the developer with
writing impossibly complex checks that require multiple round trips
which 99% of time are entirely superfluous.

If you can't fix this, then I suggest you restrict the use of
"create":"unless_exists" to a single top level object. That way you
force every programmer into the same correct programming pattern. 
 
Have fun,

    Arthur van Hoff

-----Original Message-----
From: developers-bounces at freebase.com
[mailto:developers-bounces at freebase.com] On Behalf Of Kurt Bollacker
Sent: Thursday, December 20, 2007 8:51 AM
To: developers at freebase.com
Subject: Re: [Developers] multiple create unless_exists in one query


On Thu, Dec 20, 2007 at 07:53:46AM -0800, Arthur van Hoff wrote:
> 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.

It is fair to say that their ought to be an easy and obvious way to
handle multiple inserts (in the same query) of the same topic.

However,currently it is My understanding is that in processing a MQL
query envelope, all verifying reads (e.g. does foo2 exist?) are done
before any writes are done.  Thus, you can't count on dependencies
between queries in the same envelope being satistfied.  If you want to
avoid dependency problems, you can break your writes into simpler
query envelopes.  I give the mod to your example below.  In your
earlier example, just perform the sub-query inserts as their own
query.

This is not perfect, but it will work, and should not affect
performance significantly.

								Kurt :-)

 
> 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
> }]

Just do this query twice:

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

1st RESULT:
{
  "code" : "/api/status/ok",
  "result" : {
    "create" : "created",
    "id" : "/guid/9202a8c04000641f8000000006e601c3",
    "name" : "foo002",
    "type" : "/user/avh/default_domain/foo"
  }
}

2nd RESULT:

{
  "code" : "/api/status/ok",
  "result" : {
    "create" : "existed",
    "id" : "/guid/9202a8c04000641f8000000006e601c3",
    "name" : "foo002",
    "type" : "/user/avh/default_domain/foo"
  }
}

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


More information about the Developers mailing list