如题
scan不支持排序,支持分页,参考该帖子
import com.vesoft.nebula.client.graph.NebulaClient;
import com.vesoft.nebula.client.graph.exception.ExecuteException;
import com.vesoft.nebula.client.graph.response.ScanResponse;
public class NebulaPaginationExample {
public static void main(String[] args) {
NebulaClient nebulaClient = new NebulaClient.Builder()
.withAddress("127.0.0.1")
.withPort(9669)
.withSpace("your_space")
.build();
try {
String startVid = ""; // 初始为空,表示从第一个顶点开始
int limit = 100; // 每页返回 100 个顶点
while (true) {
ScanResponse response = nebulaClient.scanVertex(startVid, limit);
if (!response.isSucceeded()) {
System.err.println("Scan failed: " + response.getErrorMessage());
break;
}
// 处理返回的顶点数据
response.getVertices().forEach(vertex -> {
System.out.println(vertex);
});
// 检查是否还有更多顶点
if (response.getVertices().size() < limit) {
System.out.println("No more vertices to scan.");
break;
}
// 更新 startVid 为当前批次的最后一个顶点 ID
startVid = response.getVertices().get(response.getVertices().size() - 1).getVid();
}
} catch (ExecuteException e) {
e.printStackTrace();
} finally {
nebulaClient.close();
}
}
}