[Developers] Comparison operation in write?

Kurt Bollacker kurt at metaweb.com
Mon Dec 24 06:05:20 UTC 2007


On Sun, Dec 23, 2007 at 09:25:04PM -0800, Arthur van Hoff wrote:
> What do you mean legal MQL? This query works just fine as a read query:

MQL read syntax and MQL write syntax are slightly different.  The
semantics of arrays is one of the places where they are not the same.

> "query":[{
>     "type": "/user/cotton/default_domain/internet_station",
>     "internet_streams": [{
>         "uri~=": "*live365*",
>         "uri":null,
>         "type": "/user/cotton/default_domain/internet_availability"
>     }],
>     "id": null,
>     "name": null
> }]
> 
> Also, what do you mean [{.....}] vs [{...},{...},{...}]?

Look in section 5.1.6 of the MQL API docs.  If you are going to
specify multiple MQL writes (whether they are the same shape or
not), you need to specify the clauses explicitly.  From the docs:

[{
  "create":"unless_exists",
  "id":null,
  "type":"/user/docs/note",
  "name":"C"
},{
  "create":"unless_exists",
  "id":null,
  "type":"/user/docs/note",
  "name":"G"
}]

Creates two instances of the "note" type.  Each instance is within its
own {}.  So if you want to do N "notes", you'll use N {}'s.  You need
to specify how many assertions you are making (e.g. how many
"broadcaster" property links) in a write before it is executed.
 
> Since multiple queries are not transactional I would like to write a
> SINGLE query that finds all internet_stations that contain live365 in
> the URL and update their broadcaster field. That should be possible,
> right?

Unfortunately, I don't think it is possible to do this in a single MQL
query.  It can be done in as little as two queries (a read followed by
a write with multiple clauses).  

Consider your example above in the hypothetical case where there are
1,000,000 matches, some of which are disallowed due to permissions
problems.  Such a large query would likely timeout and give partial
errors due to the permissions.  Navigating the result clause of such a
write query could easily be a mess.  

MQL has been designed to be as expressive as required while being as
simple as possible.  Sometimes that means that some operations are
best broken into more, simpler queries rather than fewer, more complex
queries.  Keeping track of state remains easy with simpler queries.

If there is something that you cannot do, please keep asking for help.

								Kurt :-)

 


 
> -----Original Message-----
> From: developers-bounces at freebase.com
> [mailto:developers-bounces at freebase.com] On Behalf Of Kurt Bollacker
> Sent: Sunday, December 23, 2007 8:01 PM
> To: For discussions about MQL,Freebase API and apps built on Freebase
> Subject: Re: [Developers] Comparison operation in write?
> 
> 
> On Sun, Dec 23, 2007 at 06:30:50PM -0800, Arthur van Hoff wrote:
> > Here is an example: set the broadcaster for all stations that have
> > live365 in a stream URL.
> > 
> > "query":[{
> >     "type": "/user/cotton/default_domain/internet_station",
> >     "internet_streams": [{
> >         "uri~=": "*live365*",
> >         "uri":null,
> >         "type": "/user/cotton/default_domain/internet_availability"
> >     }],
> >     "/user/cotton/default_domain/broadcast/broadcaster":{
> >         "id":"/topic/en/live365",
> >         "connect":"update"
> >     }
> > }]
> 
> Before I address what I think you are asking for, let me mention that
> MQL write syntax requires that arrays of writes be explicit.  In your
> query, you are using the MQL read syntax of [{.....}] to request an
> array result.  You should be using [{...},{...},{...}] to specify an
> array read.  Also, this particular example also falls afoul of MQL
> write rules by asking for a literal value ("uri") in a write.  Could
> you give an example of the query you need that only requires
> additional comparison operators, but is otherwise legal MQL?  That
> might help me understand more clearly.
> 
> As a workaround, you can break this into a read then a write query
> without any loss of expressiveness.  If that won't work, let's try to
> figure something out that does.
> 
> 								Kurt :-)
> 
> > The result is:
> > 
> > {
> >   "status": "200 OK", 
> >   "code": "/api/status/error", 
> >   "messages": [
> >     {
> >       "info": {
> >         "mode": "write", 
> >         "key": "uri~="
> >       }, 
> >       "query": [
> >         {
> >           "/user/cotton/default_domain/broadcast/broadcaster": {
> >             "id": "/topic/en/live365", 
> >             "connect": "update"
> >           }, 
> >           "type": "/user/cotton/default_domain/internet_station", 
> >           "internet_streams": [
> >             {
> >               "type":
> > "/user/cotton/default_domain/internet_availability", 
> >               "uri~=": "*live365*", 
> >               "uri": null, 
> >               "error_inside": "."
> >             }
> >           ]
> >         }
> >       ], 
> >       "message": "Can't use comparison operators in a write, only in a
> > read", 
> >       "code": "/api/status/error/mql/parse", 
> >       "path": "internet_streams"
> >     }
> >   ]
> > }
> > 
> > -----Original Message-----
> > From: developers-bounces at freebase.com
> > [mailto:developers-bounces at freebase.com] On Behalf Of Kurt Bollacker
> > Sent: Sunday, December 23, 2007 6:22 PM
> > To: For discussions about MQL,Freebase API and apps built on Freebase
> > Subject: Re: [Developers] Comparison operation in write?
> > 
> > 
> > On Sun, Dec 23, 2007 at 05:46:46PM -0800, Arthur van Hoff wrote:
> > > Hi,
> > > 
> > >  
> > > 
> > > Why can't I use a comparison operation in a write? I need to fix a
> > bunch
> > > of objects that contain a particular hostname in a URL. I would seem
> > > reasonable to do this in a single operation.
> > 
> > Can you give an example of this?
> > 
> > 							Kurt :-)
> > 
> >  
> > >  
> > > 
> > > 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
> > _______________________________________________
> > 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
> _______________________________________________
> Developers mailing list
> Developers at freebase.com
> http://lists.freebase.com/mailman/listinfo/developers


More information about the Developers mailing list