本节为您介绍如何使用Connection
对象的方法下载算法结果文件,从图集导出点和边。
每个示例主要展示如何使用所列方法。点击完整示例查看完整代码示例。
downloadAlgoResultFile()
下载当前图集一个算法任务中的一个结果文件。
参数:
String
:文件名称。String
:生成结果文件的算法任务ID。DownloadFileResultListener
:下载进程的监听器。RequestConfig
(可选):配置请求。
返回值:
Response
:请求的结果。
RequestConfig requestConfig = new RequestConfig();
requestConfig.setGraphName("miniCircle");
// 在图集miniCircle上运行鲁汶算法并打印任务ID
Response response = client.uql("algo(louvain).params({phase1_loop_num: 20, min_modularity_increase: 0.001}).write({file:{filename_community_id: 'communityID', filename_ids: 'ids', filename_num: 'num'}})", requestConfig);
Table table = response.alias("_task").asTable();
String taskId = (String) table.getRows().get(0).get(0);
System.out.println("taskId = " + taskId);
Thread.sleep(2000);
// 下载以上算法任务生成的一个文件,打印文件内容和下载响应信息
Response resDownLoad = client.downloadAlgoResultFile("communityID", taskId, new DownloadFileResultListener() {
public void onReady(String s) {
System.out.println("Start downloading");
}
public void next(String filename, DownloadFileResult result) {
System.out.println("Content of the file '" + filename + "':");
System.out.println("-----------------------");
System.out.println(new String(result.getBytes(), StandardCharsets.UTF_8));
System.out.println("-----------------------");
}
public void onComplete(String s) {
System.out.println("Download complete");
}
public void onError(String s, Throwable throwable) {
System.out.println("Error occurred while downloading");
}
}, requestConfig);
System.out.println("resDownLoad = " + new Gson().toJson(resDownLoad));
taskId = 54228
Content of the file 'communityID':
-----------------------
ULTIPA8000000000000001,94
...
ULTIPA8000000000004E6E,154
-----------------------
Download complete
resDownLoad = {"host":"192.168.1.88:60611","status":{"errorCode":"SUCCESS","msg":"","clusterInfo":{"redirect":"","leaderAddress":"","followers":[]}},"aliases":[],"items":{}}
downloadAllAlgoResultFile()
下载当前图集一个算法任务中的全部结果文件。
参数:
String
:生成结果文件的算法任务ID。DownloadFileResultListener
:下载进程的监听器。RequestConfig
(可选):配置请求。
返回值:
Response
:请求的结果。
RequestConfig requestConfig = new RequestConfig();
requestConfig.setGraphName("miniCircle");
// 在图集miniCircle上运行鲁汶算法并打印任务ID
Response response = client.uql("algo(louvain).params({phase1_loop_num: 20, min_modularity_increase: 0.001}).write({file:{filename_community_id: 'communityID', filename_ids: 'ids', filename_num: 'num'}})", requestConfig);
Table table = response.alias("_task").asTable();
String taskId = (String) table.getRows().get(0).get(0);
System.out.println("taskId = " + taskId);
Thread.sleep(2000);
// 下载以上算法任务生成的全部文件,打印每个文件的内容和下载响应信息
Response resDownLoad = client.downloadAllAlgoResultFile(taskId, new DownloadFileResultListener() {
public void onReady(String s) {
System.out.println("Start downloading");
}
public void next(String filename, DownloadFileResult result) {
System.out.println("Content of the file '" + filename + "':");
System.out.println("-----------------------");
System.out.println(new String(result.getBytes(), StandardCharsets.UTF_8));
System.out.println("-----------------------");
}
public void onComplete(String s) {
System.out.println("Download complete");
}
public void onError(String s, Throwable throwable) {
System.out.println("Error occurred while downloading");
}
}, requestConfig);
System.out.println("resDownLoad = " + new Gson().toJson(resDownLoad));
taskId = 54229
Content of the file 'communityID':
-----------------------
ULTIPA8000000000000001,137
...
ULTIPA8000000000004E6E,284
-----------------------
Download complete
Content of the file 'ids':
-----------------------
284,ULTIPA800000000000001A,ULTIPA8000000000000412,...
...
179,ULTIPA800000000000001E,ULTIPA800000000000002B,...
-----------------------
Download complete
Content of the file 'num':
-----------------------
284,89
...
179,23
-----------------------
Download complete
resDownLoad = {"status":{"errorCode":"SUCCESS","msg":"success"},"aliases":[],"items":{}}
export()
从当前图集导出点和边。
参数:
ExportRequest
:导出请求的配置信息,包括dbType:Ultipa.DBType
,schema:String
,limit:Integer
和selectPropertiesName:List<String>
。ExportListener
:导出进程的监听器。RequestConfig
(可选):配置请求。
返回值:
Response
:请求的结果。
// 从图集miniCircle名为account的schema导出10个点,并打印点的信息
RequestConfig requestConfig = new RequestConfig();
requestConfig.setGraphName("miniCircle");
ExportRequest exportRequest = new ExportRequest();
exportRequest.setDbType(Ultipa.DBType.DBNODE);
exportRequest.setLimit(10);
exportRequest.setSchema("account");
exportRequest.setSelectPropertiesName(Arrays.asList("_id", "_uuid", "name", "year"));
Response response = client.export(exportRequest, new ExportListener() {
public void onReady() {
System.out.println("Start downloading");
}
public void onError(Throwable t) {
System.out.println("Error occurred while downloading");
}
public void onComplete() {
System.out.println("Download complete");
}
public void next(ExportData result) {
List<Node> nodes = result.getNodes();
for (Node node : nodes) {
System.out.println(node.toString());
}
}
}, requestConfig);
Node(uuid=1, id=ULTIPA8000000000000001, schema=account, values={_id=ULTIPA8000000000000001, name=Yu78, year=1978})
Node(uuid=2, id=ULTIPA8000000000000002, schema=account, values={_id=ULTIPA8000000000000002, name=jibber-jabber, year=1989})
Node(uuid=3, id=ULTIPA8000000000000003, schema=account, values={_id=ULTIPA8000000000000003, name=mochaeach, year=1982})
Node(uuid=4, id=ULTIPA8000000000000004, schema=account, values={_id=ULTIPA8000000000000004, name=Win-win0, year=2007})
Node(uuid=5, id=ULTIPA8000000000000005, schema=account, values={_id=ULTIPA8000000000000005, name=kevinh, year=1973})
Node(uuid=6, id=ULTIPA8000000000000006, schema=account, values={_id=ULTIPA8000000000000006, name=alexyhel, year=1974})
Node(uuid=7, id=ULTIPA8000000000000007, schema=account, values={_id=ULTIPA8000000000000007, name=hooj, year=1986})
Node(uuid=8, id=ULTIPA8000000000000008, schema=account, values={_id=ULTIPA8000000000000008, name=vv67, year=1990})
Node(uuid=9, id=ULTIPA8000000000000009, schema=account, values={_id=ULTIPA8000000000000009, name=95smith, year=1988})
Node(uuid=10, id=ULTIPA800000000000000A, schema=account, values={_id=ULTIPA800000000000000A, name=jo, year=1992})
Download complete
完整示例
package com.ultipa.www.sdk.api;
import com.google.gson.Gson;
import com.ultipa.sdk.connect.Connection;
import com.ultipa.sdk.connect.conf.RequestConfig;
import com.ultipa.sdk.connect.conf.UltipaConfiguration;
import com.ultipa.sdk.connect.driver.UltipaClientDriver;
import com.ultipa.sdk.operate.command.listener.DownloadFileResultListener;
import com.ultipa.sdk.operate.entity.*;
import com.ultipa.sdk.operate.response.DownloadFileResult;
import com.ultipa.sdk.operate.response.Response;
import java.nio.charset.StandardCharsets;
public class Main {
public static void main(String[] args) {
// 设置连接
UltipaConfiguration myConfig = UltipaConfiguration.config()
// URI示例: .hosts("mqj4zouys.us-east-1.cloud.ultipa.com:60010")
.hosts("192.168.1.85:60611,192.168.1.87:60611,192.168.1.88:60611")
.username("<username>")
.password("<password>");
UltipaClientDriver driver = null;
try {
// 建立与数据库的连接
driver = new UltipaClientDriver(myConfig);
Connection client = driver.getConnection();
Thread.sleep(3000);
RequestConfig requestConfig = new RequestConfig();
requestConfig.setGraphName("miniCircle");
// 运行鲁汶算法并打印任务ID
Response response = client.uql("algo(louvain).params({phase1_loop_num: 20, min_modularity_increase: 0.001}).write({file:{filename_community_id: 'communityID', filename_ids: 'ids', filename_num: 'num'}})", requestConfig);
Table table = response.alias("_task").asTable();
String taskId = (String) table.getRows().get(0).get(0);
System.out.println("taskId = " + taskId);
Thread.sleep(2000);
// 下载以上算法任务生成的全部文件,打印每个文件的内容和下载响应信息
Response resDownLoad = client.downloadAllAlgoResultFile(taskId, new DownloadFileResultListener() {
public void onReady(String s) {
System.out.println("Start downloading");
}
public void next(String filename, DownloadFileResult result) {
System.out.println("Content of the file '" + filename + "':");
System.out.println("-----------------------");
System.out.println(new String(result.getBytes(), StandardCharsets.UTF_8));
System.out.println("-----------------------");
}
public void onComplete(String s) {
System.out.println("Download complete");
}
public void onError(String s, Throwable throwable) {
System.out.println("Error occurred while downloading");
}
}, requestConfig);
System.out.println("resDownLoad = " + new Gson().toJson(resDownLoad));
} catch (InterruptedException e) {
throw new RuntimeException(e);
} finally {
if (driver != null) {
driver.close();
}
}
}
}