First() function makes query result be 1 record long

76 views
Skip to first unread message

syshex

unread,
Jan 16, 2015, 7:01:24 AM1/16/15
to orient-...@googlegroups.com
I was doing some tests on a query I've got and noticed something that seemed odd, or maybe I'm doing something wrong and completely missed the point of function first();

I went into  2.0 RC1 and RC2 on Linux and made a few tests, and whenever I use the  first()  function on a query the results that I get back are just 1 record long. 

I though that first() work simply operate on a set and return the first item of a set , like for example :    first( ["AAA","BBB", "CCC"] )  would return  "AAA"  for that particular record in a result that has many other records. 

Example :

select
 itemid
,
 
out("somethingelse").description
from (
 
select expand(in("something"))
 
from Company where something="blah"
  limit
-1
)
limit
-1


With this query I get a multi record result, where the  out("somethingelse").description   is a  set of items that always have just one item,  like  ["AAA"] . 

Since I dont want an array to be returned , specially since it will always be 1 item long I wrote the next query  : 

select
 itemid
,
 first
( out("somethingelse").description )
from (
 
select expand(in("something"))
 
from Company where something="blah"
  limit
-1
)
limit
-1


With it I now get :
  • a resultset of 1 record long, which is clearly something I dont want, I want all the results I was getting before  
  • first( out("somethingelse")) returning now  "AAA" i, which I want

Maybe I'm seeing this all wrong and first()  function makes the result set be always just one record long , the first one ,  but I though that first()  only operated on the set provided as an argument,

Thanks


Marcel Pitch

unread,
Jan 16, 2015, 8:15:12 AM1/16/15
to orient-...@googlegroups.com
Hi,

Did you try this syntax ?

select
 itemid
,
 
out("somethingelse")[0].description

syshex

unread,
Jan 16, 2015, 8:46:34 AM1/16/15
to orient-...@googlegroups.com
I haven't but will give it a go. I didn't know that syntax .... sorry. 

Still, regarding the  first()  function,  is that what it is supposed to be doing on my query? 

Marcel Pitch

unread,
Jan 16, 2015, 9:34:51 AM1/16/15
to orient-...@googlegroups.com
In my first queries, I've encountered the same problem. That's why I use now the '[0]' code.

But I was just reading the OrientDB Functions documentation.

And I saw that : 

"In case you need to use a function as inline when you've only one parameter, then add a second one like "null":


SELECT first( out('friends').name, null ) as firstFriend FROM Profiles


In this case first() function doesn't aggregate everything in only one record, but returns one record per Profile where the firstFriend is the first item of the collection received as parameter."


Maybe you could try it ?

syshex

unread,
Jan 16, 2015, 2:09:17 PM1/16/15
to orient-...@googlegroups.com
Hi Marcel

The [0] notation works  like you said 

The other try, with the null being passed as an argument fails with an exception :

com.orientechnologies.orient.core.exception.OCommandExecutionException: Syntax error: function 'first' needs 1 argument(s) while has been received 2

apparently  first only accepts one argument. 

the [x]  notation will do for now. It just surprised me to see first() behaving like that. 

Thanks so much for your help

Luca Garulli

unread,
Jan 16, 2015, 6:20:28 PM1/16/15
to orient-database
Hi guys,
I think you are right: first shouldn't return one record at all, but rather return the first element in a multi-value (array, list, set, map).

Please could you open a new issue for that?

Lvc@


--

---
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.

Rui Pereira

unread,
Jan 17, 2015, 7:32:21 AM1/17/15
to orient-...@googlegroups.com
Sure, will do that.

--

---
You received this message because you are subscribed to a topic in the Google Groups "OrientDB" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/orient-database/fbZEimTyJjM/unsubscribe.
To unsubscribe from this group and all its topics, send an email to orient-databa...@googlegroups.com.

syshex

unread,
Jan 17, 2015, 7:39:32 AM1/17/15
to orient-...@googlegroups.com
https://github.com/orientechnologies/orientdb/issues/3416


On Saturday, January 17, 2015 at 12:32:21 PM UTC, syshex wrote:
Sure, will do that.

On 16 January 2015 at 23:20, Luca Garulli   wrote:
Hi guys,
I think you are right: first shouldn't return one record at all, but rather return the first element in a multi-value (array, list, set, map).

Please could you open a new issue for that?

Lvc@

On 16 January 2015 at 20:09, syshex   wrote:
Hi Marcel

The [0] notation works  like you said 

The other try, with the null being passed as an argument fails with an exception :

com.orientechnologies.orient.core.exception.OCommandExecutionException: Syntax error: function 'first' needs 1 argument(s) while has been received 2

apparently  first only accepts one argument. 

the [x]  notation will do for now. It just surprised me to see first() behaving like that. 

Thanks so much for your help


On Friday, January 16, 2015 at 2:34:51 PM UTC, Marcel Pitch wrote:
In my first queries, I've encountered the same problem. That's why I use now the '[0]' code.

But I was just reading the OrientDB Functions documentation.

And I saw that : 

"In case you need to use a function as inline when you've only one parameter, then add a second one like "null":


SELECT first( out('friends').name, null ) as firstFriend FROM Profiles


In this case first() function doesn't aggregate everything in only one record, but returns one record per Profile where the firstFriend is the first item of the collection received as parameter."


Maybe you could try it ?

--

---
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-database+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--

---
You received this message because you are subscribed to a topic in the Google Groups "OrientDB" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/orient-database/fbZEimTyJjM/unsubscribe.
To unsubscribe from this group and all its topics, send an email to orient-database+unsubscribe@googlegroups.com.

Luca Garulli

unread,
Jan 17, 2015, 10:17:44 AM1/17/15
to orient-database
Fixed thanks. Both first() and last() functions works in non-aggregate mode.

Lvc@


To unsubscribe from this group and stop receiving emails from it, send an email to orient-databa...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages