You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@cayenne.apache.org by Hugi Thordarson <hu...@karlmenn.is> on 2014/10/31 11:14:12 UTC

Traversing relationships in DataRow queries?

Hi all.

Once again, I’m looking into migrating to Cayenne from EOF :). One question though: Our code depends heavily on raw row fetching (data rows) that traverses relationships. I haven’t looked much at the Cayenne code, but do you believe adding support for this to Cayenne would be a huge undertaking? Or does Cayenne perhaps provide an alternative method to achieve the same results?

Cheers,
- hugi

PS: My apologies for the previous post, which my brain for some reason decided to post as an answer to an older thread. I’m still on my first cup of coffee, and it’s a really Monday-ish Friday up here.

// Hugi Thordarson
// http://www.loftfar.is/ <http://www.loftfar.is/>
// s. 895-6688

Re: Traversing relationships in DataRow queries?

Posted by Hugi Thordarson <hu...@karlmenn.is>.
>> While this doesn’t:
>> 
>> SelectQuery<DataRow> q = SelectQuery.dataRowQuery( SMReceipt.class );
>> q.addPrefetch( SMReceipt.SHOP.getName() );
>> List<DataRow> list = objectContext.select( q );
>> 
>> Should I file a bug report?
> 
> Very surprising. This should generate a "disjoint" prefetch (i.e. a query #2, fetching Shop objects). And I am certain that we have dozens of unit tests for it. But yeah, if it is broken, please open a Jira, including generated SQL if possible.

I was ablet o reproduce this in a different relationship so I filed an issue: https://issues.apache.org/jira/browse/CAY-1996 <https://issues.apache.org/jira/browse/CAY-1996> .


> BTW, feel free to use ObjectSelect query, which a "fluent" analog of SelectQuery in M2.

Ah, very nice!

- hugi

Re: Traversing relationships in DataRow queries?

Posted by Andrus Adamchik <an...@objectstyle.org>.
> On Apr 1, 2015, at 2:59 PM, Hugi Thordarson <hu...@karlmenn.is> wrote:
> 
> While this doesn’t:
> 
> SelectQuery<DataRow> q = SelectQuery.dataRowQuery( SMReceipt.class );
> q.addPrefetch( SMReceipt.SHOP.getName() );
> List<DataRow> list = objectContext.select( q );
> 
> Should I file a bug report?

Very surprising. This should generate a "disjoint" prefetch (i.e. a query #2, fetching Shop objects). And I am certain that we have dozens of unit tests for it. But yeah, if it is broken, please open a Jira, including generated SQL if possible.

BTW, feel free to use ObjectSelect query, which a "fluent" analog of SelectQuery in M2.

Andrus

Re: Traversing relationships in DataRow queries?

Posted by Hugi Thordarson <hu...@karlmenn.is>.
>> 1) When fetching data rows, can I limit the set of fields fetched, i.e. is there an equivalent to EOF’s EOFetchSpecification.setRawRowKeyPaths( NSArray )?
> 
> Not right now. This is doable with EJBQLQuery (it allows to specify individual columns, aggregate functions, etc). This functionality is coming soon to SelectQuery/ObjectSelect (probably in M3).

Great! We use EOF a lot for reporting so this will be really helpful performance/memory wise.

> 
>> 2) When specifying the prefetch, why do I have to addPrefetch( A.SOME_REL.joint() ) instead of just doing addPrefetch( “someRel” )? 
> 
> You can still use the String. A.SOME_REL form is an alternative that gives you a compile-time guarantee that your property name is valid .

Hmm, doesn’t seem to work. This code performs the expected prefetch:

 SelectQuery<DataRow> q = SelectQuery.dataRowQuery( SMReceipt.class );
 q.addPrefetch( SMReceipt.SHOP.joint() );
 List<DataRow> list = objectContext.select( q );

While this doesn’t:

 SelectQuery<DataRow> q = SelectQuery.dataRowQuery( SMReceipt.class );
 q.addPrefetch( SMReceipt.SHOP.getName() );
 List<DataRow> list = objectContext.select( q );

Should I file a bug report?


>> When traversing further relationships, is this the correct way? :
>> 
>> q.addPrefetch( PrefetchTreeNode.withPath( "shop.chain", 1 ) );
> 
> q.addPrefetch( A.SHOP.dot(Shop.CHAIN).disjoint()) is probably a cleaner way. 

Thanks,
- hugi

Re: Traversing relationships in DataRow queries?

Posted by Andrus Adamchik <an...@objectstyle.org>.
> 1) When fetching data rows, can I limit the set of fields fetched, i.e. is there an equivalent to EOF’s EOFetchSpecification.setRawRowKeyPaths( NSArray )?

Not right now. This is doable with EJBQLQuery (it allows to specify individual columns, aggregate functions, etc). This functionality is coming soon to SelectQuery/ObjectSelect (probably in M3).

> 2) When specifying the prefetch, why do I have to addPrefetch( A.SOME_REL.joint() ) instead of just doing addPrefetch( “someRel” )? 

You can still use the String. A.SOME_REL form is an alternative that gives you a compile-time guarantee that your property name is valid .

> When traversing further relationships, is this the correct way? :
> 
> q.addPrefetch( PrefetchTreeNode.withPath( "shop.chain", 1 ) );

q.addPrefetch( A.SHOP.dot(Shop.CHAIN).disjoint()) is probably a cleaner way. 

Andrus


