From 074facf11ba0b54c15c99b017b1e57ea8d968ae8 Mon Sep 17 00:00:00 2001 From: 0o-de-lally <1364012+0o-de-lally@users.noreply.github.com> Date: Tue, 26 Nov 2024 16:31:35 -0500 Subject: [PATCH] fix args insert --- src/cypher_templates.rs | 6 +++++- src/json_rescue_v5_load.rs | 8 +++++++- src/schema_transaction.rs | 15 +++++++++------ tests/test_json_rescue_v5_load.rs | 3 --- 4 files changed, 21 insertions(+), 11 deletions(-) diff --git a/src/cypher_templates.rs b/src/cypher_templates.rs index a5b1d80..6c4d3cb 100644 --- a/src/cypher_templates.rs +++ b/src/cypher_templates.rs @@ -16,12 +16,16 @@ MERGE (from)-[rel:Tx {{tx_hash: tx.tx_hash}}]->(to) ON CREATE SET rel.created_at = timestamp(), rel.modified_at = null ON MATCH SET rel.modified_at = timestamp() SET - rel += tx.args, rel.block_datetime = tx.block_datetime, rel.block_timestamp = tx.block_timestamp, rel.relation = tx.relation, rel.function = tx.function +// Conditionally add `tx.args` if it exists +FOREACH (_ IN CASE WHEN tx.args IS NOT NULL THEN [1] ELSE [] END | + SET rel += tx.args +) + WITH rel RETURN diff --git a/src/json_rescue_v5_load.rs b/src/json_rescue_v5_load.rs index 1cec688..e93ac0e 100644 --- a/src/json_rescue_v5_load.rs +++ b/src/json_rescue_v5_load.rs @@ -35,7 +35,13 @@ pub async fn decompress_and_extract(tgz_file: &Path, pool: &Graph) -> Result= LOAD_QUEUE_SIZE { let drain: Vec = std::mem::take(&mut queue); - let res = tx_batch(&drain, pool, QUERY_BATCH_SIZE, j.to_str().unwrap()).await?; + let res = tx_batch( + &drain, + pool, + QUERY_BATCH_SIZE, + j.file_name().unwrap().to_str().unwrap(), + ) + .await?; created_count += res.created_tx as u64; } } diff --git a/src/schema_transaction.rs b/src/schema_transaction.rs index 5259223..0f778ac 100644 --- a/src/schema_transaction.rs +++ b/src/schema_transaction.rs @@ -111,28 +111,31 @@ impl WarehouseTxMaster { /// since no sane Cypher serialization libraries exist. /// and I'm not going to write a deserializer. /// and JSON is not the same format as cypher property maps - /// JSON5 but the last time someone updated + /// I'd use JSON5 but the last time someone updated /// that crate was 3 years ago. pub fn to_cypher_object_template(&self) -> String { - let tx_args = match &self.entry_function { - Some(ef) => to_cypher_object(ef).unwrap_or("null".to_string()), - None => "null".to_owned(), + // make blank string or nest the arguments + let mut tx_args = "NULL".to_string(); + if let Some(args) = &self.entry_function { + if let Ok(st) = to_cypher_object(args) { + tx_args = st; + } }; format!( - r#"{{tx_hash: "{}", block_datetime: datetime("{}"), block_timestamp: {}, relation: "{}", function: "{}", sender: "{}", args: {}, recipient: "{}"}}"#, + r#"{{ args: {maybe_args_here}, tx_hash: "{}", block_datetime: datetime("{}"), block_timestamp: {}, relation: "{}", function: "{}", sender: "{}", recipient: "{}"}}"#, self.tx_hash.to_hex_literal(), self.block_datetime.to_rfc3339(), self.block_timestamp, self.relation_label.to_cypher_label(), self.function, self.sender.to_hex_literal(), - tx_args, // TODO: should be from relation_label.get_recipient self.relation_label .get_recipient() .unwrap_or(self.sender) .to_hex_literal(), + maybe_args_here = tx_args, ) } diff --git a/tests/test_json_rescue_v5_load.rs b/tests/test_json_rescue_v5_load.rs index 7951bc9..f993f79 100644 --- a/tests/test_json_rescue_v5_load.rs +++ b/tests/test_json_rescue_v5_load.rs @@ -46,7 +46,6 @@ async fn test_load_entrypoint() -> anyhow::Result<()> { let path = fixtures::v5_json_tx_path(); let tx_count = json_rescue_v5_load::rip(&path, &pool).await?; - // dbg!(&tx_count); assert!(tx_count == 5244); Ok(()) @@ -60,8 +59,6 @@ async fn test_rescue_v5_parse_set_wallet_tx() -> anyhow::Result<()> { let (vec_tx, _) = extract_v5_json_rescue(&path)?; - dbg!(&vec_tx); - let c = start_neo4j_container(); let port = c.get_host_port_ipv4(7687); let pool = get_neo4j_localhost_pool(port)