query 2 vertexes orientdb - orientdb

I have 2 vertexes, Client and Campaign, linked by an edge hasClient.
Schema: Client #33 ----- hasClient #19 ----- Campaign #15
I would like to have the name of the client and also the number of edge he has with Campaign (generally more than 1).
Do you know how to query this ?
thanks !

You can use
select name,out("hasClient").size() as size from Client
Hope it helps

Related

How to find most connected child nodes in OrientDB

So I'm new to OrientDB, and while I'm pretty good at SQL the syntax to get what I want in OrientDB is escaping me.
I know I can do something like select *, in().size() as size from Users order by size desc to find the most connected node of a certain class (Users in this case), but how do I find the most connected children a couple levels down?
I.e., let's say I have Organizations --> PROMOTES (edge) --> Platform --> MANAGES (edge) --> Suggestion
How do I find the most connected Suggestions at the Organization level? I.e., I know I can easily find the most connected suggestions one level out using the query I shared, but what about the most connected another level beyond that?
I'd ultimately like a result which lists each Suggestion along with how indirectly connected (number of edges) it is to Organizations.
Thank you!
Use TRAVERSE
You should use the command TRAVERSE to do that
SELECT out(PROMOTES).size() AS connectedOrg,*
FROM (
TRAVERSE out(MANAGES)
FROM Suggestion WHILE $depth < 2
)
WHERE $depth > 0
Result will be the Platforms linked to a Suggestion. Records can be duplicated.
Along with each Platform, you get the number of Organisation called connectedOrg.
About traverse :
Traverse follow the record ids present in a record and aggregates them in the results. With WHILE $depth < 2 you can limit search to only one level and with WHERE $depth > 0 you can remove the original record from the result. More info here.
Use OrientDB Functions
If you need to know how many Organization is linked to each Suggestion (through Plateform), use this syntax.
SELECT *, set(out(MANAGES).out(PROMOTES), null).size() FROM Suggestion
Note : , null allows to switch from AGGREGATE to INLINE. It prevents from having all sizes aggregated in a single record. See the doc for more info.

How to select all nodes of a certain type connected via an Edge?

I am quite new to OrientDB, I have a Node labeled Resource, and i have other nodes labeled User and Administrator connected to it. I know I can Select all the Users who are "HasAccessTo" the Resource, like this:
SELECT in("HasAccessTo") FROM Resource
But how do I write the Query if I want to Select only those who are labeled as User and not Administrator?
Thanks for the help in advance.
Long answer:
SELECT FROM (
SELECT expand(in("HasAccessTo")) FROM Resource
) WHERE #class = "User"
Short answer:
SELECT in("HasAccessTo")[#class = "User"] FROM Resource
or (expanded)
SELECT expand(in("HasAccessTo")[#class = "User"]) FROM Resource

Titan Graph: Group by query for specific vertex

I have following situation:
User (userId,Name)
Group (groupId,groupName,createdTime)
User ------ created -------> Group1
User ------ created -------> Group2
User ------ created -------> Group3
I want to get the list of group created by user in desending order. I have this query
//g is TitanGraph
g.query().interval("createdTime",0,time).orderBy("createdTime",
Order.DESC).limit(5).vertices();
This will traverse whole graph. but i want for the specific user using userId
Means i will take userId and show all group created by that userId sorted by createdTime
One I was trying
g.query().has(`userId`,'xyz').interval("createdTime",0,time).orderBy("createdTime",
Order.DESC).limit(5).vertices();
Din't work.it was just returning nothing.
You are using a Graph Query when you want a Vertex Query:
https://github.com/thinkaurelius/titan/wiki/Vertex-Centric-Indices
Query the vertex first and then execute the query from there, like:
Vertex v = g.getVertex(userId)
v.query().has(`userId`,'xyz').interval("createdTime",0,time).orderBy("createdTime",
Order.DESC).limit(5).vertices()
I guess this is basically the answer from #MarcoCI written with Titan/Java instead of Gremlin.
What about this?
g.v(userId).outE.interval("createdTime",0,time).orderBy("createdTime", Order.DESC).limit(5);

Writing a NON-EXIST query using JPA / Criteria

I'm running an application simulates selling air plane tickets.
Using a simple schema (1-n):
SEAT
------
id_seat
description
position
BOOKING
---------
id
customer
id_seat
I'd like to produce a Query using either JPA API or Criteria which provides me a list of all available SEATs. That is, all SEAT Objects which do not exist (not booked) in the BOOKING table. (SEAT.id_seat = BOOKING.id_seat)
Can anybody give me a clue which is the best option to produce such a Query?
select seat from Seat seat
where seat.id not in (
select seat2.id from Booking booking
inner join booking.seat seat2)

Can web2py serve REST data of many-to-may tables via parse_as_rest?

I need to serve REST data about a many-to-many relationship. I've been playing with web2py's lovely parse_as_rest functionality, but can't quite get the many-to-many thing working.
As an example, let's take standard users and groups.
Tables:
user
id
user_name
group
id
group_name
membership
id
user_id
group_id
What pattern do I need to use to serve a url that will give me all group_name's that a user belongs to?
patterns = [
"/user[user]",
"/user[user]/id/{user.id}",
"/user[user]/id/{user.id}/membership[membership.user_id]",
# This is the line that I can't make yet:
#"/user[user]/id/{user.id}/membership[membership.user_id]/group<WHAT GOES HERE>",
"/group[group]",
"/group[group]/id/{group.id}",
]
parser = db.parse_as_rest(patterns, args, vars)
With the non-commented lines above, I can get to these urls:
.../user
.../user/id/1
.../user/id/1/membership
.../group
.../group/id/3
URL #3 shows me all my memberships, and I can then make several separate calls to URL #5 to get the group_name values, but there's got to be a way to do this with one call.
Help me StackOverflow! You're my only hope.
EDIT: Fixed bad cutting and pasting.
This question is in top of Google search for that topic.
Just start building query from the many-to-many table.
/user[membership]/id/{membership.user_id}/groups[group.id]
You don't really need 'user' table for this request.
Then request to "/user/id/22/groups" will give you all groups not only their IDs.