Insertion

Insert Node

Single Insertion

Example: Insert two nodes with names 'Xu Sheng' and 'Chen Sheng', and ages 18 and 28:

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 Insertion

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);

Insert Edge

Single Insertion

Example: Insert two edges, one of which is from node ( id = 2 ) to node ( id = 1 ) and rank = 60, the other is from node ( id = 2 ) to node ( id = 5 ) and rank = 50

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

Batch Insertion

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);

Silent Mode

Turn on silent insertion mode with 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);