Read Data¶
Read data by providing SQL query through the specified channel.
Prerequisites¶
Read channels are created and started in the organization.
Request Format¶
POST https://{apigw-address}/data-federation/v2.0/channels/read/{channelId}
Request Parameters (Header)¶
Name | Mandatory/Optional | Data Type | Description |
---|---|---|---|
Content-Type | Mandatory | String | Content or file type. The default value is application/json. |
Request Parameters (URI)¶
Name | Location (Path/Query) | Mandatory/Optional | Data Type | Description |
---|---|---|---|---|
orgId | Query | Mandatory | String | Your organization ID. How to get the orgId>> |
channelId | Path | Mandatory | String | Channel ID |
Request Parameters (Body)¶
Name | Mandatory/Optional | Data Type | Description |
---|---|---|---|
sqlQuery | Mandatory | String | SQL query for getting data from storage systems. |
source | Optional | String | For channels with cross-source analysis disabled, specify the alias of the data source. |
queue | Optional | String | Specify the priority of the data query job. Options are Hot, Warm, and Cold. |
itemFormat | Optional | String | Reserved parameter for specifying the format of returned JSON. |
Response Parameters¶
Name | Data Type | Description |
---|---|---|
data | List<Object> | Data that is returned by the SQL query. For more information, see Returned Data Struct |
Returned Data Struct¶
Name | Data Type | Description |
---|---|---|
columns | String | Column name. |
metadata | String | Meta data. |
queryState | String | Data querying state. |
rows | List<Object> | Rows of data. For more information, see Data Row Struct |
Data Row Struct¶
Name | Data Type | Description |
---|---|---|
COLUMN_NAME | String | Column name. |
DATA_TYPE | String | Data type. |
IS_NULLABLE | String | Data type. |
Sample¶
Request Sample¶
url: https://{apigw-address}/data-federation/v2.0/channels/read/{channelId}?orgId={}
method: POST
requestBody:
{
"sqlQuery": "show schemas"
}
Return Sample¶
{
"msg": "OK",
"code": 0,
"data": {
"metadata": ["VARCHAR"],
"columns": ["SCHEMA_NAME"],
"queryState": "COMPLETED",
"rows": []
}
}
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;
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 readData() throws InterruptedException {
Request request = new Request();
request.setQueryParam("orgId", orgId);
request.setMethod("POST");
request.headerParams().put(HttpHeaders.CONTENT_TYPE, "application/json");
request.setBodyParams("sqlQuery", "show schemas");
//For channels with cross-source analysis disabled, specify the data source alias.
//request.setBodyParams("source", "customerMysql");
request.setBodyParams("queue", null);
request.setBodyParams("itemFormat", null);
try {
JSONObject response = Poseidon.config(PConfig.init().connectTimeout(0).readTimeout(0).writeTimeout(0).appKey(accessKey).appSecret(secretKey).debug())
.url(url + "/data-federation/v2.0/channels/read/" + chId)
.getResponse(request, JSONObject.class);
System.out.println(response);
} catch (Exception e) {
e.printStackTrace();
}
System.out.println(System.currentTimeMillis());
}
}