embedded list and contains and containsall

71 views
Skip to first unread message

Mihai Ocneanu

unread,
Nov 26, 2015, 6:39:53 AM11/26/15
to orient-...@googlegroups.com
Hello,

I have a query that don't exactly manage to get right:

A class contains a property with: 
type - embedded list
linked type  - integer.

something like V_Foo { years: [2014, 2015,2016] }

a { years: [2014] }
b { years: [2014, 2015] }
c { years: [2014, 2015, 2016] }

I wish to do a select where all the years I get as parameters are inside my embedded list:

like
select from V_Foo where years contains all [2015] -> b,c
select from V_Foo where years contains all [2014, 2015] -> b,c
select from V_Foo where years contains all [2014, 2015, 2016] -> c

the command containsall, apparently, isn't what I'm looking for.
the command contains used as 'contains [2014, 2015]' doesn't give me anything
the command contains used as 'contains 2014' works, but I want multiple values
the command 'where fiscalYears in  [2014,2015,2016]' gives me ALL the results and I want just c

I don't want to use AND* because I have a variable no. of parameters. *( like 'years contains 2014 and years contains 2015' )

Any ideas?

Thanks,
Mihai

alessand...@gmail.com

unread,
Nov 26, 2015, 8:42:50 AM11/26/15
to OrientDB
Hi, try to create a javascript function  
Example : my Function with parameter myClass, property and value

var g=orient.getGraph();
var myList=[];
var values=value.substring(1,value.length-1).split(",");
var verteces=g.command("sql","select from "+ myClass);
for(i=0;i<verteces.length;i++){
var val=verteces[i].getProperty(property);
 
var found=false;
 
for(h=0;h<values.length;h++){
    found
=false;
   
for(j=0;j<val.length;j++){
       
if(val[j]==values[h]){
        found
=true;
         
break;
   
}
 
}
     
if(found==false){
     
break;
   
}
 
}
 
if(found==true){
  myList
.push(verteces[i]);
 
}
}
return myList;

and use this command

select expand(result) from ( select myFunction("V_FOO","years",[2014,2015]) as result)




Reply all
Reply to author
Forward
0 new messages