My Current Query:
SELECT *, in('Provides').include('id') as provider FROM #12:1
This gives the full record of #12:1 plus one more property provider (as expected).
However, provider contains:
[{"#type":"d","#version":0,"id":"providerId"}]
I would like it to contain:
"providerId"
to not have to "clean up" the property, is it possible?
Background (if my approach is wrong)
I have 2 vertices connected by a 'Provides' edge.
V1 ----Provides----> V2
I want to query for whole V1 but add V2's id property as provider.
I create this schema to try your case:
try this query:
SELECT *, in('Provides').id[id] as provider FROM #12:1
this is the output:
if you don't like seeing the 'providerId' between brackets you can use unwind:
SELECT *, in('Provides').id[id] as provider FROM #12:1 unwind provider
Hope it helps.
Related
I have the following query using the Invantive Query Tool connecting to NMBRS.
select e.number
, es.EmployeeId
, e.displayname
, es.ParttimePercentage
, es.startdate
from Nmbrs.Employees.EmployeeSchedules es
left
outer
join Nmbrs.Employees.Employees e
on es.EmployeeId = e.id
order
by e.displayname
, es.startdate
(I want to retrieve all mutations in part-time percentage/schedule)
However Nmbrs.Employees.Employees only shows active employees. And I need that because that shows the employee ID as shown in Nmbrs.Employees.EmployeeSchedules is not the employee ID shown in the UI rather it is an internal ID.
I did notice Nmbrs.Employees.Employees has an additional where clause (as per documentation):
Additional Where Clause:
- CompanyId
- active
The following query
select * from Nmbrs.Employees.Employees where active = 1
gives an error:
Unknown identifier 'active'.
Consider one of the following: Nmbrs.Employees.Employees.PartitionID, Nmbrs.Employees.Employees.Id, Nmbrs.Employees.Employees.Number, Nmbrs.Employees.Employees.DisplayName, Employees.Employees.PartitionID, Employees.PartitionID, PartitionID, Employees.Employees.Id.
Active isn't mentioned so I don't know if that is usable.
active is a server-side filter on Nmbrs.nl. It defaults to the value "active". Don't ask me why they choose to have an API reflect the user interface; it is weird, but it is the way it is.
To retrieve all employees from one or more companies (partitions), use:
use all
select * from employeesall
OR
select * from employeesinactive
These are recent additions to the Nmbrs.nl API tables supported.
Note that the output does NOT contain whether an employee is active. When you need that too, please use a view or:
select 'active' type
, t.*
from nmbrs..employeesactive t
union all
select 'inactive' type
, t.*
from nmbrs..employeesinactive t
I have a unique constraint on edge:
CREATE CLASS hasAssignee extends E
CREATE PROPERTY hasAssignee.out LINK Assignable
CREATE PROPERTY hasAssignee.in LINK User
CREATE INDEX UniqueHasAssignee ON hasAssignee(out,in) UNIQUE
I want to multiple create edges if they don't yet exist in one query. If they do exist, then either replace them, or simply don't add them. Something like that, but without possibility of errors:
CREATE EDGE hasAssignee FROM ( SELECT FROM Project WHERE id=:id ) TO ( SELECT FROM User WHERE login in :login )
UPSERT from what I've noticed can deal with only one edge at a time (at least I couldn't produce query parsable by studio)
I see a few possibe solutions (but I don't see anything like it in docs):
something like CREATE IFNOTEXISTS
Soft indexes, that don't throw an error, simply don't create additional edges
Remove unique index, create duplicates, and somehow remove duplicates after each query (?)
Is it possible to do something like that in orientdb? Should I fill out a request?
There is an open feature request for this:
https://github.com/orientechnologies/orientdb/issues/4436
My suggestion is to vote on it
I have not figure it out yet, how to retrieve the #rid value from the record metadata using python 3.5 with pyorient client.command to run such SQL query.
Let's said that I have created a User class using the following query in the client.command(query) of pyorient. For simplicity only the queries calls will be shown here:
CREATE User EXTENDS V
CREATE PROPERTY User.name IF NOT EXISTS STRING (MANDATORY TRUE, NOTNULL TRUE)
CREATE INDEX User.name ON User (name) UNIQUE
Let's create a dictionary to hold the pointers of recent created vertex
rec = {}
Now we add some vertex:
rec['Cleo'] = CREATE VERTEX User CLUSTER User CONTENT {'name': 'Cleopatra'}
rec['Alex'] = CREATE VERTEX User CLUSTER User CONTENT {'name': 'Alex'}
Let's see the value of rec['Alex']:
rec['Alex']
[<pyorient.otypes.OrientRecord at 0x7fc39cd69c50>]
Let's said that, we want to know the #rid for Alex, so we can later on use it to create Edges among other classes.
If I run a quety using orientdb studio I can see the #rid:
but, if I run the same query using client.command I get the a list with the two record pointers. So it is the same as having the result from rec['Alex']
so, if I do rec['Alex'][0].oRecordData to get the record data, I only get back:
{'name': 'Alex'}
(1) How can I store the rid in a variable when I create a new vertex?
(2) How can I retrieve the rid for a record when you know, let's said the property name ?
With the python driver you need to do : ret._rid to access the rid
I am beginner in OrientDB and I have a scenario as below,
I want to select all the permissions "Adrian" has on "Workspace A"
I can see from the graph that "Adrian" will have all the permissions but I am not able to form the Select query in OrientDB for that.
The classes are as below,
I think the query should look like below but it doesn't return any result,
SELECT name, out('isOfType').in('ofType').out('hasA').name as permission
FROM resource
WHERE name = 'Workspace A' and
out('isOfType').in('OfType').in('hasARole').name = 'Adrian'
graph operators return collections, so you have to use CONTAINS instead of =
eg.
SELECT name, out('isOfType').in('ofType').out('hasA').name as permission
FROM resource
WHERE name = 'Workspace A' and
out('isOfType').in('OfType').in('hasARole').name CONTAINS 'Adrian'
Due to the way this is structured I can't bring back groups with no comments/feeds in them, unfortunately trying to invert this brings up multiple errors as CollaborationGroup does not understand the relationship it has with CollaborationGroupFeed.
Here is the query:
SELECT
c.Parent.Id,
c.Parent.OwnerId,
c.Parent.CreatedById,
c.Id,
c.ParentId,
(
SELECT
Id,
FeedItemId,
ParentId
FROM FeedComments
)
FROM CollaborationGroupFeed c
I can't do it like this though for whatever reason:
SELECT
Id,
OwnerId,
CreatedById,
(
SELECT
Id,
ParentId
FROM CollaborationGroupFeeds
),
(
SELECT
Id,
FeedItemId,
ParentId
FROM FeedComments
)
FROM CollaborationGroup
Didn't understand relationship 'CollaborationGroupFeed' in FROM part of query call.`
EDIT
So lets say I have a Group that I just created called Foo
[FOO]
Foo has one Post in it BlahPost
[FOO]
|
|_BlahPost
Lets say BlahPost has a comment (or several)
[FOO]
|
|_BlahPost
|_Comment 1
|_Comment 2
The query above will return all of this.
Now lets say I have a new Group Bar
[Bar]
Since there are NO posts/comments the query above returns nothing since I'm working from child to parent,
and parent has no posts. I am looking for a query that starts at the parent CollaborationGroup and moves
down to CollaborationFeed which will display FeedComment
Make more sense? The order is mess up, I'm working from the middle and should be working from the top
Try using Chatter in Apex, which is Chatter REST API resource actions exposed as static methods in the Apex ConnectApi namespace. It's a much easier way to access Chatter data.
http://www.salesforce.com/us/developer/docs/apexcode/Content/connectAPI_overview.htm
http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_classes_connect_api.htm