cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

If property names can contain "%20", why can't apoc.refactor.rename.nodeProperty work with them?

Summary:
I have a use case where we anticipate loading labels and properties with "%20" (spaces) in their names, and so have a requirement to clean those names after they've been imported.

I can fix labels using apoc.refactor.rename.label, but cannot do the same for properties using apoc.refactor.rename.nodeProperty due to the implicit invocation of "EXPLAIN", which fails to wrap the nodeProperty name in backticks (`).

For example, take this RDF:

@prefix n4sch: <neo4j://graph.schemaspaces#> .
n4sch:Subject a n4sch:Class%20With%20Spaces;
  n4sch:nodeProperty%20with%20spaces "Subject";
  n4sch:CLASS_RELATES_TO n4sch:Sex .
n4sch:Sex a n4sch:Class;
  n4sch:label "Sex" .

This approach for fixing labels works as expected, using apoc.refactor.rename.label:

    UNWIND ['Resource', 'Class', 'Class%20With%20Spaces'] as label
    CALL apoc.refactor.rename.label(label, apoc.text.regreplace(label, '%20', ' '))
    YIELD batches, failedBatches, total, failedOperations
    RETURN batches, failedBatches, total, failedOperations

However, using the equivalent approach for Properties:

UNWIND ['nodeProperty%20with%20spaces', 'uri'] as label
CALL apoc.refactor.rename.nodeProperty(label, apoc.text.regreplace(label, '%20', ' '))
YIELD batches, failedBatches, total, failedOperations 
RETURN batches, failedBatches, total, failedOperations

results in:

neo4j.exceptions.ClientError: {code: Neo.ClientError.Procedure.ProcedureCallFailed} {message: Failed to invoke procedure `apoc.refactor.rename.nodeProperty`: Caused by: org.neo4j.exceptions.SyntaxException: invalid literal number (line 1, column 48 (offset: 47))
"EXPLAIN match (n) where exists (n.nodeProperty%20with%20spaces) return n"

Surrounding the property name with backticks doesn't cause error;

EXPLAIN match (n) where exists (n.`nodeProperty%20with%20spaces`) return n

Unfortunately this is out of user's control and is a characteristic of apoc.refactor.rename.nodeProperty.

Is there another approach to this, or is this a bug within the procedure apoc.refactor.rename.nodeProperty?

1 REPLY 1

andreperez
Graph Buddy

Maybe this can help, it's an apoc function that can decode this type of URL chars