Hi Luigi. Pardon me if it's too verbose, but here is the full picture:

// Account class
create class Account extends V
create property Account.id INTEGER (DEFAULT "sequence('accountId').next()", 
READONLY TRUE)
create property Account.created DATETIME (DEFAULT "sysdate()", READONLY 
TRUE)
create property Account.active BOOLEAN (NOTNULL TRUE, DEFAULT FALSE)
create property Account.company STRING (NOTNULL TRUE, MANDATORY TRUE, MIN 
2, MAX 50, COLLATE "ci")

// SellCampaign class
create class SellCampaign extends V
create property SellCampaign.leadCategory LINK LeadCategory (NOTNULL TRUE, 
MANDATORY TRUE)

// Subscription class
create class Subscription extends V
create property Subscription.active BOOLEAN (NOTNULL TRUE, DEFAULT false)
create property Subscription.buyer LINK Account (NOTNULL TRUE, MANDATORY 
TRUE)
create property Subscription.created DATETIME (DEFAULT "sysdate()", 
READONLY TRUE)
create property Subscription.lastDelivery DATETIME

// Add SellCampaign and connect Account to it with 'Sell' edge
insert into SellCampaign set leadCategory = (select from LeadCategory where 
id = 2)
create edge Sell from #25:0 to #149:0

// Add Subscriptions and connect SellCampaign to it with 'SellsTo' edge
insert into Subscription (buyer) values (#25:1)
create edge SellsTo from #149:0 to #159:0
create edge SellsTo from #149:0 to #157:1
create edge SellsTo from #149:0 to #157:2


At this point the graph shall be complete and will look as in the attached 
snapshot (if I didn't miss anything).

<https://lh3.googleusercontent.com/-xBnNu-xg8q8/WBDayLm6zUI/AAAAAAAAAAM/goj7LjztyKIV2DfYCdA7PLJ0R9hcrj7sgCLcB/s1600/account%2Bto%2Bsubscription%2Bgraph.png>

Now, we need to get all active buyer subscriptions starting from the 
account #25:0 for a specific SellCampaign. Query I crafter (maybe there's 
better way):

select 
    expand(out('Sell')[leadCategory contains $category.@rid] // get to 
SellCampaign for specific leadCategory
.outE('SellsTo')[active = true]                      // then, get to all 
active Subscriptions
.inV()[active = true])                               // finally, get the 
active subscription vertex
from Account 
let $category = (select from LeadCategory where id = 2)      // here is the 
sub-query (you helped in issue: 
https://groups.google.com/forum/#!topic/orient-database/HT1PbMbf21c)
where @rid = #25:0

Here is the query results from the studio:

<https://lh3.googleusercontent.com/-0pPi2ARbkn8/WBDeeqrnhRI/AAAAAAAAAAc/EoZ5-7_1kAARulUjVFNHdAtAe_1WKNHIQCLcB/s1600/get%2Bsubscriptions%2Bquery.png>


I use the expand() to get all properties of the final Subscription vertex 
and it does send all properties to the java code, but without the @rid.

Here is my Java code:

public Set<Subscription> getSubscribedBuyers(int categoryId, String 
sellerRid) {
    Set<Subscription> subscriptions = new TreeSet<>();

    try (ODatabaseDocumentTx db = DbPool.getConnection()) {
        String sql
            = " select "
            + "     expand(out('Sell')[leadCategory contains 
$category.@rid]"
            + "             .outE('SellsTo')[active = true]"
                          + "     .inV()[active = true]) "
                          + " from Account "
            + " let $category = (select from LeadCategory where id = ? 
limit 1) "
            + " where @rid = ?";
        OSQLSynchQuery<ODocument> query = new OSQLSynchQuery<>(sql);
        List<ODocument> result = db.command(query).execute(categoryId, 
sellerRid);
        if (result != null) {
            result.forEach(subscription -> {
                if (subscription != null) {
                    String[] fields = subscription.fieldNames(); // just 
for debugging to check properties

                    subscriptions.add(Json.fromJson(subscription.toJSON(), 
Subscription.class));
                }
            });
        }
    }

    return subscriptions;
}

The Set<Subscription> subscriptions is constructed, but without setting the 
rid. When I opened the data in debugger I can clearly see that "fields" 
array does not have the @rid or rid present. See below:

<https://lh3.googleusercontent.com/-_zOBMR24JZM/WBDeFV1ts7I/AAAAAAAAAAY/boQpQi9Ud84DzndLD2iZGc6qckDE5jisQCLcB/s1600/fields%2Bwithout%2Brid.png>

