0

I have written a buggy cypher script, but I cannot find the actual problem.

Here is the crucial part of the script:

:begin
:param measured => 'heat';
:param vals => [
    {d: datetime({year: 2022, month: 1, day: 1, hour: 4}), v: 47980},
    {d: datetime({year: 2022, month: 2, day: 1, hour: 4}), v: 50840},
    {d: datetime({year: 2022, month: 3, day: 1, hour: 4}), v: 53190}];
MATCH (i:Installation:HeatPump {name: "Demoanlage"})--(m:MeasurementSite {measuredObj: $measured})--(me:Meter)
    WHERE ID(i) = $hpId WITH me UNWIND $vals as val
        MERGE (me)-[:MEASURED_MANUALLY {createdAt: datetime.transaction()}]->
            (v:Val {d: val.d, v: val.v}) RETURN v;
:commit
There is one more :begin :commit block, this might also be a problem.

When I run this script I am getting the following output:

// using a cypher shell 
sdptest@neo4j> :source /home/myname/path/to/cypher-scripts/data_imports/add_demo_hp_vals.cypher;
org/neo4j/internal/helpers/collection/Pair // this is in red, kind of error message
sdptest@neo4j# // note the hash instead of the 'greater than' sign

For making the question clearer: I don't get the org/neo4j/internal/helpers/collection/Pair 'error' and I don't get why the hash suddenly shows up (which looks like a root user in a usual linux shell)?

Googling did not help.

(Version: Neo4j 4.4.9, cypher-shell the same).

Edit

May it is not allowed to add parameter in scripted transaction (:begin :commit)? Because the query seems to be OK to me.

BairDev
  • 2,865
  • 4
  • 27
  • 50

2 Answers2

0

It might be a shot in the dark, but I think you are missing a parameter, $hpId, in the following snippet:

:begin
:param measured => 'heat';
:param vals => [
    {d: datetime({year: 2022, month: 1, day: 1, hour: 4}), v: 47980},
    {d: datetime({year: 2022, month: 2, day: 1, hour: 4}), v: 50840},
    {d: datetime({year: 2022, month: 3, day: 1, hour: 4}), v: 53190}];
MATCH (i:Installation:HeatPump {name: "Demoanlage"})--(m:MeasurementSite {measuredObj: $measured})--(me:Meter)
    WHERE ID(i) = $hpId WITH me UNWIND $vals as val
        MERGE (me)-[:MEASURED_MANUALLY {createdAt: datetime.transaction()}]->
            (v:Val {d: val.d, v: val.v}) RETURN v;
:commit

Try after, providing it a value.

Charchit Kapoor
  • 8,934
  • 2
  • 8
  • 24
0

This is an alternative way of executing your script via cypher-shell. Save it into a file then running the contents of that file thru cypher-shell command.

From bash terminal; 1) create the file (vi file) 2) copy/paste/save your code 3) then run below command thru bash command. It will pass the contents of file and give it to cypher-shell to execute.

 cat file | cypher-shell -u neo4j -p <neo4j_password> --format plain
jose_bacoy
  • 12,227
  • 1
  • 20
  • 38