is there a way to return Record from Function ?

68 views
Skip to first unread message

Payne Chu

unread,
Apr 23, 2014, 9:57:13 PM4/23/14
to orient-...@googlegroups.com
I created a function below, and executed through Functions page, Browse page and Binary Protocol. they return differently.
What I expect the return should always like Functions page. But Browse page and Binary Protocol only return Record Id.
Any way can return Record from Function ?
function test() {
   
return db.query("select from V where @rid=#9:1")
}



EXECUTED through Functions page
[{"@type":"d","@rid":"#9:1","@version":25,"@class":"V","name":"HEY BO DIDDLEY","song_type":"cover","performances":5,"type":"song","out_followed_by":["#11:0","#11:1","#11:2","#11:3","#11:4"],"out_written_by":"#9:7","out_sung_by":"#9:8","in_followed_by":["#11:10","#11:150","#11:2578","#11:5574"],"@fieldTypes":"out_followed_by=g,in_followed_by=g"}]



EXECUTED through Browse page
SELECT test()
returned
{
   
"result": [
       
{
           
"@type": "d",
           
"@rid": "#-2:0",
           
"@version": 0,
           
"test": [
               
1
           
]
       
}
   
],
   
"notification": "Query executed in 0.023 sec. Returned 1 record(s)"
}



EXECUTED through Binary Protocol
p.Exec(SyncQuery(dbSid, "SELECT test()", -1, "", nil, nil, nil))
server log
2014-04-24 09:47:02:355 INFO /127.0.0.1:49697 - Reading byte (1 byte)... [OChannelBinaryServer]
2014-04-24 09:47:02:356 INFO /127.0.0.1:49697 - Read byte: 41 [OChannelBinaryServer]
2014-04-24 09:47:02:356 INFO /127.0.0.1:49697 - Reading int (4 bytes)... [OChannelBinaryServer]
2014-04-24 09:47:02:356 INFO /127.0.0.1:49697 - Read int: 5 [OChannelBinaryServer]
2014-04-24 09:47:02:357 INFO /127.0.0.1:49697 - Reading byte (1 byte)... [OChannelBinaryServer]
2014-04-24 09:47:02:357 INFO /127.0.0.1:49697 - Read byte: 115 [OChannelBinaryServer]
2014-04-24 09:47:02:359 INFO /127.0.0.1:49697 - Reading chunk of bytes. Reading chunk length as int (4 bytes)... [OChannelBinaryServer]
2014-04-24 09:47:02:359 INFO /127.0.0.1:49697 - Read chunk lenght: 42 [OChannelBinaryServer]
2014-04-24 09:47:02:359 INFO /127.0.0.1:49697 - Reading 42 bytes... [OChannelBinaryServer]
SELECT test()�������� [OChannelBinaryServer]7 - Read 42 bytes: q
2014-04-24 09:47:02:413 INFO /127.0.0.1:49697 - Writing byte (1 byte): 0 [OChannelBinaryServer]
2014-04-24 09:47:02:414 INFO /127.0.0.1:49697 - Writing int (4 bytes): 5 [OChannelBinaryServer]
2014-04-24 09:47:02:414 INFO /127.0.0.1:49697 - Writing byte (1 byte): 108 [OChannelBinaryServer]
2014-04-24 09:47:02:414 INFO /127.0.0.1:49697 - Writing int (4 bytes): 1 [OChannelBinaryServer]
2014-04-24 09:47:02:416 INFO /127.0.0.1:49697 - Writing short (2 bytes): 0 [OChannelBinaryServer]
2014-04-24 09:47:02:416 INFO /127.0.0.1:49697 - Writing byte (1 byte): 100 [OChannelBinaryServer]
2014-04-24 09:47:02:416 INFO /127.0.0.1:49697 - Writing short (2 bytes): -2 [OChannelBinaryServer]
2014-04-24 09:47:02:416 INFO /127.0.0.1:49697 - Writing cluster position (8 bytes) : 0.... [OChannelBinaryServer]
2014-04-24 09:47:02:417 INFO /127.0.0.1:49697 - Writing int (4 bytes): 0 [OChannelBinaryServer]
2014-04-24 09:47:02:419 INFO /127.0.0.1:49697 - Writing bytes (4+11=15 bytes): [116, 101, 115, 116, 58, 91, 35, 57, 58, 49, 93] [OChannelBinaryServer]
2014-04-24 09:47:02:419 INFO /127.0.0.1:49697 - Writing byte (1 byte): 0 [OChannelBinaryServer]
deserialized record
&Record{
 
Type:0x64,
 
Rid:RecordId{cluster:-2, position:0},
 
Version:0,
 
Content:{
   
"@type":100,
   
"test":[
     
{cluster:9, position:1}
   
]
 
}
}



Artem Orobets

unread,
Apr 24, 2014, 3:42:52 PM4/24/14
to orient-...@googlegroups.com
Try:
SELECT expand(test())

It should return the same result.

The issue there is that function return a collection of records, so when query is executed it creates a wrapper document where insert this collection. That's why you see "[1]" (collection with 1 element) instead of the expected record.

Best regards,
Artem Orobets

Orient Technologies

the Company behind OrientDB



--

---
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 orient-databa...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Payne Chu

unread,
Apr 24, 2014, 9:31:43 PM4/24/14
to orient-...@googlegroups.com

Thanks Artem,
I tried,
SELECT expand(test())
SELECT expand('test') FROM (SELECT test())
traverse test from (SELECT test())
But all return nothing.


Artem Orobets

unread,
Apr 25, 2014, 6:40:43 AM4/25/14
to orient-...@googlegroups.com
That is strange. Could you create a ticket?

Best regards,
Artem Orobets

Orient Technologies

the Company behind OrientDB



Payne Chu

unread,
Apr 25, 2014, 7:57:22 AM4/25/14
to orient-...@googlegroups.com

Payne Chu

unread,
Apr 25, 2014, 8:03:29 AM4/25/14
to orient-...@googlegroups.com
But Artem,

I think this issue just same as
https://github.com/orientechnologies/orientdb/issues/2264

I still suggest instead of return a fake record always. may should just return that object (scalar, string or record) directly without need the fake record.
Reply all
Reply to author
Forward
0 new messages