UltipaDocs
Try Playground
  • Introduction
  • RESTful API
    • Installation
    • Connection
      • Request Configuration
      • Querying Methods
      • UQL Execution
      • Graphset Management
      • Schema and Property Management
      • Data Insertion and Deletion
      • Query Acceleration
      • Algorithm Management
      • Downloads and Exports
      • Process and Task Management
      • Access Management
      • Others
    • Result Processing
    • Types Mapping
    • Installation
    • Connection
      • Request Configuration
      • Querying Methods
      • UQL Execution
      • Graphset Management
      • Schema and Property Management
      • Data Insertion and Deletion
      • Query Acceleration
      • Algorithm Management
      • Downloads and Exports
      • Process and Task Management
      • Access Management
      • Others
    • Result Processing
    • Types Mapping
    • Installation
    • Connection
      • Request Configuration
      • Querying Methods
      • UQL Execution
      • Graphset Management
      • Schema and Property Management
      • Data Insertion and Deletion
      • Query Acceleration
      • Algorithm Management
      • Downloads and Exports
      • Process and Task Management
      • Access Management
      • Others
    • Result Processing
    • Types Mapping
    • Installation
    • Connection
      • Request Configuration
      • Querying Methods
      • UQL Execution
      • Graphset Management
      • Schema and Property Management
      • Data Insertion and Deletion
      • Query Acceleration
      • Algorithm Management
      • Downloads and Exports
      • Process and Task Management
      • Access Management
      • Others
    • Result Processing
    • Types Mapping
    • Installation
    • Connection
      • Request Configuration
      • Querying Methods
      • UQL Execution
      • Graphset Management
      • Schema and Property Management
      • Data Insertion and Deletion
      • Query Acceleration
      • Algorithm Management
      • Downloads and Exports
      • Process and Task Management
      • Access Management
      • Others
    • Result Processing
    • Types Mapping
  1. Docs
  2. /
  3. Ultipa Drivers
  4. /
  5. Database Querying

Downloads and Exports

This section introduces methods on a Connection object for downloading algorithm result files and exporting nodes and edges from a graphset.

Each example focuses solely on the method's usage. For a complete code example, please refer to the full example.

downloadAlgoResultFile()

Downloads one result file from an algorithm task in the current graph.

Parameters:

  • String: Name of the file.
  • String: ID of the algorithm task that generated the file.
  • DownloadFileResultListener: Listener for the download process.
  • RequestConfig (Optional): Configuration settings for the request.

Returns:

  • Response: Result of the request.
Java
RequestConfig requestConfig = new RequestConfig();
requestConfig.setGraphName("miniCircle");

// Runs the Louvain algorithm in graphset 'miniCircle' and prints the task 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);

// Downloads one file generated by the above algorithm task, prints the content in the file and prints the information of the download response

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

Downloads all result files from an algorithm task in the current graph.

Parameters:

  • String: ID of the algorithm task that generated the file(s).
  • DownloadFileResultListener: Listener for the download process.
  • RequestConfig (Optional): Configuration settings for the request.

Returns:

  • Response: Result of the request.
Java
RequestConfig requestConfig = new RequestConfig();
requestConfig.setGraphName("miniCircle");

// Runs the Louvain algorithm in graphset 'miniCircle' and prints the task 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);

// Downloads all files generated by the above algorithm task, prints the content in each file and prints the information of the download response 

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

Exports nodes and edges from the current graph.

Parameters:

  • ExportRequest: Configurations for the export request, including dbType:Ultipa.DBType, schema:String, limit:Integer and selectPropertiesName:List<String>.
  • ExportListener: Listener for the export process.
  • RequestConfig (Optional): Configuration settings for the request.

Returns:

  • Response: Result of the request.
Java
// Exports 10 nodes of schema 'account' with selected properties in graphset 'miniCircle' and prints their information

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

Full Example

Main.java
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) {
        // Connection configurations
        UltipaConfiguration myConfig = UltipaConfiguration.config()
            // URI example: .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 {
            // Establishes connection to the database
            driver = new UltipaClientDriver(myConfig);
            Connection client = driver.getConnection();

            Thread.sleep(3000);
          
            RequestConfig requestConfig = new RequestConfig();
            requestConfig.setGraphName("miniCircle");

            // Runs the Louvain algorithm and prints the task 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);

            // Downloads all files generated by the above algorithm task, prints the content in each file and prints the information of the download response 

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