On Wed, May 23, 2012 at 6:46 AM, Huseyn Guliyev <
hus...@gmail.com> wrote:
> Both of these features will be really cool to have in Objectify.
>
> 1) Question re: Embedded entity. I thought we already have embedding in OFY.
> How is the native one different/better?
In nearly all respects, the EmbeddedEntity approach is far superior.
It will go through the normal load/save code path, so you get
polymorphism, infinitely nested collections, lifecycle methods, etc.
Objectify will support both approaches, but I am going to strongly
encourage people to prefer EmbeddedEntity.
The difference between current @Embed and the EmbeddedEntity (haven't
figured out the relevant annotations yet) are the same as the
difference between NDB's StructuredProperty and
LocalStructuredProperty. In fact, they should be binary-compatible in
the datastore. For example, let's say you have these two classes:
class Address { String city; String state; }
class Location {
@Id Long id;
String name;
Address addy;
}
The current @Embed approach will put something in the datastore with
properties like this:
name = "Here"
addy.city = "San Francisco"
addy.state = "CA"
The embedded entity approach puts something in the datastore that
looks like this:
name = "here"
addy = {
city = "San Francisco"
state = "CA"
}
The downsides of the embedded entity approach are:
* Indexes are not currently supported by the datastore. They might
not be natively supported by the datastore ever. Guido and I have
been discussing how to create a standardized set of synthetic index
properties such that Objectify and NDB are binary-compatible with
datastore contents (ie, you can use Python/NDB instances and
Java/Objectify instances against the same dataset).
* The datastore viewer treats these embedded entity structures as
opaque. Or at least, it did the last time I checked. This will
certainly change at some point as the embedded entity is part of the
"standard" set of datastore values.
There needs to be some significant discussion about how the
annotations surrounding this feature will work. I'm not entirely
certain that @Embed should refer to the 'old' embedding system. I'm
not quite ready to open up this discussion yet - but it will be soon,
because I really need this feature in Voost.
> 2) As for projection queries, it is going to be really useful for those who
> want to get more performance/pay less on big queries. If you have big
> entities with dozens of fields (almost all real apps do), each time you have
> to pull all of the data, even if you want a specific property. This costs us
> a lot of $$, for instance. Being able to specify property name would
> therefore be very useful.
>
> Here is what they say in GAE documentation:
> Most Datastore queries return an entire entity object, but some queries only
> seek a few properties within an entity. You can query the Datastore for
> specific properties of an entity using projection queries. These queries
> provide lower latency and cost (like keys-only queries), but also let you
> return only the properties you need.
>
https://developers.google.com/appengine/docs/python/datastore/queries#Query_Projection
Yes, but keep in mind that Projection Queries are not quite like SQL
select statements, and the reason they are "cheap" is not strictly
because they return less data. It's because they are purely
index-walks just like keys-only queries. This imposes some severe
limitations.
Remember that a normal query walks an index BigTable, getting keys,
then issues separate fetches to the data BigTable to get the full data
blob for each one of those keys. Google charges you a read operation
for each value returned (plus an extra read op for the whole query).
A keys-only query skips the fetch to the data BigTable since you have
the key in the index. Google charges you a small op for each value
returned (plus an extra read op for the whole query).
Projection queries recognize that you can return the data in the index
BigTable without needing the extra fetch to the data BigTable. This
means you are only walking the index, doing the equivalent of a
keys-only query. Thus each row returned costs the same as a keys-only
query - a small op.
The downside of this is that you must create and update an appropriate
multi-property index, and you can ONLY select values that are in that
index. Given that you must also have single-property indexes for each
element of a multi-property index, this could easily require a dozen
extra write operations to maintain the projection index. Depending on
the read-to-update ratio of your data, this could potentially cost you
more than simply using a cached hybrid query or even a simple naive
query.
My point is that this is a very specialized tool and really should
only be used for optimizing very particular cases... and only when you
really know what you're doing.
All that said, yes, Objectify will support projection queries.
Jeff