Create Download Request¶
Create a file download task.
Prerequisites¶
A read channel for downloading files is already started and running, and the channel must have the cross-source analysis function disabled. For more information, see Downloading Files.
Request Format¶
POST https://{apigw-address}/data-federation/v2.0/channels/read/{channelId}/download-request
Request Parameters (URI)¶
Name |
Location (Path/Query) |
Mandatory/Optional |
Data Type |
Description |
---|---|---|---|---|
orgId |
Query |
Mandatory |
String |
The organization ID. How to get the orgId>> |
channelId |
Path |
Mandatory |
String |
Channel ID. |
Request Parameters (Body)¶
Name |
Mandatory/Optional |
Data Type |
Description |
---|---|---|---|
taskName |
Mandatory |
String |
Specify the name of the file download task. |
sourceName |
Mandatory |
String |
Specify the data source alias (currently supporting HIVE(EnOS) data source). |
querySql |
Mandatory |
String |
Specify the SQL statement for downloading files. |
filePackageName |
Mandatory |
String |
Specify name of the downloaded file. |
files |
Optional |
List<JSONObject> |
Configuration of the downloaded file. For details, see File Configuration Struct |
File Configuration Struct¶
Name |
Mandatory/Optional |
Data Type |
Description |
---|---|---|---|
split |
Mandatory |
Boolean |
Specify whether to enable partition for the downloaded file (true: enable partition; false: disable partition). |
encoding |
Mandatory |
String |
Specify the file encoding method (options are utf-8 and gbk). |
delimiter |
String |
Boolean |
Specify the field delimiter (options are |
fileHeader |
Mandatory |
List<String> |
Specify the file table header, separated by |
fileRename |
Optional |
List<JSONObject> |
When enabling partition for the downloaded file, specify file part names. For details, see File Rename Struct |
File Rename Struct¶
Name |
Mandatory/Optional |
Data Type |
Description |
---|---|---|---|
file1 |
Mandatory |
String |
Specify the file part name. |
file2 |
Mandatory |
String |
Specify the file part name. |
file3 |
Mandatory |
String |
Specify the file part name. |
Response Parameters¶
Name |
Data Type |
Description |
---|---|---|
data |
List<JSONObject> |
Return the information of downloaded file, see Task ID Struct |
Task ID¶
Name |
Data Type |
Description |
---|---|---|
taskId |
String |
ID of the created file download task. |
Samples¶
Request Sample¶
url: https://{apigw-address}/data-federation/v2.0/channels/read/{channelId}/download-request?orgId={}
method: POST
request body:
{
"taskName": "test_federation_download_openapi",
"sourceName": "hive_enos"
"querySql": "select * from students",
"filePackageName": "studentsOpenAPI",
"files": {
"split": true,
"encoding": "utf-8",
"delimiter": ",",
"fileHeader": [
"c1",
"c2",
"c3",
"c4",
"c5",
"c6"
],
"fileRename": {
"1": "group1",
"2": "group2",
"3": "group3",
"4": "group4"
}
}
}
Return Sample¶
{
"msg": "OK",
"code": 0,
"data": {
"taskId": "3049d82e949e47958246ff0136a77fba"
}
}
Java SDK Sample¶
import com.alibaba.fastjson.JSONObject;
import com.envision.apim.poseidon.config.PConfig;
import com.envision.apim.poseidon.core.Poseidon;
import com.envision.apim.poseidon.request.PoseidonRequest;
import com.google.common.net.HttpHeaders;
import org.apache.commons.codec.binary.Hex;
import org.junit.Test;
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.HashMap;
public class Sample {
private static String accessKey = "AccessKey of your APP";
private static String secretKey = "SecretKey of your APP";
private static String orgId = "yourOrgId";
private static String chId = "yourChannelId";
private static String url = "https://{domain_url}";
private static class Request extends PoseidonRequest {
public void setQueryParam(String key, Object value) {
queryEncodeParams().put(key, value);
}
public void setMethod(String method) {
this.method = method;
}
public void setBodyParams(String key, Object value) {
bodyParams().put(key, value);
}
private String method;
@Override
public String baseUri() {
return "";
}
@Override
public String method() {
return method;
}
}
@Test
public void downloadRequest() {
Request request = new Request();
request.setQueryParam("orgId", orgId);
request.setMethod("POST");
request.setBodyParams("taskName", "yourTaskName");
request.setBodyParams("sourceName", "hive_enos");
request.setBodyParams("querySql", "select * from students");
request.setBodyParams("filePackageName", "studentsOpenAPI");
Map<String, Object> files = new HashMap<>();
files.put("split", true);
files.put("encoding", "utf-8");
files.put("delimiter", ",");
List<String> fileHeaders = new ArrayList<>();
fileHeaders.add("c1");
fileHeaders.add("c2");
files.put("fileHeader", fileHeaders);
Map<String, String> fileRename = new HashMap<>();
fileRename.put("1", "group1");
fileRename.put("2", "group2");
files.put("fileRename", fileRename);
request.setBodyParams("files", files);
try {
JSONObject response = Poseidon.config(PConfig.init().appKey(accessKey).appSecret(secretKey))
.url(url + "/data-federation/v2.0/channels/read/" + chId + "/download-request")
.getResponse(request, JSONObject.class);
System.out.println(response);
} catch (Exception e) {
e.printStackTrace();
}
}
}