export to csv from neo4j using import-cypher - neo4j

I found this neo4j data exporting tool (https://github.com/jexp/neo4j-shell-tools#cypher-import) and it worked perfectly on my mac OS computer. I followed the same step to export data from a ubuntu server and the following error message was generated without further explanations.
Has anyone used this tool on ubuntu and any idea what the error message may indicate? Also, is there another way to export large (~100M rows) neo4j data into a csv file?
neo4j-sh (?)$ import-cypher -d"," -o test.csv match (p:Product)-[s:SIMILAR_TO]-(q:Product) return p.Id,q.Id limit 10
Query: match (p:Product)-[s:SIMILAR_TO]-(q:Product) return p.Id,q.Id limit 10 infile (none) delim ',' quoted false outfile test.csv batch-size 1000
Error occurred in server thread; nested exception is:
java.lang.NoSuchMethodError: org.neo4j.graphdb.GraphDatabaseService.execute(Ljava/lang/String;)Lorg/neo4j/graphdb/Result;

I just added a new way of exporting data as cypher statements.
https://github.com/jexp/neo4j-shell-tools#cypher-export
(Note this is for Neo4j 2.2.5)
But for 100M rows I think import-cypher -o is still a good approach.
Otherwise check out: http://neo4j.com/blog/export-csv-from-neo4j-curl-cypher-jq/

Related

Vertica's vsql.exe returns errorlevel 0 when facing ERROR 3326: Execution time exceeded run time cap

I am using vsql.exe on an external Vertica database for which I don't have any administrative access. I use some views with simple SELECT+FROM+WHERE queries.
These queries 90% of the time work just fine, but some times, randomly, I get this error:
ERROR 3326:  Execution time exceeded run time cap of 00:00:45
The strange thing is that this error can happen way after those 45 seconds, even after 3 minutes. I've been told this is related to having different resource pools, but anyway I don't want to dig into that.
The problem is that when this occurs, vsql.exe returns errorlevel 0 and there is (apparently almost) no way to know this failed.
The output of the query is stored in a csv file. When it succeeds, it ends with (#### rows). But when it fails with this error, it just stops at any point of the csv, and its resulting size is around half of what's expected. This is of course not what you would expect when an error occurs, like no output or an empty one.
If there is a connection error or if the query has syntax errors, the errorlevel is not 0, so in those cases it behaves as expected.
I've tried many things, like increasing the timeout or adding -v ON_ERROR_STOP=ON to the vsql.exe parameters, but none of that helped.
I've googled a lot and found many people having this error, but the solutions are mostly related to increasing the timeouts, not related to the errorlevel returned.
Any help will be greatly appreciated.
TL;DR: how can I detect an error 3326 in a batch file like this?
#echo off
vsql.exe -h <hostname> -U <user> -w <pwd> -o output.cs -Ac "SELECT ....;"
echo %errorlevel% is always 0
if errorlevel 1 echo Error!! But this is never displayed.
Now that's really unexpected to me. I don't have Windows available just now, but trying on my Mac - at first just triggering a deliberate error:
$ vsql -h zbook -d sbx -U dbadmin -w $VSQL_PASSWORD -v ON_ERROR_STOP=ON -Ac "select * from foobarfoo"
ERROR 4566: Relation "foobarfoo" does not exist
$ echo $?
1
With ON_ERROR_STOP set to ON, this should be the behaviour everywhere.
Could you try what I did above through Windows, just with echo %ERRORLEVEL% instead of echo $?, just from the Windows command prompt and not in a batch file?
Next test: I run on resource pool general in my little test database, so I temporarily modify it to a runtime cap of 30 sec, run a silly query that will take over 30 seconds with ON_ERROR_STOP set to ON, collect the value returned by vsql and set the runtime cap of general back to NONE. I also have the %VSQL_* % env variables set so I don't have to repeat them all the time:
rem Windows way to set environment variables for vsql:
set VSQL_HOST=zbook
set VSQL_DATABASE=sbx
set VSQL_USER=dbadmin
set VSQL_PASSWORD=***masked***
Now for the test (backslashes, in Linux/MacOs escape a new line, which enables you to "word wrap" a shell command. Use the caret (^) in Windows for that):
marco ~/1/Vertica/supp $ # set a runtime cap
marco ~/1/Vertica/supp $ vsql -i -c \
"alter resource pool general runtimecap '00:00:30'"
ALTER RESOURCE POOL
Time: First fetch (0 rows): 116.326 ms. All rows formatted: 116.730 ms
marco ~/1/Vertica/supp $ vsql -v ON_ERROR_STOP=ON -iAc \
"select count(*) from one_million_rows a cross join one_million_rows b"
ERROR 3326: Execution time exceeded run time cap of 00:00:30
marco ~/1/Vertica/supp $ # test the return code
marco ~/1/Vertica/supp $ echo $?
1
marco ~/1/Vertica/supp $ # clear the runtime cap
marco ~/1/Vertica/supp $ vsql -i -c \
"alter resource pool general runtimecap NONE "
ALTER RESOURCE POOL
Time: First fetch (0 rows): 11.148 ms. All rows formatted: 11.383 ms
So it works in my case. Your line:
if errorlevel 1 echo Error!! But this is never displayed.
... never echoes anything because the previous line, with echo will return 0 to the shell, overriding the previous errorlevel.
Try it command by command on your Windows command prompt, and see what happens. Just echo %errorlevel%, without evaluating it.
And I notice that you are trying to export to CSV format. Then, try this:
Format the output unaligned (-A)
set the field separator to comma (-F ',')
remove the footer '(n rows)' (-P footer)
limit the output to 5 rows in the query for test
(I show the output before redirecting to file):
marco ~/1/Vertica/supp $ vsql -A -F ',' -P footer -c "select * from one_million_rows limit 5"
id,id_desc,dob,category,busid,revenue
0,0,1950-01-01,1,====== boss ========,0.000
1,-1,1950-01-02,2,kbv-000001kbv-000001,0.010
2,-2,1950-01-03,3,kbv-000002kbv-000002,0.020
3,-3,1950-01-04,4,kbv-000003kbv-000003,0.030
4,-4,1950-01-05,5,kbv-000004kbv-000004,0.040
Not aligning is much faster than aligning.
Then, as you spend most time in the fetching of the rows (that's because you get a timeout in the middle of an output file write process), try fetching more rows at a time than the default 1000. You will need to play with the value, depending on the network settings at your site until you get your best value:
-v ROWS_AT_A_TIME=10000
Once you're happy with the tested output, try this command (change the SELECT for your needs, of course ....):
marco ~/1/Vertica/supp $ vsql -A -F ',' -P footer \
-v ON_ERROR_STOP=ON -v ROWS_AT_A_TIME=10000 -o one_million_rows.csv \
-c "select * from one_million_rows"
marco ~/1/Vertica/supp $ wc -l one_million_rows.csv
1000001 one_million_rows.csv
The table actually contains one million rows. Note the line count in the file: 1,000,001. That's the title line included, but the footer (1000000 rows) removed.

Export table to a csv file in DBeaver with command

I am using the following command to export the data
\copy (select * From table_name) To 'my_path' With CSV DELIMITER ',' HEADER;
But I get error syntax error at or near "\".
If I use
copy (select * From table_name) To 'my_path' With CSV DELIMITER ',' HEADER;
I get the error COPY TO instructs the PostgreSQL server process to write a file. You may want a client-side facility such as psql's \copy.
I really do not know which command I should run. Thanks in advance for your help:))

neo4j-import failed while import local CSV file

I am trying to import a CSV file into the neo4j database, I adopted the sample online but I still failed.
I executed the following command under the 'import' directory:
../bin/neo4j-admin import --into retail.db --id-type string --nodes:Customer customers.csv --nodes products.csv --nodes orders_header.csv --relationships:CONTAINS order_details.csv --relationships:ORDERED customer_orders_headers.csv
Expectedly,the windows powershell should have results like:
IMPORT DONE IN 5s 212ms
Imported:
6 nodes
7 relationships
12 properties
However,my actual result is
expected '--nodes 'to have at least 1 valid item,but had 0[]
and gave me some usage guidance of neo4j-admin import. I cannot tell what the problem was because my command seemed correct.

Apoc failed to find a compatible version

I'm brand new, fresh and clean with Neo4J. Just downladed and installed the Neo4J Desktop application, working offline. Noticed that the plugins don't get the install button enabled.
Creating a graph DB and trying to install manually the apoc plugin with latest jar file (compatible one), it fails to get loaded apparently.
Using NEO4J Desktop 1.1.17 offline + server 3.5.2 + APOC 3.5.0.2 jar in plugins folder
I've followed the online doc and updated neo4j conf auhtorizing things in there.
dbms.security.procedures.unrestricted=apoc.*
dbms.security.procedures.whitelist=apoc.*
Restarted things but still with no success. What Am I doing wrong in here ?
Seems quite a basic issue but as there is no stupid question...
Thanks for your feedbacks
Best regards
Any hint.
I have neo4j server (not desktop) version 3.5.4.
I downloaded apoc 3.5.0.3 which if memory serves was a zip archive. After unzipping, I copied the one jar into my plugins directory.
I modified the config file as you indicated. I used commas to separate the entries.
I did not update the whitelist parameter which remains commented out in my config file.
Next I restarted neo4j and the apoc procedures seem to work.
Have a look at my transcript below for the details of my setup:
gmc#linux-ihon:/usr/local/neo4j-community-3.5.4> ls -l plugins
total 14808
-rw-r--r-- 1 gmc users 13695353 Apr 18 09:51 apoc-3.5.0.3-all.jar
-rw-r--r-- 1 gmc users 1459334 Apr 11 00:34 graph-algorithms-algo-3.5.4.0.jar
-rw-r--r-- 1 gmc users 2217 Apr 3 18:09 README.txt
gmc#linux-ihon:/usr/local/neo4j-community-3.5.4> grep whitelist conf/neo4j.conf
#dbms.security.procedures.whitelist=apoc.coll.*,apoc.load.*
gmc#linux-ihon:/usr/local/neo4j-community-3.5.4> grep unrestricted conf/neo4j.conf
#dbms.security.procedures.unrestricted=my.extensions.example,my.procedures.*
dbms.security.procedures.unrestricted=apoc.*,algo.*
gmc#linux-ihon:~> cypher-shell --username neo4j
password: ****
Connected to Neo4j 3.5.4 at bolt://localhost:7687 as user neo4j.
Type :help for a list of available commands or :exit to exit the shell.
Note that Cypher queries must end with a semicolon.
neo4j> call apoc.help("apoc.help");
+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| type | name | text | signature | roles | writes |
+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| "procedure" | "apoc.help" | "Provides descriptions of available procedures. To narrow the results, supply a search string. To also search in the description text, append + to the end of the search string." | "apoc.help(proc :: STRING?) :: (type :: STRING?, name :: STRING?, text :: STRING?, signature :: STRING?, roles :: LIST? OF STRING?, writes :: BOOLEAN?)" | NULL | NULL |
+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row available after 31 ms, consumed after another 1 ms
neo4j>
FWIW, the graph algorithms procedures also work.
It is possible that you have two installations and modified the non-running one???

WARNING: Invalid input 'S': expected 'n/N' USING PERIODIC COMMIT

I'm trying to import à CSV via Neo4JShell on Neo4J 3.0.4.
This script worked on an older version of Neo4J.
Here's my script :
USING PERIODIC COMMIT 5000
LOAD CSV WITH HEADERS FROM
"file:///my_file.csv"
AS line FIELDTERMINATOR ';'
WITH coalesce(line.VAR1,"") as var1
MERGE (i:myObject {var1: var1})
But I get this error :
WARNING: Invalid input 'S': expected 'n/N' (line 9, column 2 (offset: 247))
"USING PERIODIC COMMIT 5000"
Any idea ?
I install the zip version, one powershell to run "invoke-neo4j console", and an other powershell to run de "invoke-neo4jshell -file "my_script.cypher"
Thanks.

Resources