neo4j / apoc

Apache License 2.0
96 stars 28 forks source link

[DUPLICATED] Round trip with apoc graphml coerces types to string #44

Closed neo-technology-build-agent closed 2 years ago

neo-technology-build-agent commented 2 years ago

Issue by Rosswart Tuesday Jul 20, 2021 at 10:03 GMT Originally opened as https://github.com/neo4j-contrib/neo4j-apoc-procedures/issues/2099


Expected Behavior

Exporting a graph with

    CALL apoc.export.graphml.all('types.graphml', {useTypes: true, storeNodeIds: false})

into graphml

    <?xml version="1.0" encoding="UTF-8"?>
    <graphml xmlns="http://graphml.graphdrawing.org/xmlns" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://graphml.graphdrawing.org/xmlns http://graphml.graphdrawing.org/xmlns/1.0/graphml.xsd">
    <key id="b" for="node" attr.name="b" attr.type="string"/>
    <key id="c" for="node" attr.name="c" attr.type="string" attr.list="string"/>
    <key id="d" for="node" attr.name="d" attr.type="long"/>
    <graph id="G" edgedefault="directed">
    <node id="n0"><data key="a">string</data><data key="b">string</data></node>
    <node id="n1"><data key="a">string</data><data key="b">string</data></node>
    <node id="n2"><data key="a">["array","string"]</data><data key="c">["array","string"]</data></node>
    <node id="n3"><data key="a">["array","string"]</data><data key="c">["array","string"]</data></node>
    <node id="n4"><data key="a">123</data><data key="d">123</data></node>
    <node id="n5"><data key="a">123</data><data key="d">123</data></node>
    </graph>
    </graphml>

and then importing this again with

    CALL apoc.import.graphml('types.graphml', {readLabels: true})

should reproduce the same graph

    MATCH (n)
    RETURN
      apoc.meta.type(n.a), n.a,
      apoc.meta.type(n.b), n.b,
      apoc.meta.type(n.c), n.c,
      apoc.meta.type(n.d), n.d

with all properties having the same type as in the original graph:

    ╒═════════════════════╤══════════════════╤═════════════════════╤════════╤═════════════════════╤══════════════════╤═════════════════════╤═════╕
    │"apoc.meta.type(n.a)"│"n.a"             │"apoc.meta.type(n.b)"│"n.b"   │"apoc.meta.type(n.c)"│"n.c"             │"apoc.meta.type(n.d)"│"n.d"│
    ╞═════════════════════╪══════════════════╪═════════════════════╪════════╪═════════════════════╪══════════════════╪═════════════════════╪═════╡
    │"STRING"             │"string"          │"STRING"             │"string"│"NULL"               │null              │"NULL"               │null │
    ├─────────────────────┼──────────────────┼─────────────────────┼────────┼─────────────────────┼──────────────────┼─────────────────────┼─────┤
    │"STRING"             │"string"          │"STRING"             │"string"│"NULL"               │null              │"NULL"               │null │
    ├─────────────────────┼──────────────────┼─────────────────────┼────────┼─────────────────────┼──────────────────┼─────────────────────┼─────┤
    │"String[]"           │["array","string"]│"NULL"               │null    │"String[]"           │["array","string"]│"NULL"               │null │
    ├─────────────────────┼──────────────────┼─────────────────────┼────────┼─────────────────────┼──────────────────┼─────────────────────┼─────┤
    │"String[]"           │["array","string"]│"NULL"               │null    │"String[]"           │["array","string"]│"NULL"               │null │
    ├─────────────────────┼──────────────────┼─────────────────────┼────────┼─────────────────────┼──────────────────┼─────────────────────┼─────┤
    │"INTEGER"            │123               │"NULL"               │null    │"NULL"               │null              │"INTEGER"            │123  │
    ├─────────────────────┼──────────────────┼─────────────────────┼────────┼─────────────────────┼──────────────────┼─────────────────────┼─────┤
    │"INTEGER"            │123               │"NULL"               │null    │"NULL"               │null              │"INTEGER"            │123  │
    └─────────────────────┴──────────────────┴─────────────────────┴────────┴─────────────────────┴──────────────────┴─────────────────────┴─────┘

Actual Behavior

If the original node properties are of mixed type (see "n.a"), then the imported properties are coerced to string. All properties with pure types do have the original type.

    ╒═════════════════════╤════════════════════╤═════════════════════╤════════╤═════════════════════╤══════════════════╤═════════════════════╤═════╕
    │"apoc.meta.type(n.a)"│"n.a"               │"apoc.meta.type(n.b)"│"n.b"   │"apoc.meta.type(n.c)"│"n.c"             │"apoc.meta.type(n.d)"│"n.d"│
    ╞═════════════════════╪════════════════════╪═════════════════════╪════════╪═════════════════════╪══════════════════╪═════════════════════╪═════╡
    │"STRING"             │"string"            │"STRING"             │"string"│"NULL"               │null              │"NULL"               │null │
    ├─────────────────────┼────────────────────┼─────────────────────┼────────┼─────────────────────┼──────────────────┼─────────────────────┼─────┤
    │"STRING"             │"string"            │"STRING"             │"string"│"NULL"               │null              │"NULL"               │null │
    ├─────────────────────┼────────────────────┼─────────────────────┼────────┼─────────────────────┼──────────────────┼─────────────────────┼─────┤
    │"STRING"             │"["array","string"]"│"NULL"               │null    │"String[]"           │["array","string"]│"NULL"               │null │
    ├─────────────────────┼────────────────────┼─────────────────────┼────────┼─────────────────────┼──────────────────┼─────────────────────┼─────┤
    │"STRING"             │"["array","string"]"│"NULL"               │null    │"String[]"           │["array","string"]│"NULL"               │null │
    ├─────────────────────┼────────────────────┼─────────────────────┼────────┼─────────────────────┼──────────────────┼─────────────────────┼─────┤
    │"STRING"             │"123"               │"NULL"               │null    │"NULL"               │null              │"INTEGER"            │123  │
    ├─────────────────────┼────────────────────┼─────────────────────┼────────┼─────────────────────┼──────────────────┼─────────────────────┼─────┤
    │"STRING"             │"123"               │"NULL"               │null    │"NULL"               │null              │"INTEGER"            │123  │
    └─────────────────────┴────────────────────┴─────────────────────┴────────┴─────────────────────┴──────────────────┴─────────────────────┴─────┘

How to Reproduce the Problem

Simple Dataset

    CREATE ({a: "string",           b: "string"})
    CREATE ({a: "string",           b: "string"})
    CREATE ({a: ["array", "string", c: ["array", "string"]]})
    CREATE ({a: ["array", "string", c: ["array", "string"]]})
    CREATE ({a: 123,                d: 123})
    CREATE ({a: 123,                d: 123})

Steps (Mandatory)

  1. Create graph
  2. Export
  3. Import

Specifications

Versions

neo-technology-build-agent commented 2 years ago

Comment by Rosswart Tuesday Jul 20, 2021 at 10:05 GMT


I have found these issues which maybe are related