imbajin commented on code in PR #683:
URL:
https://github.com/apache/incubator-hugegraph-toolchain/pull/683#discussion_r2458904320
##########
hugegraph-loader/src/main/java/org/apache/hugegraph/loader/HugeGraphLoader.java:
##########
@@ -153,11 +270,286 @@ private void createSchema() {
throw new LoadException("Failed to read schema file '%s'", e,
options.schema);
}
- groovyExecutor.execute(script, client);
+
+ if (!options.shorterIDConfigs.isEmpty()) {
+ for (ShortIdConfig config : options.shorterIDConfigs) {
+ PropertyKey propertyKey =
client.schema().propertyKey(config.getIdFieldName())
+ .ifNotExist()
+
.dataType(config.getIdFieldType())
+ .build();
+ client.schema().addPropertyKey(propertyKey);
+ }
+ groovyExecutor.execute(script, client);
+ List<VertexLabel> vertexLabels =
client.schema().getVertexLabels();
+ for (VertexLabel vertexLabel : vertexLabels) {
+ ShortIdConfig config;
+ if ((config =
options.getShortIdConfig(vertexLabel.name())) != null) {
+ config.setLabelID(vertexLabel.id());
+ IndexLabel indexLabel = client.schema()
+
.indexLabel(config.getVertexLabel() + "By" +
+
config.getIdFieldName())
+
.onV(config.getVertexLabel())
+
.by(config.getIdFieldName())
+ .secondary()
+ .ifNotExist()
+ .build();
+ client.schema().addIndexLabel(indexLabel);
+ }
+ }
+ } else {
+ groovyExecutor.execute(script, client);
+ }
+ }
+
+ // create schema for Graph Source
+ List<InputStruct> structs = this.mapping.structs();
+ for (InputStruct struct : structs) {
+ if (SourceType.GRAPH.equals(struct.input().type())) {
+ GraphSource graphSouce = (GraphSource) struct.input();
+ if (StringUtils.isEmpty(graphSouce.getPdPeers())) {
+ graphSouce.setPdPeers(this.options.pdPeers);
+ }
+ if (StringUtils.isEmpty(graphSouce.getMetaEndPoints())) {
+ graphSouce.setMetaEndPoints(this.options.metaEndPoints);
+ }
+ if (StringUtils.isEmpty(graphSouce.getCluster())) {
+ graphSouce.setCluster(this.options.cluster);
+ }
+ if (StringUtils.isEmpty(graphSouce.getUsername())) {
+ graphSouce.setUsername(this.options.username);
+ }
+ if (StringUtils.isEmpty(graphSouce.getPassword())) {
+ graphSouce.setPassword(this.options.password);
+ }
+
+ GraphSource graphSource = (GraphSource) struct.input();
+ createGraphSourceSchema(graphSource);
+ }
}
+
this.context.updateSchemaCache();
}
+ /**
+ * create schema like graphdb when source is graphdb;
+ *
+ * @param graphSource
Review Comment:
⚠️ **HugeClient 资源泄漏**: `createGraphSourceSchema` 方法中创建的 `sourceClient` 和
`client` 使用 try-with-resources,但如果在 schema 创建过程中抛出异常,可能导致部分操作未完成。
**建议**: 添加异常处理和清理日志:
```java
try (HugeClient sourceClient = graphSource.createHugeClient();
HugeClient client = HugeClientHolder.create(this.options, false)) {
createGraphSourceVertexLabel(sourceClient, client, graphSource);
createGraphSourceEdgeLabel(sourceClient, client, graphSource);
createGraphSourceIndexLabel(sourceClient, client, graphSource);
} catch (Exception e) {
LOG.error("Failed to create graph source schema for {}: {}",
graphSource.getGraph(), e.getMessage(), e);
throw new LoadException("Schema creation failed", e);
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]