Filtering query using outE() with EmbeddedMap - orientdb

I have a vertex as below.
And I also have an edge (it is an out edge of above vertex) as below.
I can query with following SQL statements.
select from #20:6 where outE().weight in 1
select from #28:12 where sessionStatus.keys() in "session1"
However when I combined the 2 filters above, there is no vertex out from the query.
select from #20:6 where outE().sessionStatus.keys() in "session1"
Is there anyone guide me the correct filter I can use?

you can use MATCH
select expand(vv) from (
MATCH
{
class: GW_Score,
as: vv,
where: (#rid=20:6)
}
.outE(){
as: ee,
where: (sessionStatus.keys() = "session1")
}
RETURN vv
)

Try with this query:
select from #20:6 where ["session1"] in outE()[0].sessionStatus.keys()
Hope it helps.

Related

postgresql how to use boolean in where statement

I'm a really bad in sql , my query is
select * from car_wash where
(select ST_Within((select car_wash.lon_lat from car_wash),(select ST_Buffer(ST_GeomFromText('POINT(65.3 323.2)'),20)))) = true
AND car_wash.was_deleted=false;
But i know that it isn't correct because nested query can return more than 1 column, how to modify this query to use where clause
select *
from car_wash cw
where
ST_Within (
cw.lon_lat,
ST_Buffer(ST_GeomFromText('POINT(65.3 323.2)'),20)
)
AND
not car_wash.was_deleted
I don't use postgresql, but maybe something like this works:
select * from car_wash
where EXISTS (select ST_Within((select car_wash.lon_lat from car_wash),
(select ST_Buffer(ST_GeomFromText('POINT(65.3 323.2)'),20))) within
WHERE within = true)
AND car_wash.was_deleted=false;
If it doesn't work, I have a variant, so tell me when.

Querying Out from Out in OrienDB?

Looking at the following image:
I need a query that just outputs four rows as below:
A1.SomeProperty, B1.SomeProperty, C1.SomeProperty
A1.SomeProperty, B1.SomeProperty, C2.SomeProperty
A1.SomeProperty, B2.SomeProperty, C3.SomeProperty
A1.SomeProperty, B2.SomeProperty, C4.SomeProperty
I have tried the following:
SELECT
SomeProperty as A_Property
out(L1).SomeProperty as B_Property,
out(L1).out(L2).SomeProperty as C_Property
from A
UNWIND B_Property, C_Property
I can't get my head around UNWIND - I think the problem is following out(L1) and out(L2).
Getting closer thanks to Luigi.
Need to get other properties from "Result" without unwiding
SELECT
a.A_Property as ID,
b.B_Property as Name,
b.out(Link).C_Property as Result
FROM
(MATCH
{class:A, as:a} --> {optional:true, as:b}
RETURN
a,b)
UNWIND Result
If you are on v 2.2 you can use MATCH statement:
MATCH
{class:A, as:a} -L1-> {as:b} -L2-> {as:c}
RETURN
a.SomeProperty as A_Property,
b.SomeProperty as B_Property,
c.SomeProperty as C_Property
If you also need the edges:
MATCH
{class:A, as:a} .outE("L1"){as:edge1}.inV() {as:b} .outE("L2"){as:edge2}.inV() {as:c}
RETURN
a.SomeProperty as A_Property,
b.SomeProperty as B_Property,
c.SomeProperty as C_Property,
edge1.something as xxx,
edge2.something as yyy

How to correctly use the querybuilder in order to do a subselect?

I would like to do a subselect in order to do the following postgresql query with the querybuilder:
SELECT i.* FROM internship i
WHERE EXISTS (SELECT iw.*
FROM internship_weeks iw
WHERE i.id = iw.internship)
Does anyone have an idea how to get the same result with queryBuilder? or maybe with DQL?
Thanks for the help !
As example, only for demonstrate HOW-TO use a subquery select statement inside a select statement, suppose we what to find all user that not yet have compile the address (no records exists in the address table):
// get an ExpressionBuilder instance, so that you
$expr = $this->_em->getExpressionBuilder();
// create a subquery
$sub = $this->_em->createQueryBuilder()
->select('iw')
->from(IntershipWeek::class, 'iw')
->where('i.id = iw.intership');
$qb = $this->_em->createQueryBuilder()
->select('i')
->from(Intership::class, 'u')
->where($expr->exists($sub->getDQL()));
return $qb->getQuery()->getResult();
Hope this help

Making a copy of record without edges

Is there a way to make a copy of an arbitrary OrientDB record without its edges? I modified an original command (from the docs) for copying records and added fetchplan to it, but it does not work (frankly speaking to me it looks like there's a problem parsing this particular command, but hopefully im wrong)
This one executes fine, but edges remain:
insert into Test from select from Test where #rid=#102:119 fetchplan in_*:-2 out_*:-2
This one gives an error:
insert into Test from (select from Test where #rid=#102:119 fetchplan in_*:-2 out_*:-2)
com.orientechnologies.orient.core.command.OCommandExecutorNotFoundException: Cannot find a command executor for the command request: sql.(SELECT FROM Test WHERE #rid = #102:119 FETCHPLAN in_*:-2 out_*:-2)
also tried smth like
insert into Test content (select #this.toJSON('fetchPlan:in_*:-2 out_*:-2') from Test where #rid=#102:119)
but that doesn't work either. Any thoughts? I'm on Orient 2.1.x
As workaround you can use this javascript function with one parameter (id)
var g=orient.getGraph();
var b=g.command("sql","select #this.toJSON('fetchPlan:in_*:-2 out_*:-2') as json from "+ id);
if(b.length>0){
var query="insert into Test content " + b[0].getProperty("json") ;
var myVertex=g.command("sql",query);
g.commit();
return myVertex;
}
Using the following command
select expand(result) from (select yourFunction(#102:119) as result)
Here's how to select all vertices (V) that have no incoming or outgoing edges:
select from (select #this, bothE().size() as n from V) where n = 0
I tried your query and I have the same problem.
I solved it in this way:
insert into Test from select <property-name> from Test where #rid=#102:119
If you want use it with fatchplan try this:
insert into Test from select <property-name> from Test where #rid=#102:119 fetchplan in_*:-2 out_*:-2
Hope it helps.
Regards,
Michela

Laravel 5, Derived table in join clause?

I have this query:
SELECT * FROM blog
LEFT JOIN (
SELECT blog_id, AVG(value) as blog_rating FROM blog_ratings
GROUP BY (blog_id)
) T ON T.blog_id = blog.id;
I do not know how to write this with Eloquent.
For Example:
Blog::select("*")->leftJoin( /* Here goes derived table */ )->get()
How do I accomplish this?
I'd personally just use the fluent query builder, try this out and see how it works out:
DB::table('blog')
->select('*')
->leftJoin(DB::raw('(SELECT blog_id, AVG(value) as blog_rating FROM blog_ratings
GROUP BY (blog_id)
) as T'), function ($join) {
$join->on ( 'T.blog_id', '=', 'blog.id' );
})
->get();
You can always swap ->get() for ->toSql() to dump out the query and adjust if you see any mistakes.