5

我目前正在研究 ArangoDB POC。我发现使用 PyArango 在 ArangoDB 中创建文档所花费的时间非常长。插入 300 个文档大约需要 5 分钟。我已经粘贴了下面的粗略代码,如果有更好的方法可以加快速度,请告诉我:

with open('abc.csv') as fp:
for line in fp:
    dataList = line.split(",")

    aaa = dbObj['aaa'].createDocument()
    bbb = dbObj['bbb'].createDocument() 
    ccc = dbObj['ccc'].createEdge()

    bbb['bbb'] = dataList[1]
    aaa['aaa'] = dataList[0]
    aaa._key = dataList[0]

    aaa.save()
    bbb.save()

    ccc.links(aaa,bbb)
    ccc['related_to'] = "gfdgf"
    ccc['weight'] = 0

    ccc.save()

不同的集合由以下代码创建:

 dbObj.createCollection(className='aaa', waitForSync=False)
4

2 回答 2

4

对于您在 arango java 驱动程序中的批处理模式的问题。如果您知道顶点的关键属性,您可以通过“collectionName”+“/”+“documentKey”构建文档句柄。例子:

arangoDriver.startBatchMode();

for(String line : lines)
{
  String[] data = line.split(",");

  BaseDocument device = new BaseDocument();
  BaseDocument phyAddress = new BaseDocument(); 
  BaseDocument conn = new BaseDocument();

  String keyDevice = data[0];
  String handleDevice = "DeviceId/" + keyDevice; 

  device.setDocumentKey(keyDevice);

  device.addAttribute("device_id",data[0]);

  String keyPhyAddress = data[1];
  String handlePhyAddress = "PhysicalLocation/" + keyPhyAddress; 

  phyAddress.setDocumentKey(keyPhyAddress);

  phyAddress.addAttribute("address",data[1]);

  final DocumentEntity<BaseDocument> from = arangoDriver.graphCreateVertex("testGraph", "DeviceId", device, null);       
  final DocumentEntity<BaseDocument> to = arangoDriver.graphCreateVertex("testGraph", "PhysicalLocation", phyAddress, null);

  arangoDriver.graphCreateEdge("testGraph", "DeviceId_PhysicalLocation", null, handleDevice, handlePhyAddress, null, null);

}
arangoDriver.executeBatch();
于 2016-08-18T12:56:33.843 回答
0

我将构建要插入到 json 格式字符串中的所有数据,并使用 createDocumentRaw 一次保存所有数据。

于 2016-08-16T15:56:06.813 回答