> On Apr 1, 2015, at 1:38 PM, Hugi Thordarson <hu...@karlmenn.is> wrote:
> 
> This is perfect, thank you :). Couple of additional questions though:
> 
> 1) When fetching data rows, can I limit the set of fields fetched, i.e. is there an equivalent to EOF’s EOFetchSpecification.setRawRowKeyPaths( NSArray )?
> 
> 2) When specifying the prefetch, why do I have to addPrefetch( A.SOME_REL.joint() ) instead of just doing addPrefetch( “someRel” )? When traversing further relationships, is this the correct way? :
> 
> q.addPrefetch( PrefetchTreeNode.withPath( "shop.chain", 1 ) );
> 
> Cheers,
> - hugi
> 
> // Hugi Thordarson
> // http://www.loftfar.is/ <http://www.loftfar.is/>
> // s. 895-6688
> 
> 
> 
>> On 31. okt. 2014, at 10:34, Andrus Adamchik <an...@objectstyle.org> wrote:
>> 
>> If I understand the task correctly, a combination of JOINT prefetching and "data rows" should probably do the trick:
>> 
>> SelectQuery<A> query = new SelectQuery<>(A.class);
>> query.addPrefetch(A.SOME_REL.joint());
>> query.setFetchingDataRows(true);
>> 
>> Andrus
>> 
>>> On Oct 31, 2014, at 1:14 PM, Hugi Thordarson <hu...@karlmenn.is> wrote:
>>> 
>>> Hi all.
>>> 
>>> Once again, I’m looking into migrating to Cayenne from EOF :). One question though: Our code depends heavily on raw row fetching (data rows) that traverses relationships. I haven’t looked much at the Cayenne code, but do you believe adding support for this to Cayenne would be a huge undertaking? Or does Cayenne perhaps provide an alternative method to achieve the same results?
>>> 
>>> Cheers,
>>> - hugi
>>> 
>>> PS: My apologies for the previous post, which my brain for some reason decided to post as an answer to an older thread. I’m still on my first cup of coffee, and it’s a really Monday-ish Friday up here.
>>> 
>>> // Hugi Thordarson
>>> // http://www.loftfar.is/ <http://www.loftfar.is/>
>>> // s. 895-6688
>> 
> 


Re: Traversing relationships in DataRow queries?

Posted by Hugi Thordarson <hu...@karlmenn.is>.
This is perfect, thank you :). Couple of additional questions though:

1) When fetching data rows, can I limit the set of fields fetched, i.e. is there an equivalent to EOF’s EOFetchSpecification.setRawRowKeyPaths( NSArray )?

2) When specifying the prefetch, why do I have to addPrefetch( A.SOME_REL.joint() ) instead of just doing addPrefetch( “someRel” )? When traversing further relationships, is this the correct way? :

q.addPrefetch( PrefetchTreeNode.withPath( "shop.chain", 1 ) );

Cheers,
- hugi

// Hugi Thordarson
// http://www.loftfar.is/ <http://www.loftfar.is/>
// s. 895-6688



> On 31. okt. 2014, at 10:34, Andrus Adamchik <an...@objectstyle.org> wrote:
> 
> If I understand the task correctly, a combination of JOINT prefetching and "data rows" should probably do the trick:
> 
>  SelectQuery<A> query = new SelectQuery<>(A.class);
>  query.addPrefetch(A.SOME_REL.joint());
>  query.setFetchingDataRows(true);
> 
> Andrus
> 
>> On Oct 31, 2014, at 1:14 PM, Hugi Thordarson <hu...@karlmenn.is> wrote:
>> 
>> Hi all.
>> 
>> Once again, I’m looking into migrating to Cayenne from EOF :). One question though: Our code depends heavily on raw row fetching (data rows) that traverses relationships. I haven’t looked much at the Cayenne code, but do you believe adding support for this to Cayenne would be a huge undertaking? Or does Cayenne perhaps provide an alternative method to achieve the same results?
>> 
>> Cheers,
>> - hugi
>> 
>> PS: My apologies for the previous post, which my brain for some reason decided to post as an answer to an older thread. I’m still on my first cup of coffee, and it’s a really Monday-ish Friday up here.
>> 
>> // Hugi Thordarson
>> // http://www.loftfar.is/ <http://www.loftfar.is/>
>> // s. 895-6688
> 


Re: Traversing relationships in DataRow queries?

Posted by Andrus Adamchik <an...@objectstyle.org>.
If I understand the task correctly, a combination of JOINT prefetching and "data rows" should probably do the trick:

  SelectQuery<A> query = new SelectQuery<>(A.class);
  query.addPrefetch(A.SOME_REL.joint());
  query.setFetchingDataRows(true);

Andrus

> On Oct 31, 2014, at 1:14 PM, Hugi Thordarson <hu...@karlmenn.is> wrote:
> 
> Hi all.
> 
> Once again, I’m looking into migrating to Cayenne from EOF :). One question though: Our code depends heavily on raw row fetching (data rows) that traverses relationships. I haven’t looked much at the Cayenne code, but do you believe adding support for this to Cayenne would be a huge undertaking? Or does Cayenne perhaps provide an alternative method to achieve the same results?
> 
> Cheers,
> - hugi
> 
> PS: My apologies for the previous post, which my brain for some reason decided to post as an answer to an older thread. I’m still on my first cup of coffee, and it’s a really Monday-ish Friday up here.
> 
> // Hugi Thordarson
> // http://www.loftfar.is/ <http://www.loftfar.is/>
> // s. 895-6688