{
  "kind": "documentation",
  "format": 1,
  "note": "Reference text, not instructions. One verified relate sample from https://relatedb.ai/docs/guides/embed/c/: the program exactly as the page shows it, the standard output a run of it recorded (npm run docs:samples compares every replay with it byte for byte), the relate client build, toolchain and platform of the last replay, and how the docs' sample runner builds and runs it. Before launch every client is a source build, not a published package; verified.client names the upstream commit it was built from, and verified.docs_engine the build the rest of the docs were recorded from.",
  "id": "metadata",
  "url": "https://relatedb.ai/docs/guides/embed/c/samples/metadata.json",
  "page": {
    "id": "guides/embed/c",
    "title": "Use the C ABI",
    "url": "https://relatedb.ai/docs/guides/embed/c/",
    "md_url": "https://relatedb.ai/docs/guides/embed/c.md"
  },
  "section": {
    "anchor": "read-result-metadata",
    "heading": "Read result metadata",
    "url": "https://relatedb.ai/docs/guides/embed/c/#read-result-metadata"
  },
  "language": "c",
  "client": "C",
  "file": "sample.c",
  "env": null,
  "code": "#include <stdio.h>\n#include \"relate.h\"\n\nstatic const char *TEAM =\n    \"CREATE (ada:Person {name: 'Ada', role: 'engineer'}),\"\n    \"       (grace:Person {name: 'Grace', role: 'engineer'}),\"\n    \"       (noor:Person {name: 'Noor', role: 'maintainer'}),\"\n    \"       (relate:Project {name: 'relate', language: 'Rust'}),\"\n    \"       (tck:Project {name: 'opencypher-tck', language: 'Gherkin'}),\"\n    \"       (ada)-[:WORKS_ON {since: 2024}]->(relate),\"\n    \"       (grace)-[:WORKS_ON {since: 2023}]->(relate),\"\n    \"       (grace)-[:WORKS_ON {since: 2022}]->(tck),\"\n    \"       (noor)-[:MAINTAINS]->(relate),\"\n    \"       (ada)-[:KNOWS]->(grace)\";\n\nstatic int fail(const char *what, char *err) {\n    fprintf(stderr, \"%s failed: %s\\n\", what, err ? err : \"(no detail)\");\n    relate_free_string(err);\n    return 1;\n}\n\nint main(void) {\n    relate_database db = NULL;\n    relate_connection conn = NULL;\n    relate_query_result r = NULL;\n    char *err = NULL;\n    if (relate_database_open(\":memory:\", &db, &err) != RELATE_OK) return fail(\"open\", err);\n    if (relate_connect_namespace(db, NULL, &conn, &err) != RELATE_OK) return fail(\"connect\", err);\n    if (relate_query_params(conn, TEAM, NULL, &r, &err) != RELATE_OK) return fail(\"query\", err);\n    relate_destroy_result(r);\n\n    /* Metadata of a read: every string here is result-owned. */\n    if (relate_query_params(conn, \"MATCH (p:Person) RETURN p.name AS name, p.role AS role\",\n                            NULL, &r, &err) != RELATE_OK) return fail(\"query\", err);\n    for (long long c = 0; c < relate_column_count(r); c++) {\n        printf(\"column %lld: %s\\n\", c, relate_column_name(r, c));\n    }\n    printf(\"rows=%lld query_type=%s namespace=%s\\n\", relate_row_count(r),\n           relate_result_query_type(r), relate_result_namespace(r));\n    printf(\"plan=%s notifications=%s\\n\",\n           relate_result_plan_json(r) ? \"present\" : \"NULL\", relate_result_notifications(r));\n    printf(\"phases within elapsed: %d\\n\",\n           relate_result_parse_ms(r) + relate_result_plan_ms(r) + relate_result_execute_ms(r)\n               <= relate_result_elapsed_ms(r));\n    relate_destroy_result(r);\n\n    /* EXPLAIN plans without running: a plan document and its notifications. */\n    if (relate_query_params(conn, \"EXPLAIN MATCH (p:Person), (q:Project) RETURN p.name, q.name\",\n                            NULL, &r, &err) != RELATE_OK) return fail(\"query\", err);\n    printf(\"query_type=%s rows=%lld\\n\", relate_result_query_type(r), relate_row_count(r));\n    printf(\"notifications=%s\\n\", relate_result_notifications(r));\n    printf(\"plan=%s\\n\", relate_result_plan_json(r));\n    relate_destroy_result(r);\n\n    relate_disconnect(conn);\n    relate_database_close(db);\n    return 0;\n}",
  "code_sha256": "ee4ce66c11a874af018f20fe3c3f8d1f9fcaf59629ac716277166b454b73c64b",
  "source_sha256": "2f6d1cb61ae9075e932b23479b028522cf009e42e929368c8b66a2868c20070e",
  "output": {
    "text": "column 0: name\ncolumn 1: role\nrows=3 query_type=r namespace=neo4j\nplan=NULL notifications=[]\nphases within elapsed: 1\nquery_type=r rows=0\nnotifications=[{\"category\":\"PERFORMANCE\",\"code\":\"Neo.ClientNotification.Statement.CartesianProduct\",\"description\":\"the MATCH patterns share no join anchor\",\"gql_status\":\"03N90\",\"operator_id\":1,\"remedy\":\"Give the patterns a join anchor: reuse a node variable across them, or add a pattern that relates their endpoints; otherwise run them as separate queries.\",\"severity\":\"INFORMATION\",\"title\":\"Cartesian product\"}]\nplan={\"profiled\":false,\"root\":{\"actual\":null,\"children\":[{\"actual\":null,\"children\":[],\"details\":\"(q:Project), (p:Person)\",\"estimated_rows\":null,\"identifiers\":[],\"operator\":\"Expand\",\"warnings\":[{\"category\":\"PERFORMANCE\",\"code\":\"Neo.ClientNotification.Statement.CartesianProduct\",\"description\":\"the MATCH patterns share no join anchor\",\"gql_status\":\"03N90\",\"remedy\":\"Give the patterns a join anchor: reuse a node variable across them, or add a pattern that relates their endpoints; otherwise run them as separate queries.\",\"severity\":\"INFORMATION\",\"title\":\"Cartesian product\"}]}],\"details\":\"2 item(s)\",\"estimated_rows\":null,\"identifiers\":[],\"operator\":\"ProduceResults\",\"warnings\":[]},\"schema\":\"relate.plan/v1\",\"statement\":\"MATCH (p:Person), (q:Project) RETURN p.name, q.name\"}",
    "sha256": "d9a66bc084da8378977f6f9592445dd80538c9b858e74f3f3bc3e77290be4d48"
  },
  "verified": {
    "version": "0.1.2",
    "client": {
      "label": "C",
      "package": "relate.h and librelate_ffi",
      "engine_commit": "f0c09d2",
      "client_commit": "f0c09d2",
      "build": "relate.h and librelate_ffi built from upstream v0.1.2 (f0c09d2) (cargo build -p relate-ffi --release).",
      "toolchain": {
        "cc": "Apple clang 21.0.0"
      }
    },
    "packages": [],
    "replayed": "2026-11-09",
    "platform": "macOS on arm64",
    "docs_engine": {
      "version": "0.1.2",
      "commit": "f0c09d2",
      "source_build": false
    }
  },
  "run": {
    "runner": "npm run docs:samples",
    "setup": "bash scripts/samples/setup.sh --upstream <path to the relate checkout>",
    "variables": [
      "RELATE_CC",
      "RELATE_C_INCLUDE",
      "RELATE_LIB"
    ],
    "program": "<build dir>/sample.c",
    "files": [],
    "build": {
      "command": [
        "$RELATE_CC",
        "-I$RELATE_C_INCLUDE",
        "sample.c",
        "-L<directory of $RELATE_LIB>",
        "-lrelate_ffi",
        "-Wl,-rpath,<directory of $RELATE_LIB>",
        "-o",
        "<build dir>/sample"
      ],
      "environment": {
        "DO_NOT_TRACK": "1"
      },
      "directory": "<build dir>",
      "timeout_s": 600
    },
    "run": {
      "command": [
        "<build dir>/sample"
      ],
      "environment": {
        "DO_NOT_TRACK": "1"
      },
      "directory": "<run dir>",
      "timeout_s": 60
    },
    "passes": "It exits 0 within 60 s and prints at least one line on standard output.",
    "output": "Standard output, with line endings as \\n, trailing spaces and blank lines removed, and the temporary directories' paths written as `.`; standard error is not recorded.",
    "placeholders": {
      "<run dir>": "a fresh, empty temporary directory: the program's working directory, deleted afterwards",
      "<build dir>": "a second fresh temporary directory, where a compiled sample is built",
      "$NAME": "a variable from the env.sh that scripts/samples/setup.sh writes (described in its header)"
    }
  }
}
