graph - 将批量数据导入 ArangoDB 的最佳方法

标签 graph arangodb pyarango

我目前正在研究 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)

最佳答案

对于您在 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();

关于graph - 将批量数据导入 ArangoDB 的最佳方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38979072/

相关文章:

algorithm - 表示图形的数据结构

arangodb - 检索 arangodb 中没有链接边的顶点

ArangoDB:图形查看器中边和顶点的自定义标签

algorithm - 图表中的移动可达性

algorithm - 找到最大匹配

java - 为什么 Queue<Integer> 在这里返回 Iterable<Integer> ?

browser - arangodb 服务器连接被拒绝

Python - 如何在 ArangoDB 中创建边

arangodb - pyArango 与 Foxx 微服务