I find Cypher, or at least its documentation, to be extraordinarily frustrating because it tells me obvious things and is silent about the things that matter. I am new to Cypher, that's why I depend on the docs. Let me give an example.
As a baby step, I just want to see "avg" work in a live bolt browser (mumble:7474). The doc says "avg returns the average of a set of numeric values". Great. I guessed that from its name. The docs say that the syntax is "avg(expression)". Duh.
So I need to understand how to write an expression in Cypher that evaluates to a set of numeric values. That's EASY (in the bolt browser):
RETURN [1, 2, 3, 4, 5]
Push the little button and I get:
[1, 2, 3, 4, 5]
Ok, I just want to pass that to avg and return the result, right?
RETURN avg([1, 2, 3, 4, 5])
Wrong. ERROR: Neo.ClientError.Statement.SyntaxError --
Type mismatch: expected Float, Integer or Duration but was List<Integer> (line 1, column 12 (offset: 11))
"RETURN avg([1, 2, 3, 4, 5])"
^
Hmmm. Well, maybe I need to wrap it in something. But what?
RETURN COLLECT([1, 2, 3, 4, 5])
Nope, that's a list of lists.
Well, the complaint seemed to squawk about the square bracket, so maybe the following will work:
RETURN avg(1, 2, 3, 4)
Nope, no joy.
And so suddenly I find myself lost in the Cypher manual.
If a list literal -- [1, 2, 3]
, or range(0, 3)
-- doesn't work as an argument to "avg", then what DOES work? What TYPE is an "expression" in the documentation of avg?
I sort-of understand how paths work. Once I understand how to talk to cypher, I THINK what I want to do is straightforward -- I want to collect a set of data values from an existing graph and compute something that looks a lot like a standard deviation (full, not sample).
My intuition says, perhaps incorrectly, that I ought to be able to do all of this in Cypher so that once I have a query I can apply it to my database (with several hundred thousand datapoints).
I know what a list comprehension is in Python, and I'm perfectly comfortable with its counterpart in Javascript/nodejs/React. I can write what I want in about 10 minutes in any of those. I think I can probably do it in MySQL if I had to (perish the thought).
I think this is almost surely a documentation issue and/or pilot error.
Does this REALLY have to be so hard? Is there some resource that walks through stuff like this that I don't know about?
I want to know, quite specifically (as in a BNF grammar or something similar) EXACTLY what type avg expects. Then I want to find out exactly what type these various clauses emit.
A phone-book style enumeration of names and natural-language descriptions just barely scratches the surface.