MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / parse_int_attr

Function parse_int_attr

nodedb-cluster-tests/tests/bitemporal_array_cluster.rs:64–81  ·  view source on GitHub ↗

Parse the `attrs[0]` int64 from a single ARRAY_SLICE result row. `SELECT *` over ARRAY_SLICE expands to one pgwire field per declared column. This test uses the column-0 helper, which lands on the `attrs` JSON-array column for the slice TVF (e.g. `[99]`). Older codecs returned the full `{"coords": [...], "attrs": [v]}` envelope in that slot — accept either shape so the test stays robust to the

(row: &str)

Source from the content-addressed store, hash-verified

62/// in that slot — accept either shape so the test stays robust to the
63/// projection tightening.
64fn parse_int_attr(row: &str) -> i64 {
65 let v: serde_json::Value =
66 serde_json::from_str(row).unwrap_or_else(|e| panic!("row is not JSON: {row}: {e}"));
67 let arr = match v {
68 // Bare attrs array — `[99]`.
69 serde_json::Value::Array(a) => a,
70 // Envelope with `attrs` field.
71 serde_json::Value::Object(map) => map
72 .get("attrs")
73 .and_then(|a| a.as_array())
74 .cloned()
75 .unwrap_or_else(|| panic!("envelope missing attrs array: {row}")),
76 _ => panic!("row is neither array nor object: {row}"),
77 };
78 arr.first()
79 .and_then(|n| n.as_i64())
80 .unwrap_or_else(|| panic!("cannot extract attrs[0] as i64 from: {row}"))
81}
82
83/// Bring up a 3-node cluster, write v1 then v2 of a cell at coord `x=0`,
84/// capturing the system-time cutoff between the two writes. Assert that

Calls 4

as_arrayMethod · 0.80
firstMethod · 0.80
getMethod · 0.45
as_i64Method · 0.45

Tested by

no test coverage detected