我在执行以下代码时遇到了问题:
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();
}
}
下面的密码查询将无休止地运行:
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})
感谢您的帮助!
2条答案
按热度按时间shstlldc1#
这里有7个嵌套的循环,它们占了13^7次迭代,即超过6200万次迭代。要么查询永远不会完成,因为它耗尽了内存,要么它只是需要(很多)时间。
如果你只需要创建13个
CT11000000
节点,你可以定义一个UNWIND
,并使用一个包含13个map的列表:边注:请看看密码风格指南,标签和属性的情况下是相当不寻常的在这里
z9smfwbn2#
一个更简单的替代@fbiville的查询: