I have a problem with the execution of the following code:
public static void create(final Session session, final String nodeName, final Map<String, List<Object>> attributes) {
final String create = getCreate(nodeName, attributes);
Logger.getLogger("Neo4jCommands").log(Level.FINE, "Creating node " + nodeName);
try {
session.executeWriteWithoutResult(tx -> {
var query = new Query(create);
tx.run(query);
}, TransactionConfig.builder().withTimeout(Duration.of(30, ChronoUnit.SECONDS)).build());
} catch (final Exception e) {
if (create.length() > 3000) {
Logger.getLogger("Neo4jCommands").log(Level.SEVERE, "Failed create: " + create.substring(0, 3000));
;
} else {
Logger.getLogger("Neo4jCommands").log(Level.SEVERE, "Failed create: " + create);
}
throw new RuntimeException(e);
} finally {
session.close();
}
}
The following cypher query runs endless:
UNWIND [6432013617038820698, 6432013617038820698, 6432013617038820698, 6432013617038820698, 6432013617038820698, 6432013617038820698, 6432013617038820698, 6432013617038820698, 6432013617038820698, 6432013617038820698, 6432013617038820698, 6432013617038820698, 6432013617038820698] AS A
UNWIND [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13] AS B
UNWIND ['1000000', '1000000', '1000000', '1000000', '1000000', '1000000', '1000000', '1000000', '1000000', '1000000', '1000000', '1000000', '1000000'] AS C
UNWIND ['Attribute101', 'Attribute102', 'Attribute103', 'Attribute104', 'Attribute105', 'Attribute106', 'Attribute107', 'Attribute108', 'Attribute109', 'Attribute110', 'Attribute111', 'Attribute112', 'Attribute113'] AS D
UNWIND [4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4] AS E
UNWIND ['1000161', '1000162Text', '1000163', '1000164Text', '1000165', '1000166Text', '1000167', '1000168Text', '1000169', '1000170Text', '1000171', '1000172Text', '1000173'] AS F
UNWIND [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1] AS G
CREATE (:CT11000000 {VA: A, VB: B, VC: C, VD: D, VE: E, VF: F, VG: G})
Thank you for help!
You've got 7 nested loops here, that account for 13^7 iterations, i.e. more than 62 million iterations. Either the query never completes because it runs out of memory or it just needs (a lot of) time.
If you only need to create 13 CT11000000
nodes, you could instead define a single UNWIND
with a single list of 13 maps:
UNWIND [
{A: 6432013617038820698, B: 1, C: '1000000', D: 'Attribute101', E: 4, F: '1000161', G: 1}
// [...] + 12 other maps
] AS attributes
CREATE (:CT11000000 {VA: attributes.A, VB: attributes.B, VC: attributes.C, VD: attributes.D, VE: attributes.E, VF: attributes.F, VG: attributes.G})
Side note: please have a look at the Cypher style guide, the label and properties' case are quite unusual here