# Get Statement Result

Launch stage: GA

`GET /api/2.0/sql/statements/{statement_id}`

This request can be used to poll for the statement's status. StatementResponse contains
 `statement_id` and `status`; other fields might be absent or present depending on context.
 When the `status.state` field is `SUCCEEDED` it will also return the result manifest and the
 first chunk of the result data. When the statement is in the terminal states `CANCELED`,
 `CLOSED` or `FAILED`, it returns HTTP 200 with the state set. After at least 12 hours in
 terminal state, the statement is removed from the warehouse and further calls will receive an
 HTTP 404 response.

 **NOTE**
 This call currently might take up to 5 seconds to get the latest status and result.

API scopes: sql

## Path parameters

- `statement_id` (string, optional)
  The statement ID is returned upon successfully submitting a SQL statement, and is a required
   reference for all subsequent calls.

## Returns

- `statement_id` (string, optional)
  The statement ID is returned upon successfully submitting a SQL statement, and is a required
   reference for all subsequent calls.
- `status` (object, optional)
  - `state` (string, optional)
    Statement execution state:
     - `PENDING`: waiting for warehouse
     - `RUNNING`: running
     - `SUCCEEDED`: execution was successful, result data available for fetch
     - `FAILED`: execution failed; reason for failure described in accompanying error message
     - `CANCELED`: user canceled; can come from explicit cancel call, or timeout with
     `on_wait_timeout=CANCEL`
     - `CLOSED`: execution successful, and statement closed; result no longer available for fetch
    Possible values: `STATE_UNSPECIFIED`, `PENDING`, `RUNNING`, `SUCCEEDED`, `FAILED`, `CANCELED`, `CLOSED`
  - `error` (object, optional)
    - `error_code` (string, optional)
      Possible values: `UNKNOWN`, `INTERNAL_ERROR`, `TEMPORARILY_UNAVAILABLE`, `IO_ERROR`, `BAD_REQUEST`, `SERVICE_UNDER_MAINTENANCE`, `WORKSPACE_TEMPORARILY_UNAVAILABLE`, `DEADLINE_EXCEEDED`, `CANCELLED`, `RESOURCE_EXHAUSTED`, `ABORTED`, `NOT_FOUND`, `ALREADY_EXISTS`, `UNAUTHENTICATED`
    - `message` (string, optional)
      A brief summary of the error condition.
  - `sql_state` (string, optional)
    SQLSTATE error code returned when the statement execution fails.
     Only populated when the statement status is `FAILED`.
- `manifest` (object, optional)
  - `format` (string, optional)
    Possible values: `FORMAT_UNSPECIFIED`, `JSON_ARRAY`, `ARROW_STREAM`, `CSV`
  - `schema` (object, optional)
    - `column_count` (int32, optional)
    - `columns` (array of object, optional)
      - `name` (string, optional)
        The name of the column.
      - `type_text` (string, optional)
        The full SQL type specification.
      - `type_name` (string, optional)
        The name of the base data type. This doesn't include details for complex types such as STRUCT, MAP or ARRAY.
        Possible values: `BOOLEAN`, `BYTE`, `SHORT`, `INT`, `LONG`, `FLOAT`, `DOUBLE`, `DATE`, `TIMESTAMP`, `STRING`, `BINARY`, `DECIMAL`, `INTERVAL`, `ARRAY`, `STRUCT`, `MAP`, `CHAR`, `NULL`, `USER_DEFINED_TYPE`
      - `position` (int32, optional)
        The ordinal position of the column (starting at position 0).
      - `type_precision` (int32, optional)
        Specifies the number of digits in a number. This applies to the DECIMAL type.
      - `type_scale` (int32, optional)
        Specifies the number of digits to the right of the decimal point in a number. This applies to the DECIMAL type.
      - `type_interval_type` (string, optional)
        The format of the interval type.
  - `total_chunk_count` (int32, optional)
    The total number of chunks that the result set has been divided into.
  - `chunks` (array of object, optional)
    Array of result set chunk metadata.
    - `chunk_index` (int32, optional)
      The position within the sequence of result set chunks.
    - `row_offset` (int64, optional)
      The starting row offset within the result set.
    - `row_count` (int64, optional)
      The number of rows within the result chunk.
    - `byte_count` (int64, optional)
      The number of bytes in the result chunk. This field is not available when using `INLINE`
       disposition.
    - `next_chunk_index` (int32, optional)
      When fetching, provides the `chunk_index` for the _next_ chunk. If absent, indicates there are no
       more chunks. The next chunk can be fetched with a
       :method:statementexecution/getstatementresultchunkn request.
    - `next_chunk_internal_link` (string, optional)
      When fetching, provides a link to fetch the _next_ chunk. If absent, indicates there are no more
       chunks. This link is an absolute `path` to be joined with your `$DATABRICKS_HOST`, and should be
       treated as an opaque link. This is an alternative to using `next_chunk_index`.
  - `total_row_count` (int64, optional)
    The total number of rows in the result set.
  - `total_byte_count` (int64, optional)
    The total number of bytes in the result set. This field is not available when using `INLINE`
     disposition.
  - `truncated` (boolean, optional)
    Indicates whether the result is truncated due to `row_limit` or `byte_limit`.
