I am sending cypher query using REST API as shown below:
MATCH (user:Profile)-[:HAS_SEARCHED]-(term{name:"TV"})
WITH [x in collect(user)| id(x) ] AS userIDs
MATCH(user:Profile) where id(user) in userIDs
MATCH (user)-[r:HAS_SEARCHED]->(term:SearchTerm)
return term.name
Although the query executes well when running on the server directly, gives below error in eclipse:
{"results":[],"errors":[{"code":"Neo.ClientError.Request.InvalidFormat",
"message":"Unable to deserialize request:
Unexpected character ('T' (code 84)): was expecting comma to separate OBJECT entries\n at
[Source: HttpInputOverHTTP#2543f0f2; line: 1, column: 85]"}]}
Please help!! Thanks
Regarding your query, you don't need to match the users twice:
MATCH (user:Profile)-[:HAS_SEARCHED]-(term:SearchTerm {name:"TV"})
WITH distinct user
MATCH (user)-[r:HAS_SEARCHED]->(term:SearchTerm)
RETURN term.name, count(*) as freq
or even:
MATCH (term:SearchTerm {name:"TV"})<-[:HAS_SEARCHED]-(:Profile)-[:HAS_SEARCHED]->(term:SearchTerm)
RETURN term.name, count(*) as freq
Related
I have HTTP access log data in a Druid data source, and I want to see access patterns based on certain identifiers in the URL path. I wrote this query, and it works fine:
select regexp_extract(path, '/id/+([0-9]+)', 1) as "id",
sum("count") as "request_count"
from "access-logs"
where __time >= timestamp '2022-01-01'
group by 1
The only problem is that not all requests match that pattern, so I get one row in the result with an empty "id". I tried adding an extra condition in the where clause:
select regexp_extract(path, '/id/+([0-9]+)', 1) as "id",
sum("count") as "request_count"
from "access-logs"
where __time >= timestamp '2022-01-01' and "id" != ''
group by 1
But when I do that, I get this error message:
Error: Plan validation failed: org.apache.calcite.runtime.CalciteContextException:
From line 4, column 46 to line 4, column 49: Column 'id' not found in any table
So it doesn't let me reference the result of the expression in the where clause. I could of course just copy the entire regexp_extract expression, but is there a cleaner way of doing this?
Since id is an aggregated column, you would need a HAVING clause to filter on it.
I'm trying make a query with HQL that will stay with the same order as given list of IDs. I know it's possible with SQL but I can't find any way to do it with HQL (and I cannot do it with native SQL because I got many joins)
Example
fingerIds = [3,1,10,4]
SELECT p FROM People p
JOIN FETCH p.fingers f
WHERE f.id IN :fingerIds
DB: PostgreSQL 10.4
Hibernate: 4.3.11.Final
Eg. Given list of IDs: [3,1,10,4]
Actual result's order: [1,3,4,10]
Expected result's order: [3,1,10,4]
You can obtain the order by adding to your query the keyword FIELD, in your example:
SELECT p FROM People p
JOIN FETCH p.fingers f
WHERE f.id IN :fingerIds
ORDER BY FIELD(f.ID,3,1,10,4)
Ofc you can replace the numbers with your variable :fingerIds
You can find more about that command here.
Returns the index (position) of str in the str1, str2, str3, ... list. Returns 0 if str is not found.
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
I have a simple graph in which I am trying to start at a particular node and traverse a depth of 2. From this traversal I am trying to extract the names of nodes and relationships.
This is my query,
START n=node(5)
MATCH p=(n)-[r:Relation*0..2]-(m)
RETURN n.name,r.name,m.name;
I get this error:
Type mismatch: expected Map, Node or Relationship but was Collection<Relationship> (line 3, column 15)
In the error description, it points a ^ symbol to r.name
Can Someone help me understand this issue. My goal is to get the names of relationships along way..
From what I have understood, the r is being returned as a collection. Is there a way to display the individual names within the collection?
Sham,
As you noted, the problem is that 'r' is a collection of relationships that may have 0, 1, or 2 elements. You can use the reduce function to create a string of the relationship names and return that string.
START n=node(5)
MATCH (n)-[r:Relation*0..2]-(m)
WITH n, m, reduce(s = '', rel IN r | s + rel.name + ',') as rels
RETURN n.name, m.name, rels;
Grace and peace,
Jim
I am writing a query that calculates a possible score for a QuestionAnswer, when executing the query I get a PSQLException
Info about the model
A QuestionAnswer can have several (at least one) questionAnswerPossibilities, since there are multiple ways to answer the question correctly.
Every questionAnswerPossibility has several questionAnswerParts, in the query below we query the score per questionAnswerPossibility.
The Problematic Query
The query itself does generate SQL, but the SQL can not be executed
def queryMogelijkePuntenByVragenViaOpenVragen()(implicit session: Session) = {
(for{
ovam <- OpenVraagAntwoordMogelijkheden //questionAnswerPossibilites
ovad <- OpenVraagAntwoordOnderdelen if ovad.ovamId === ovam.id //questionAnswerParts
ova <- OpenVraagAntwoorden if ovam.ovaId === ova.id //questionAnswers
} yield ((ova, ovam), ovad.punten))
.groupBy{ case ((ova, ovam), punten) => (ova, ovam)}
.map{ case ((ova, ovam), query) => (ova, ovam, query.map(_._2).sum)}
}
Here the generated SQL (postgreSQL)
select x2."id", x2."vraag_id", x3."id", x3."volgorde", x3."ova_id", sum(x4."punten")
from "open_vraag_antwoord_mogelijkheden" x3, "open_vraag_antwoord_onderdelen" x4, "open_vraag_antwoorden" x2
where (x4."ovam_id" = x3."id") and (x3."ova_id" = x2."id")
group by (x2."id", x2."vraag_id"), (x3."id", x3."volgorde", x3."ova_id")
The problem is that the SQL can not execute , I get the following error
play.api.Application$$anon$1:
Execution exception[[
PSQLException: ERROR: column "x2.id" must appear in the GROUP BY clause or be used in an aggregate function
Position: 8]]
The SQL that is genarated contains too many brackets, the last part of the SQL should be
group by x2."id", x2."vraag_id", x3."id", x3."volgorde", x3."ova_id"
However slick generates it with brackets, am I doing something wrong here? Or is this a bug?
I solved the issue
...
} yield ((ova.id, ovam.id), ovad.punten))
Because I now only yield the nessecary id's and not all data, the sql that is generated does not contain the unnecessary braces that caused the SQL error.
I really wanted more data than just those id's, but I can work around this by using this query as a subquery, the outer query will fetch all the needed data for me.