We need to get the @rid of the Subscription object together with all 
properties to properly construct the object in code, because after the 
successful delivery we need to update the 'lastDelivery' timestamp and 
without the exact reference to the Subscription record it'll be difficult 
to do.

Let me know if I can provide any other info.


On Tuesday, October 25, 2016 at 11:49:40 PM UTC-7, Luigi Dell'Aquila wrote:
>
> Hi,
>
> I'm not sure I got the point, could you please post a script to create a 
> DB and reproduce the problem?
> By default, the expand() function returns the full record, so that should 
> be enough for what you need.
>
> Thanks
>
> Luigi
>
> 2016-10-26 7:46 GMT+02:00 <[email protected] <javascript:>>:
>
>> Unfortunately it didn't work. 
>>
>> Also, I need to return all properties, not just @rid. And to make things 
>> more complicated this is a simple query, but the other one I have is 
>> chaining more in(), out() to get to nodes about 3 levels deep. The queries 
>> work, but the final vertex must return all properties and @rid must be 
>> there.
>>
>>
>>
>>
>> On Tuesday, October 25, 2016 at 10:37:30 PM UTC-7, Oleksandr Gubchenko 
>> wrote:
>>>
>>> Try this query:
>>>
>>> select expand(out("Sell").@rid) from Account where @rid=#25:0
>>>
>>> Hope it helps.
>>>
>>> Il giorno mercoledì 26 ottobre 2016 07:06:23 UTC+2, [email protected] 
>>> ha scritto:
>>>>
>>>> Hello, I'm running OrientDB 2.2.12 on Mac/Linux
>>>>
>>>> I'm trying to perform a simple out() lookup from a class and get all 
>>>> properties of another class. I can get all properties except @rid. I tried 
>>>> different ways, but nothing seem to work or return the @rid. How do I get 
>>>> the @rid as a property? Here is what I tried:
>>>>
>>>> My class: 
>>>>
>>>> orientdb {db=Customers}> info class SellCampaign
>>>>
>>>>
>>>> CLASS 'SellCampaign'
>>>>
>>>> Records..............: 1
>>>>
>>>> Super classes........: [V]
>>>>
>>>> Default cluster......: sellcampaign (id=149)
>>>>
>>>> Supported clusters...: sellcampaign(149), sellcampaign_1(150), 
>>>> sellcampaign_2(151), sellcampaign_3(152)
>>>>
>>>> Cluster selection....: round-robin
>>>>
>>>> Oversize.............: 0.0
>>>>
>>>>
>>>> PROPERTIES
>>>>
>>>>
>>>> +----+------------+----+-----------------+---------+--------+--------+----+----+-------+-------+
>>>>
>>>> |#   |NAME       
>>>>  |TYPE|LINKED-TYPE/CLASS|MANDATORY|READONLY|NOT-NULL|MIN |MAX 
>>>> |COLLATE|DEFAULT|
>>>>
>>>>
>>>> +----+------------+----+-----------------+---------+--------+--------+----+----+-------+-------+
>>>>
>>>> |0   |leadCategory|LINK|LeadCategory     |true     |false   |true    | 
>>>>    |    |default|       |
>>>>
>>>>
>>>> +----+------------+----+-----------------+---------+--------+--------+----+----+-------+-------+
>>>>
>>>> Here are the queries I tried:
>>>>
>>>> // returns only leadCategory property
>>>> select expand(out('Sell')) from Account where @rid = #25:0
>>>>
>>>> // returns only leadCategory property
>>>> select expand(out('Sell').include('@rid','leadCategory')) from Account 
>>>> where @rid = #25:0
>>>>
>>>> // results in error
>>>> select expand(out('Sell').include(@rid.asString(),'leadCategory')) from 
>>>> Account where @rid = #25:0
>>>>
>>>> Error on execution of command: sql.select 
>>>> expand(out('Sell').include(@rid.asString(),'leadCategory')) from Account 
>>>> where @rid = #25:0
>>>>     DB name="Customers"
>>>>     DB name="Customers"
>>>>
>>>> If I simply run a select statement with @rid.asString() it works fine: 
>>>> select @rid.asString(), leadCategory from SellCampaign
>>>>
>>>>
>>>> How do I get the @rid of the class when I traverse to it?
>>>>
>>>> Please help.
>>>>
>>>> -- 
>>
>> --- 
>> You received this message because you are subscribed to the Google Groups 
>> "OrientDB" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to [email protected] <javascript:>.
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"OrientDB" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to