What I am trying to do is to import a dataset with a tree data structure inside from CSV to neo4j. Nodes are stored along with their parent node and depth level (max 6) in the tree. So I try to check depth level using CASE and then add a node to its parent like this (creating a node just for 1st level so far for testing purpose):
export FILEPATH=file:///Example.csv
CREATE CONSTRAINT ON (n:Node) ASSERT n.id IS UNIQUE;
USING PERIODIC COMMIT 500
LOAD CSV WITH HEADERS
FROM {FILEPATH} AS line
WITH DISTINCT line,
line.`Level` AS level,
line.`ParentCodeID_Cal` AS parentCode,
line.`CodeSet` AS codeSet,
line.`Category` AS nodeCategory,
line.`Type` AS nodeType,
line.`L1code` AS l1Code, line.`L1Description` AS l1Description, line.`L1Name` AS l1Name, line.`L1NameAb` AS l1NameAb,
line.`L2code` AS l2Code, line.`L2Description` AS l2Description, line.`L2Name` AS l2Name, line.`L2NameAb` AS l2NameAb,
line.`L3code` AS l3Code, line.`L3Description` AS l3Description, line.`L3Name` AS l3Name, line.`L3NameAb` AS l3NameAb,
line.`L1code` AS l4Code, line.`L4Description` AS l4Description, line.`L4Name` AS l4Name, line.`L4NameAb` AS l4NameAb,
line.`L1code` AS l5Code, line.`L5Description` AS l5Description, line.`L5Name` AS l5Name, line.`L5NameAb` AS l5NameAb,
line.`L1code` AS l6Code, line.`L6Description` AS l6Description, line.`L6Name` AS l6Name, line.`L6NameAb` AS l6NameAb,
codeSet + parentCode AS nodeId
CASE line.`Level`
WHEN '1' THEN CREATE (n0:Node{id:nodeId, description:l1Description, name:l1Name, nameAb:l1NameAb, category:nodeCategory, type:nodeType})
ELSE
END;
But I get this result:
WARNING: Invalid input 'S': expected 'l/L' (line 17, column 3 (offset:
982)) "CASE level " ^
I'm aware there is a mistake at syntax.
I'm using neo4j 3.0.4 & Windows 10 (using neo4j shell running it with D:\Program Files\Neo4j CE 3.0.4\bin>java -classpath neo4j-desktop-3.0.4.jar org.neo4j.shell.StartClient).
You have several syntax errors. For example, a CASE clause cannot contain a CREATE clause.
In any case, you should be able to greatly simplify your Cypher. For example, this might suit your needs:
USING PERIODIC COMMIT 500
LOAD CSV WITH HEADERS
FROM {FILEPATH} AS line
WITH DISTINCT line, ('l' + line.Level) AS prefix
CREATE (:Node{
id: line.CodeSet + line.ParentCodeID_Cal,
description: line[prefix + 'Description'],
name: line[prefix + 'Name'],
nameAb: line[prefix + 'NameAb'],
category: line.Category,
type: line.Type})
I am trying to get erlang-mysql-driver working, I managed to set it up and make queries but there are two things I cannot do.(https://code.google.com/archive/p/erlang-mysql-driver/issues)
(BTW, I am new to Erlang)
So Here is my code to connect MySQL.
<erl>
out(Arg) ->
mysql:start_link(p1, "127.0.0.1", "root", "azzkikr", "MyDB"),
{data, Result} = mysql:fetch(p1, "SELECT * FROM messages").
</erl>
1. I cannot get data from table.
mysql.erl doesn't contain any specific information on how to get table datas but this is the farthest I could go.
{A,B} = mysql:get_result_rows(Result),
B.
And the result was this:
ERROR erlang code threw an uncaught exception:
File: /Users/{username}/Sites/Yaws/index.yaws:1
Class: error
Exception: {badmatch,[[4,0,<<"This is done baby!">>,19238],
[5,0,<<"Success">>,19238],
[6,0,<<"Hello">>,19238]]}
Req: {http_request,'GET',{abs_path,"/"},{1,1}}
Stack: [{m181,out,1,
[{file,"/Users/{username}/.yaws/yaws/default/m181.erl"},
{line,18}]},
{yaws_server,deliver_dyn_part,8,
[{file,"yaws_server.erl"},{line,2818}]},
{yaws_server,aloop,4,[{file,"yaws_server.erl"},{line,1232}]},
{yaws_server,acceptor0,2,[{file,"yaws_server.erl"},{line,1068}]},
{proc_lib,init_p_do_apply,3,[{file,"proc_lib.erl"},{line,240}]}]
I understand that somehow I need to get second element and use foreach to get each data but strings are returned in different format like queried string is Success but returned string is <<"Success">>.
{badmatch,[[4,0,<<"This is done baby!">>,19238],
[5,0,<<"Success">>,19238],
[6,0,<<"Hello">>,19238]]}
First Question is: How do I get datas from table?
2. How to insert values into table using variables?
I can insert data into table using this method:
Msg = "Hello World",
mysql:prepare(add_message,<<"INSERT INTO messages (`message`) VALUES (?)">>),
mysql:execute(p1, add_message, [Msg]).
But there are two things I am having trouble,
1. I am inserting data without << and >> operators, because When I do Msg = << ++ "Hello World" >>, erlang throws out an exception (I think I am doing something wrong), i don't know wether they are required but without them I am able to insert data into table except this error bothers me after execution:
yaws code at /Users/{username}/Yaws/index.yaws:1 crashed or ret bad val:{updated,
{mysql_result,
[],
[],
1,
[]}}
Req: {http_request,'GET',{abs_path,"/"},{1,1}}
returned atom is updated while I commanded to insert data.
Question 2 is: How do I insert data into table in a proper way?
Error:
{badmatch,[[4,0,<<"This is done baby!">>,19238],
[5,0,<<"Success">>,19238],
[6,0,<<"Hello">>,19238]]}
Tells you that returned values is:
[[4,0,<<"This is done baby!">>,19238],
[5,0,<<"Success">>,19238],
[6,0,<<"Hello">>,19238]]
Which obviously can't match with either {data, Data} nor {A, B}. You can obtain your data as:
<erl>
out(Arg) ->
mysql:start_link(p1, "127.0.0.1", "root", "azzkikr", "MyDB"),
{ehtml,
[{table, [{border, "1"}],
[{tr, [],
[{td, [],
case Val of
_ when is_binary(Val) -> yaws_api:htmlize(Val);
_ when is_integer(val) -> integer_to_binary(Val)
end}
|| Val <- Row
]}
|| Row <- mysql:fetch(p1, "SELECT * FROM messages")
]}
]
}.
</erl>
I've below input string from source and I am using mssql database to
Load the data into a table, but I'm getting below error from tables:
Error from Component 'LOADP51file.Output_Table_1__table_.load', Partition 0 [U103,DB00156,DB16000,DB00250] ABINITIO(DB00156): Put row failed for db statement ABINITIO(DB16000): ODBC Error ABINITIO(DB16000): SQLCODE: 0 ABINITIO(DB16000): SQLSTATE: 22001 ABINITIO(DB16000): MESSAGE: [Microsoft][ODBC Driver 11 for SQL Server]String data, right truncation ABINITIO(DB00250): Rejected record value: ABINITIO(DB00250): [record id "140426924" check_valt "0" description "IT IND UTP 33 £1 3D Multi ST" style_code "000000"
I've observed that the above error is occurred only due to the column "description". Is it because of the £1 coming from source?
Input data 140426924|0|IT IND UTP 33 £1 3D Multi ST|000000
Input dml: string(9) id; string(1) check_valt ; string(30) description ; string(6) style_code ;
Output table DML: record string("\x01",charset="windows-1252", maximum_length=9) id
/*VARCHAR(9) NOT NULL*/; string("\x01",charset="windows-1252", maximum_length=1) check_valt = NULL("") /*CHAR(1)*/; string("\x01",charset="windows-1252", maximum_length=30) description = NULL("") /*VARCHAR(30)*/; string("\x01",charset="windows-1252", maximum_length=6) style_code = NULL("") /*VARCHAR(6)*/; end;
Try this:
out.description :: string_convert_explicit(in.description,"windows-1252","");
Also, if truncation is the issue:
out.description :: string_substring(string_convert_explicit(in.description,"windows-1252",""),1,30);
Please try to keep the character set as utf8.
Let us know if that works.
Thanks
Arijit
Try to use a "Redefine Format" component before the output table component and convert it to "window-1252". Until then perform all the operations in ASCII or UTF-8.
I am having a group_var/all file whose starting lines look exactly like this :
##################################
['./roles/openssh/defaults',
'./roles/rsyslog/defaults',
'./roles/tomcat8/defaults',
'./roles/oracle_java/defaults',
'./roles/psp_db/defaults',
'./roles/provision_kill_instance/defaults',
'./roles/kill_app/defaults',
'./roles/base/defaults',
'./roles/ntp/defaults']
##################################
base_google_dns_enabled: false
when i run it as ansible-playbook provision_aws.yml it throws a error :
ERROR: Syntax Error while loading YAML script, /home/nsingh/ansible-psportal/group_vars/all
Note: The error may actually appear before this position: line 13, column 1
base_google_dns_enabled: false
According to my diagnosis , this is because of the things inside [] , even if i put this at the end of my group_vars i encounter something similar. Any Help Would be highly appreciated.
Your syntax looks incorrect. Try:
---
myroles:
- './roles/openssh/defaults'
- './roles/rsyslog/defaults'
- './roles/tomcat8/defaults'
- './roles/oracle_java/defaults'
- './roles/psp_db/defaults'
- './roles/provision_kill_instance/defaults'
- './roles/kill_app/defaults'
- './roles/base/defaults'
- './roles/ntp/defaults'
base_google_dns_enabled: false
First of all I must say that I have somewhat basic knowledge of sql server and with that I'm trying to figure out how to resolve a deadlock.
I ran dbcc traceon (1204, -1), executed the culprit code and finally executed the xp_readerrorlog stored proc which gave me the following output:
Deadlock encountered .... Printing deadlock information
Wait-for graph
NULL
Node:1
OBJECT: 9:1093578934:0 CleanCnt:2 Mode:IX Flags: 0x1
Grant List 2:
Grant List 3:
Owner:0x000000008165A780 Mode: IX Flg:0x40 Ref:2 Life:02000000 SPID:57 ECID:0 XactLockInfo: 0x0000000082F00EC0
SPID: 57 ECID: 0 Statement Type: EXECUTE Line #: 1
Input Buf: RPC Event: Proc [Database Id = 9 Object Id = 1877581727]
Requested by:
ResType:LockOwner Stype:'OR'Xdes:0x0000000082E02E80 Mode: S SPID:56 BatchID:0 ECID:0 TaskProxy:(0x00000000826EE538) Value:0x81a6f9c0 Cost:(0/1492)
NULL
Node:2
APPLICATION: 9:0:[Proligent Analytics]:(6ff56412) CleanCnt:2 Mode:X Flags: 0x5
Grant List 2:
Owner:0x000000008165DE40 Mode: X Flg:0x40 Ref:1 Life:00000000 SPID:56 ECID:0 XactLockInfo: 0x0000000082E02EC0
SPID: 56 ECID: 0 Statement Type: OPEN CURSOR Line #: 27
Input Buf: RPC Event: Proc [Database Id = 9 Object Id = 1966630049]
Requested by:
ResType:LockOwner Stype:'OR'Xdes:0x0000000082F00E80 Mode: X SPID:57 BatchID:0 ECID:0 TaskProxy:(0x00000000827B8538) Value:0x83e29d40 Cost:(0/250576)
NULL
Victim Resource Owner:
ResType:LockOwner Stype:'OR'Xdes:0x0000000082E02E80 Mode: S SPID:56 BatchID:0 ECID:0 TaskProxy:(0x00000000826EE538) Value:0x81a6f9c0 Cost:(0/1492)
My problem is that I have no idea how to use this to find out what's going on. I've read that you can get the stored procedure that is getting locked but I don't know how.
Please a few pointers would be appreciated.
Thanks
As #Martin Smith says in his comment: select db_name(9), object_name(1093578934,9), object_name(1966630049,9), object_name(1877581727,9) should give you some of the objects.