- `result` (object, optional)
  - `external_links` (array of object, optional)
    - `external_link` (string, optional)
      A  URL pointing to a
       chunk of result data, hosted by an external service, with a short expiration time
       (<= 15 minutes). As this URL contains a temporary credential, it should be considered sensitive
       and the client should not expose this URL in a log.
      **AWS:** A presigned URL pointing to a
      chunk of result data, hosted by an external service, with a short expiration time
      (<= 15 minutes). As this URL contains a temporary credential, it should be considered sensitive
      and the client should not expose this URL in a log.
      **Azure:** A SAS URL pointing to a
      chunk of result data, hosted by an external service, with a short expiration time
      (<= 15 minutes). As this URL contains a temporary credential, it should be considered sensitive
      and the client should not expose this URL in a log.
      **GCP:** A signed URL pointing to a
      chunk of result data, hosted by an external service, with a short expiration time
      (<= 15 minutes). As this URL contains a temporary credential, it should be considered sensitive
      and the client should not expose this URL in a log.
    - `expiration` (string, optional)
      Indicates the date-time that the given external link will expire and
       becomes invalid, after which point a new `external_link` must be requested.
    - `chunk_index` (int32, optional)
      The position within the sequence of result set chunks.
    - `row_offset` (int64, optional)
      The starting row offset within the result set.
    - `row_count` (int64, optional)
      The number of rows within the result chunk.
    - `byte_count` (int64, optional)
      The number of bytes in the result chunk. This field is not available when using `INLINE`
       disposition.
    - `next_chunk_index` (int32, optional)
      When fetching, provides the `chunk_index` for the _next_ chunk. If absent, indicates there are no
       more chunks. The next chunk can be fetched with a
       :method:statementexecution/getstatementresultchunkn request.
    - `next_chunk_internal_link` (string, optional)
      When fetching, provides a link to fetch the _next_ chunk. If absent, indicates there are no more
       chunks. This link is an absolute `path` to be joined with your `$DATABRICKS_HOST`, and should be
       treated as an opaque link. This is an alternative to using `next_chunk_index`.
  - `data_array` (array of array of object, optional)
    The `JSON_ARRAY` format is an array of arrays of values, where each non-null value is
     formatted as a string. Null values are encoded as JSON `null`.
  - `chunk_index` (int32, optional)
    The position within the sequence of result set chunks.
  - `row_offset` (int64, optional)
    The starting row offset within the result set.
  - `row_count` (int64, optional)
    The number of rows within the result chunk.
  - `byte_count` (int64, optional)
    The number of bytes in the result chunk. This field is not available when using `INLINE`
     disposition.
  - `next_chunk_index` (int32, optional)
    When fetching, provides the `chunk_index` for the _next_ chunk. If absent, indicates there are no
     more chunks. The next chunk can be fetched with a
     :method:statementexecution/getstatementresultchunkn request.
  - `next_chunk_internal_link` (string, optional)
    When fetching, provides a link to fetch the _next_ chunk. If absent, indicates there are no more
     chunks. This link is an absolute `path` to be joined with your `$DATABRICKS_HOST`, and should be
     treated as an opaque link. This is an alternative to using `next_chunk_index`.

## Response

### Statement failed with syntax errror

```json
{
  "statement_id": "01ee48eb-5124-1922-bb90-f98c82f024fe",
  "status": {
    "error": {
      "error_code": "BAD_REQUEST",
      "message": "[PARSE_SYNTAX_ERROR] Syntax error at or near ..."
    },
    "state": "FAILED"
  }
}
```

### Statement running

```json
{
  "statement_id": "01ed9db9-24c4-1cb6-a320-fb6ebbe7410d",
  "status": {
    "state": "RUNNING"
  }
}
```

### Statement succeeded with EXTERNAL_LINKS and CSV

```json
{
  "manifest": {
    "chunks": [
      {
        "chunk_index": 0,
        "row_count": 100,
        "row_offset": 0
      }
    ],
    "format": "CSV",
    "schema": {
      "column_count": 1,
      "columns": [
        {
          "name": "id",
          "position": 0,
          "type_name": "LONG",
          "type_text": "BIGINT"
        }
      ]
    },
    "total_byte_count": 293,
    "total_chunk_count": 1,
    "total_row_count": 100
  },
  "result": {
    "external_links": [
      {
        "byte_count": 293,
        "chunk_index": 0,
        "expiration": "2023-01-30T22:23:23.140Z",
        "external_link": "https://someplace.cloud-provider.com/very/long/path/...",
        "row_count": 100,
        "row_offset": 0
      }
    ]
  },
  "statement_id": "01eda0ea-9b4b-15ce-b8bb-a7d4114cb5ed",
  "status": {
    "state": "SUCCEEDED"
  }
}
```

### Statement succeeeded with INLINE data

```json
{
  "manifest": {
    "format": "JSON_ARRAY",
    "schema": {
      "column_count": 1,
      "columns": [
        {
          "name": "id",
          "position": 0,
          "type_name": "LONG",
          "type_text": "BIGINT"
        }
      ]
    }
  },
  "result": {
    "chunk_index": 0,
    "data_array": [
      [
        "0"
      ],
      [
        "1"
      ],
      [
        "2"
      ]
    ],
    "row_count": 3,
    "row_offset": 0
  },
  "statement_id": "01eda0e7-e315-1846-84e2-79a963ffad44",
  "status": {
    "state": "SUCCEEDED"
  }
}
```

