You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by "yuzelin (Jira)" <ji...@apache.org> on 2022/11/04 06:54:00 UTC

[jira] [Comment Edited] (FLINK-29881) when Fetch results in sql gateway, the result using open api is different from using restful api

    [ https://issues.apache.org/jira/browse/FLINK-29881?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17628723#comment-17628723 ] 

yuzelin edited comment on FLINK-29881 at 11/4/22 6:53 AM:
----------------------------------------------------------

Hi,

  Maybe it is a little misleading, let me explain.

  Currently, the `resultType` of the `ResultSet` has three value[1]: NOT_READY, PAYLOAD and EOS. If the result is NOT_READY, it doesn't mean the execution has error or there doesn't have result, but means the result is not ready yet, but you may get it from `nextResultUri`. PAYLOAD result means there is data in result , and EOS means all the result has been fetched (and the EOS result doesn't contain data).

  The result has a `Token`,  means the location of the result. Let's see, in `nextResultUri`, you can see your first nextResultUri is "xxxx/1", but your second nextResultUri is "xxxxx/0".  The first result's next token said you can move to fetch result 1, indicating the result 0 has been fetched (so the result is PAY_LOAD), and the second result's next token is still 0, means the data is not ready, so you have to try to fetch the result 0 again and this result is NOT_READY result (and has no data).

  You better use such codes to get all result and judge if you get all the results for complex query (that may return much results) follows:
{code:java}
// Pseudo code 
Response response = fetch(xxx, 0L);
SomeResultCollection allResults = xxx;
allResults.add(response.getData());
Long nextToken = response.getNextToken();  // maybe you should parse from nextResultUri
while (nextToken != null) { // which means there still has result
    response = fetch(xxx, nextToken);
    allResults.add(response.getData());
    nextToken = response.getNextToken();
}{code}
[1] [ResultType |https://github.com/apache/flink/blob/8e66be89dfcb54b7256d51e9d89222ae6701061f/flink-table/flink-sql-gateway-api/src/main/java/org/apache/flink/table/gateway/api/results/ResultSet.java#L146]


was (Author: JIRAUSER293222):
Hi,

  Maybe it is a little misleading, let me explain.

  Currently, the `resultType` of the `ResultSet` has three value[1]: NOT_READY, PAYLOAD and EOS. If the result is NOT_READY, it doesn't mean the execution has error or there doesn't have result, but means the result is not ready yet, but you may get it from `nextResultUri`. PAYLOAD result means there is data in result , and EOS means all the result has been fetched (and the EOS result doesn't contain data).

  The result has a `Token`,  means the location of the result. Let's see, in `nextResultUri`, you can see your first nextResultUri is "xxxx/1", but your second nextResultUri is "xxxxx/0".  The first result's next token said you can move to fetch result 1, indicating the result 0 has been fetched (so the result is PAY_LOAD), and the second result's next token is still 0, means the data is not ready, so you have to try to fetch the result 0 again and this result is NOT_READY result (and has no data).

  You better use such codes to get all result and judge if you get all the results for complex query (that may return much results) follows:
{code:java}
// Pseudo code 
Response response = fetch(xxx, 0L);
SomeResultCollection allResults = xxx;
allResults.add(response.getData());
Long nextToken = response.getNextToken();
while (nextToken != null) { // which means there still has result
    response = fetch(xxx, nextToken);
    allResults.add(response.getData());
    nextToken = response.getNextToken();
}{code}
[1] [ResultType | https://github.com/apache/flink/blob/8e66be89dfcb54b7256d51e9d89222ae6701061f/flink-table/flink-sql-gateway-api/src/main/java/org/apache/flink/table/gateway/api/results/ResultSet.java#L146]

> when Fetch results in sql gateway, the result using open api is different  from using restful api  
> ---------------------------------------------------------------------------------------------------
>
>                 Key: FLINK-29881
>                 URL: https://issues.apache.org/jira/browse/FLINK-29881
>             Project: Flink
>          Issue Type: Bug
>          Components: Table SQL / Gateway
>    Affects Versions: 1.16.0
>            Reporter: yiwei93
>            Priority: Major
>         Attachments: image-2022-11-04-14-47-00-762.png
>
>
> use restful api , fetch result from  
> {code:java}
>   http://hermes02:8083/v1/sessions/9a8fcf37-73e5-43ca-bcc3-d44d8b71a24c/operations/b40085c1-a2c5-42f4-80e7-0971c5ef9710/result/0{code}
> the result is 
> {code:java}
> {
>   "results": {
>     "columns": [
>       {
>         "name": "localtimestamp",
>         "logicalType": {
>           "type": "TIMESTAMP_WITHOUT_TIME_ZONE",
>           "nullable": false,
>           "precision": 3
>         },
>         "comment": null
>       }
>     ],
>     "data": [
>       {
>         "kind": "INSERT",
>         "fields": [
>           "2022-11-04T11:41:40.036"
>         ]
>       }
>     ]
>   },
>   "resultType": "PAYLOAD",
>   "nextResultUri": "/v1/sessions/9a8fcf37-73e5-43ca-bcc3-d44d8b71a24c/operations/b40085c1-a2c5-42f4-80e7-0971c5ef9710/result/1"
> }{code}
> use api to fetch ,the code is 
> {code:java}
> ApiClient client = new ApiClient();
> client.setHost("hermes02");
> client.setPort(8083);
> client.setScheme("http");
> defaultApi = new DefaultApi(client);
> OpenSessionRequestBody openSessionRequestBody = new OpenSessionRequestBody();
> OpenSessionResponseBody openSessionResponseBody = defaultApi.openSession(openSessionRequestBody);
> SessionHandle sessionHandle = new SessionHandle().identifier(UUID.fromString(openSessionResponseBody.getSessionHandle()));
> ExecuteStatementRequestBody executeStatementRequestBody = new ExecuteStatementRequestBody().statement("select localtimestamp");
> ExecuteStatementResponseBody executeStatementResponseBody = defaultApi.executeStatement(sessionHandle.getIdentifier(), executeStatementRequestBody);
> FetchResultsResponseBody fetchResultsResponseBody = defaultApi.fetchResults(sessionHandle.getIdentifier(), UUID.fromString(executeStatementResponseBody.getOperationHandle()), 0L);{code}
> the result is 
> {code:java}
> class FetchResultsResponseBody {
>     results: class ResultSet {
>         resultType: null
>         nextToken: null
>         resultSchema: null
>         data: []
>     }
>     resultType: NOT_READY
>     nextResultUri: /v1/sessions/9a8fcf37-73e5-43ca-bcc3-d44d8b71a24c/operations/b40085c1-a2c5-42f4-80e7-0971c5ef9710/result/0
> }{code}



--
This message was sent by Atlassian Jira
(v8.20.10#820010)