插入

插入点(node)数据

插入点name分别为Xu Sheng 、Chen Sheng ,age分别为18、28的2个点:

InsertNodeRequest request = new InsertNodeRequest();
request.setNodes(
Arrays.asList(
Node.newBuilder()
	.value(
        Value.newBuilder()
            .add("name", "Xu Sheng")
            .add("age", 18)
            .build()
            )
        .build(),
        Node.newBuilder()
            .value(
        Value.newBuilder()
            .add("name", "Chen Sheng")
            .add("age", 28)
            .build()
		)
.build()
)
);
List<NodeAlias> result = client.insertNode(request);
println(result);

批量插入

如果是批量插入推荐用batch:

BatchInsertNodesRequest request = new BatchInsertNodesRequest();
Header nameHeader = Header.newBuilder()
	.setPropertyName("name").setPropertyType(UltipaPropertyType.PROPERTY_STRING)
.build();
Header ageHeader = Header.newBuilder()
	.setPropertyName("age").setPropertyType(UltipaPropertyType.PROPERTY_INT32)
.build();
ByteString nameBytes = ByteString.copyFrom(UltipaSerializer.serializeString(name));
ByteString ageBytes = ByteString.copyFrom(UltipaSerializer.serializeInt32(age));
NodeRow nodeRow = NodeRow.newBuilder()
.addAllValues(Arrays.asList(nameBytes, ageBytes)).build();
NodeTable nodeTable = NodeTable.newBuilder()
.addHeaders(nameHeader)
.addHeaders(ageHeader)
.addNodeRows(nodeRow)
.build();
request.setNodeTable(nodeTable);
Result result = client.batchInsertNodes(request);

插入边(edge)数据

InsertEdgeRequest request = new InsertEdgeRequest();
request.setEdges(Arrays.asList(
Edge.newBuilder()
.fromId(2L)
.toId(1L)
.value(
	Value.newBuilder()
		.add("rank", 60)
		.build()
	).build(),
	    Edge.newBuilder()
.fromId(2L)
.toId(5L)
.value(
	Value.newBuilder()
		.add("rank", 50)
		.build()
		).build()
	));
List<EdgeAlias> result = client.insertEdge(request);
println(result);

批量插入

BatchInsertEdgesRequest request = new BatchInsertEdgesRequest();
Header header = Header.newBuilder()
	.setPropertyName("name")
	.setPropertyType(UltipaPropertyType.PROPERTY_STRING)
	.build();
ByteString bs = 
ByteString.copyFrom(UltipaSerializer.serializeString("t_j_greet_1"));
EdgeRow edgeRow = 
	EdgeRow.newBuilder()
	.setFromId(1).setToId(2)
	.addAllValues(Arrays.asList(bs)).build();
EdgeTable edgeTable = EdgeTable.newBuilder()
		.addAllHeaders(Arrays.asList(header))
		.addAllEdgeRows(Arrays.asList(edgeRow)).build();
request.setEdgeTable(edgeTable);
client.batchInsertEdges(request);

静默插入

request.setSilent(true)即可。

InsertNodeRequest request = new InsertNodeRequest();
request.setNodes(
Arrays.asList(
Node.newBuilder()
		.value(
Value.newBuilder()
			.add("name", "Xu Sheng")
			.add("age", 18)
	.build()
)
	.build(),
Node.newBuilder()
	.value(
	   Value.newBuilder()
			.add("name", "Chen Sheng")
			.add("age", 28)
		.build()
	   )
	.build()
)
);
request.setSilent(true);
client.insertNode(request);

_o插入

request.setCheckO(true)

InsertNodeRequest request = new InsertNodeRequest();
request.setNodes(
Arrays.asList(
Node.newBuilder()
		.value(
Value.newBuilder()
        .add("_o", "1")
		.add("name", "Xu Sheng")
		.add("age", 18)
	.build()
)
	.build(),
Node.newBuilder()
	.value(
	   Value.newBuilder()
      		.add("_o", "2")
			.add("name", "Chen Sheng")
			.add("age", 28)
		.build()
	   )
	.build()
)
);
request.setCheckO(true);
client.insertNode(request);