OrientDB: all pairs shortest path - orientdb

I'm trying to write a OSQL query for computing the length of the shortest path between all pairs of nodes but, since having more than one class in the FROM clause is not allowed, I am wondering how I can loop over all the pairs of different nodes.
I tried with this query:
SELECT shortestPath($current, $e0, 'BOTH', 'Meets')
FROM Employee
LET $e0 = (SELECT FROM Employee where $current.nt_account > $parent.nt_account)
(nt_account is the Employee ID).
When I try to execute the query I get the following error:
java.lang.IllegalArgumentException: Vertex id can not be null
Can anybody help me?
Cheers!

Try this query
select from (select $b.shortestPath from Employee let $b= ( SELECT shortestPath($parent.current,#this, 'BOTH', 'Meets') from Employee)) unwind $b

Related

OrientDB: select edge where out=(select ??) does not work

I have a problem. I think that this is supposed to work, otherwise someone else would have run into this problem.
The following command works perfectly:
// suppose my record id is #10:0
select from MyEdgeType where out=#10:0
This works.
select from MyNodeType where name="this"
> returns obj with #rid = #10:0
The following does not work:
select from MyEdgeType where out=(select from MyNodeType where name="this")
select from MyEdgeType where out=(select #rid from (select from MyNodeType where name="this")
select from MyEdgeType let $rec = (select fcom MyNodeType...) where out=$rec.rid
... etc.
Nothing works. Nothing. How do I select from edges such that I do not have to know the record id which is incident to the edges I would like to grab ahead of time?
You're comparing a single field on a resultset (it's like comparing a string to an array), try something like this:
select from MyEdgeType where out IN (select from MyNodeType where name="this")
I got this to work.
Since my nodes are unique (this is a constraint), I used the unique property to ID them during the filtration, rather than the record id from a subquery:
select from MyEdgeType where out.unique_identifier=...
worked.

Have to find a count of rows from my postgresql query

Hi I tried to get a count of rows from my below query:
select count(substring(wsresult_question FROM '[0-9]+') as pumporder) AS totals,
job_id,
job_siteid,
job_completed
from webserviceresults w, jobs s
where job_siteid = '1401'
and job_id = wsresult_jobid
and job_completed is not null
and wsresult_question LIKE 'job.job_site_data.site_meters.pump.%'
and wsresult_category = 'Job'
group by pumporder,job_id,job_siteid,job_completed order by job_completed desc
I tried this and i got the error like
There was an SQL error:
ERROR: syntax error at or near "as" LINE 1: ... count(substring(wsresult_question FROM '[0-9]+') as pumpord... ^
In this line substring(wsresult_question FROM '[0-9]+') as pumporder I just tired to get only a number from some concatenate strings. The concatenate string is being like
1.job.job_site_data.site_meters.pump.0.meter_calibration_record.meter_adjustedtofast
2.job.job_site_data.site_meters.pump.0.meter_calibration_record.meter_adjustedtoslow
3.job.job_site_data.site_meters.pump.1.meter_calibration_record.meter_adjustedtofast
So substring(wsresult_question FROM '[0-9]+') as pumporder is return the numbers like 0,1 in array. I need to total the count of rows now. So Kindly help me on this.
Please let me know if you have any queries.
Thanks in advance!
your error means you should not create an alias for the function - only for the column, so if you remove as pumporder from count(substring(wsresult_question FROM '[0-9]+') as pumporder) , error will go away
Your approach though is very doubtful. If you want to count number of rows with substring(wsresult_question FROM '[0-9]+'), you better instead:
select count(1) AS totals,
job_id,
job_siteid,
job_completed
from webserviceresults w, jobs s
where job_siteid = '1401'
and job_id = wsresult_jobid
and job_completed is not null
and wsresult_question ~ '^(job.job_site_data.site_meters.pump.)[0-9]'
and wsresult_category = 'Job'
group by pumporder,job_id,job_siteid,job_completed order by job_completed desc
and lastly the string job.job_site_data.site_meters.pump.0 looks like json path, so it would be more appropriate using json array length function, not count on rows

EXISTS in filter returning too many values

I need to write a query that uses EXISTS, rather than IN, so that it will run fast. The filter is being fed so many parameter values that EXISTS seems like the only option. The difference is between a 20+ minute query and a 5 second query.
This is the query I have:
SELECT DISTINCT d.GROUP_NAME
FROM [EMPLOYEE] e JOIN [DATA_FACT] d ON (e.KEY = d.KEY)
WHERE d.DATE BETWEEN #Start and #End
AND EXISTS
(
select '1234567' -- #ID
)
AND e.Location IN (#Location)
ORDER BY d.GROUP_NAME ASC
The problem is that it is returning too many records. Based on the values I'm passing to filter on, I should get 1 row back but instead I am getting 28.
If I remove the EXISTS and add the following then I get the 1 record I need:
AND e.ID IN ('1234567')
Is there a way to fix the query to work with EXISTS so that I get the correct results?
This is essentially what you want if you are going to try to use exists to filter your data_fact table by parameters in your employee table. Not sure how much it's going to improve your performance though when you throw a massive number of employee IDs at it.
SELECT
d.GROUP_NAME
FROM [DATA_FACT] AS d
WHERE d.DATE BETWEEN #Start and #End
AND EXISTS
(
select 1
from EMPLOYEE AS e
WHERE d.[KEY] = e.[KEY]
AND e.[Location] IN (#Location)
AND e.ID IN ('1234567')
)
ORDER BY d.GROUP_NAME ASC

OrientDB - Creating an edge using rid's from index queries

I'm trying to create edges between existing vertices queried by their indexed IDs, similar to the first answer here, but using this index lookup query instead of the label query:
CREATE EDGE cite
FROM
(SELECT FROM index:<className>.<indexName> WHERE key = "<keyString>")
TO
(SELECT FROM index:<className>.<indexName> WHERE key = "<keyString>")
This gives me the following error: com.orientechnologies.orient.core.exception.OCommandExecutionException: Source vertex '#-1:-1' not exists
Possibly relevant:
When I just query SELECT FROM index:<className>.<indexName> WHERE key = "<keyString>" by itself it returns an array object structured like:
[ { '#type': 'd',
key: '<keyString>',
rid: { cluster: <actual cluster>, position: <actual position> }
#rid: { cluster: -1, position: -1 } } ]
I'm guessing that the error has something to do with the CREATE EDGE query using the #rid instead of the rid but I'm not sure.
The query successfully creates the edges if I simply use the #<actual cluster>:<actual position> instead of the SELECT subquery.
Any ideas what I might be doing wrong?
Edit: In the interest of replicability, I have the same problem in the GratefulDeadConcerts database when I (1) add a property name to the V class schema, (2) create a unique nameIndex index of V using the name property under V, and then (3) use the following query:
create edge followed_by from (select from index:nameIndex where key = 'HEY BO DIDDLEY') to (select from index:nameIndex where key = 'IM A MAN')
Why don't you query the class directly?
CREATE EDGE cite
FROM
(select from Class where field = '<keyString>')
TO
(select from Class where field = '<keyString>')
Select from index return a temp document as result set with key,and rid
you can try but i don't know if it will work
SELECT expand(rid) FROM index:<className>.<indexName> WHERE key = "<keyString>"

How do I traverse a relationship in a WHERE clause with OpenJPA?

I am new to JPA and OpennJPA. I have two entities UserDmo and SupplierDmo. Each Supplier can have several users and this relationship is established as follws,
In UserDmo,
Column(name="id_supplier")
private long idSupplier;
#ManyToOne(optional=true)
#JoinColumn(name="ID_SUPPLIER")
private SupplierDmo supplier;
In here column ID_SUPPLIER is the FK with referenced by ID column of the SupplierDmo. Using these two entities I tried to obtain result by following query.
SELECT u.id, u.modifiedDate FROM UserDmo u JOIN u.idSupplier s WHERE s.id = 1
But I got, Error message: Attempt to query field "s.id" from non-entity variable "s". Perhaps you forgot to prefix the path in question with an identification variable from your FROM clause?
I really appreciate your help on this
Try something like this :
SELECT u.id, u.modifiedDate FROM UserDmo u WHERE u.supplier.id = 1