在 JanusGraph 中存储字节数组需要什么数据类型?

What data type is required to store a byte array in JanusGraph?

启用自动模式创建后,我可以在属性中存储和检索字节数组,例如:

byte[] myArray = new byte[10];
vertex.property("blob", myArray);
myArray = vertex.value("blob");

但是我似乎没有找到关于何时关闭自动的正确 属性 定义。我已经尝试过 Byte.classCardinality.LIST,结果是:

org.janusgraph.core.SchemaViolationException: Value [[B@a9153e9] is not an instance of the expected data type for property key [payload] and cannot be converted. Expected: class java.lang.Byte, found: class [B

也不支持Byte[].class

Caused by: java.lang.IllegalArgumentException: Not a supported data type: class [Ljava.lang.Byte;

JanusGraph 文档中没有明确提及,但您可以像这样将数据类型定义为 byte[]

gremlin> mgmt = graph.openManagement()
==>org.janusgraph.graphdb.database.management.ManagementSystem@6cae2e4d
gremlin> mgmt.makePropertyKey('blob').dataType(byte[].class).cardinality(Cardinality.SINGLE).make()
==>blob
gremlin> mgmt.commit()
==>null

现在,您可以在 Gremlin 遍历中使用它:

gremlin> g = graph.traversal()
==>graphtraversalsource[standardjanusgraph[berkeleyje:/opt/janusgraph/conf/../db/berkeley], standard]
gremlin> g.addV().property('blob', new byte[10])
==>v[4272]
gremlin> g.V(4272).values('blob').next()
==>[0, 0, 0, 0, 0, 0, 0, 0, 0, 0]

但请注意,不幸的是,目前 JanusGraph 中的 GraphSON 不支持数组。因此,您现在基本上只能使用 Java 中的它们,并将 Gryo 作为序列化程序。有关详细信息,请参阅 JanusGraph/janusgraph#1295

Cardinality.LIST 并非用于存储值数组,而是用于您只想为同一个 属性 拥有多个值的情况,例如用户的多个不同地址.