nicolewhite / cycli

A Command Line Interface for Neo4j's Cypher.
MIT License
271 stars 25 forks source link

Cypher interpretation of commented lines ending in semicolons #64

Open victoriastuart opened 6 years ago

victoriastuart commented 6 years ago

Hi: I'm not sure if this issue resides with Neo4j or Cycli; I suspect the latter (Cycli), as detailed below.

Problem Description

I prefer to use cypher scripts and Neovim, rather than the Neo4j Browser, for working with data.

However, when I comment-out ( // ... ) lines in the cypher scripts using a keyboard shortcut in Neovim, commented lines lines ending in semicolons throw warnings in Cycli.

The same code pasted into the Neo4j Browser, or the same script loaded into Neo4j via cypher-shell results in reading of the code, with no wrnings.

Thus, when I am writing scripts and and I want to comment out statements that end in a semicolon with my keyboard shortcut (Neovim editor), I ALSO need to go to the end of all of those //-commented lines and delete those semicolons (reversing that tedious process when uncommenting those lines).

That is, if I want to avoid seeing those warnings.

glycolysis_bioentities.csv [exported form a PostgreSQL database, hence the .csv extension]:

name
α-D-glucose
glucose 6-phosphate
fructose 6-phosphate
"fructose 1,6-bisphosphate"
dihydroxyacetone phosphate
D-glyceraldehyde 3-phosphate
"1,3-bisphosphoglycerate"
3-phosphoglycerate
2-phosphoglycerate
phosphoenolpyruvate
pyruvate
hexokinase
glucose-6-phosphatase
phosphoglucose isomerase
phosphofructokinase
"fructose-bisphosphate aldolase, class I"
triosephosphate isomerase (TIM)
glyceraldehyde-3-phosphate dehydrogenase
phosphoglycerate kinase
phosphoglycerate mutase
enolase
pyruvate kinase

glycolysis.cypher:

LOAD CSV WITH HEADERS FROM "file:/glycolysis_bioentities.csv" AS row
MERGE (n:Glycolysis {name:row.name})
// RETURN n, labels(n), n.name;
RETURN n.name;
// Same:
// MATCH (n) RETURN n.name;

Examples - Cycli :

cycli -P 7474 -u victoria -p <password_obfuscated_here> -f glycolysis.cypher

> LOAD CSV WITH HEADERS FROM "/glycolysis_bioentities.csv" AS row
MERGE (n:Glycolysis {name:row.name})
// RETURN n, labels(n), n.name;
109 ms

> RETURN n.name;
Variable `n` not defined (line 1, column 8 (offset: 7))
"RETURN n.name;"
        ^

> // Same:
// MATCH (n) RETURN n.name;
Unexpected end of input: expected whitespace, comment, CYPHER options, EXPLAIN, PROFILE or Query (line 2, column 29 (offset: 37))
"// MATCH (n) RETURN n.name;"
                            ^

(py35) [victoria@victoria Vancouver]$ 

Despite those warnings, the 22 nodes are created in the Neo4j Browser. So it appears to be a warnings-related issue, not a script execution errors.

Compare that shell output to this modified script, where I deleted semicolons at ends of //-commented lines:

LOAD CSV WITH HEADERS FROM "file:/glycolysis_bioentities.csv" AS row
MERGE (n:Glycolysis {name:row.name})
// RETURN n, labels(n), n.name
RETURN n.name;
// Same
// MATCH (n) RETURN n.name

Script execution - Cycli :

cycli -P 7474 -u victoria -p <password_obfuscated_here> -f glycolysis.cypher

> LOAD CSV WITH HEADERS FROM "file:/glycolysis_bioentities.csv" AS row
MERGE (n:Glycolysis {name:row.name})
// RETURN n, labels(n), n.name
RETURN n.name;
n.name                                  
----------------------------------------
α-D-glucose                             
glucose 6-phosphate                     
fructose 6-phosphate                    
fructose 1,6-bisphosphate               
dihydroxyacetone phosphate              
D-glyceraldehyde 3-phosphate            
1,3-bisphosphoglycerate                 
3-phosphoglycerate                      
2-phosphoglycerate                      
phosphoenolpyruvate                     
pyruvate                                
hexokinase                              
glucose-6-phosphatase                   
phosphoglucose isomerase                
phosphofructokinase                     
fructose-bisphosphate aldolase, class I 
triosephosphate isomerase (TIM)         
glyceraldehyde-3-phosphate dehydrogenase
phosphoglycerate kinase                 
phosphoglycerate mutase                 
enolase                                 
pyruvate kinase                         

109 ms

Example - cypher-shell :

As mentioned, this does not occur when loading that same .cypher script into cypher-shell, where it runs without issue (resulting in 22 nodes in the Neo4j Browser):

cat glycolysis.cypher |  cypher-shell -u victoria -p <password_obfuscated_here>

n.name
"α-D-glucose"
"glucose 6-phosphate"
"fructose 6-phosphate"
"fructose 1,6-bisphosphate"
"dihydroxyacetone phosphate"
"D-glyceraldehyde 3-phosphate"
"1,3-bisphosphoglycerate"
"3-phosphoglycerate"
"2-phosphoglycerate"
"phosphoenolpyruvate"
"pyruvate"
"hexokinase"
"glucose-6-phosphatase"
"phosphoglucose isomerase"
"phosphofructokinase"
"fructose-bisphosphate aldolase, class I"
"triosephosphate isomerase (TIM)"
"glyceraldehyde-3-phosphate dehydrogenase"
"phosphoglycerate kinase"
"phosphoglycerate mutase"
"enolase"
"pyruvate kinase"

Thanks! :-)