All Products
Search
Document Center

Realtime Compute for Apache Flink:FETCH_CONTENT, TRY_FETCH_CONTENT

Last Updated:Aug 13, 2026

Downloads a file from a URI and returns its content as a byte array.

FETCH_CONTENT and TRY_FETCH_CONTENT asynchronously download a file from the specified URI and return its content as VARBINARY. They differ in behavior when a download fails:

Function

Download succeeds

Download fails after retries are exhausted

Applicable scenario

FETCH_CONTENT

Returns the file content

Throws an exception and the job fails

The file content is a required input for downstream processing. Failed records must not be skipped.

TRY_FETCH_CONTENT

Returns the file content

Returns NULL and the job continues processing other records

Failed records can be skipped, such as invalid URIs, nonexistent files, and network errors.

Engine requirement

  • Only Realtime Compute engine VVR 11.7.0 and later support the FETCH_CONTENT function.

  • Only Realtime Compute engine VVR 11.9.0-preview.1 and later support the TRY_FETCH_CONTENT function.

Syntax

VARBINARY FETCH_CONTENT(VARCHAR uri)
VARBINARY FETCH_CONTENT(VARCHAR uri, INTEGER concurrency)

VARBINARY TRY_FETCH_CONTENT(VARCHAR uri)
VARBINARY TRY_FETCH_CONTENT(VARCHAR uri, INTEGER concurrency)

Parameters

Parameter

Type

Description

uri

VARCHAR

The file URI. Supported schemes include HTTP, HTTPS, and any scheme supported by the Flink FileSystem:

  • http:// or https://: An HTTP or HTTPS link.

  • oss://: An Alibaba Cloud OSS path.

  • hdfs://: An HDFS path.

  • file://: A local file path.

concurrency

INTEGER

Optional. Size of the dedicated I/O thread pool for each FETCH_CONTENT function instance. The pool serves file-system reads and asynchronous HTTP client callbacks. When omitted, defaults to max(8, number of available JVM processors). For example, with 4 processors the default is 8; with 16 processors the default is 16.

Note
  • Returns NULL if uri is NULL. For a non-NULL uri, a failed download throws an exception.

  • If the uri specifies an OSS path, configure access credentials as described in Configure bucket authentication.

Return value

Type

Description

VARBINARY

File content

TRY_FETCH_CONTENT tolerates only content-fetching failures at runtime. SQL validation errors, such as a wrong number or types of arguments or a concurrency value out of range, still cause the job submission to fail.

Retry and timeout configuration

FETCH_CONTENT and TRY_FETCH_CONTENT use the unified retry and timeout configuration of async scalar functions. Request concurrency, timeout, and retries are managed by the Flink Async Scalar operator. You can change the related parameters with SET statements in your SQL job.

The following example sets the retry strategy to fixed-delay retry with a maximum of 2 retries, waits 1 s between two requests, and sets the async call timeout of a single record to 30 s.

SET 'table.exec.async-scalar.retry-strategy' = 'FIXED_DELAY';
SET 'table.exec.async-scalar.max-attempts' = '2';
SET 'table.exec.async-scalar.retry-delay' = '1 s';
SET 'table.exec.async-scalar.timeout' = '30 s';

When table.exec.async-scalar.max-attempts is set to 2, the function sends up to 3 requests: the first request plus 2 retries. If the timeout does not leave enough time for all retries, the timeout result applies: FETCH_CONTENT throws an exception and TRY_FETCH_CONTENT returns NULL.

The following table describes all parameters.

Parameter

Default value

Description

table.exec.async-scalar.timeout

3 min

Maximum time to wait for the async operation to complete for a single input record.

table.exec.async-scalar.max-attempts

3

Maximum retries excluding the first call. By default the call is attempted up to 4 times.

table.exec.async-scalar.max-concurrent-operations

10

Maximum number of in-flight async operations allowed per subtask. Combined with concurrency, it determines the effective concurrency: this parameter caps the in-flight inputs per subtask, while concurrency caps the I/O executor resources per function instance. The effective concurrency is typically bounded by the smaller of the two.

table.exec.async-scalar.retry-strategy

FIXED_DELAY

Retry strategy. Valid values:

  • FIXED_DELAY: retry at a fixed interval.

  • NO_RETRY: do not retry.

table.exec.async-scalar.retry-delay

100 ms

Fixed delay between two retry attempts.

Example 1: Download file content

  • Test data

    Table 1. T1

    input

    uri (VARCHAR)

    1

    http://example.com/image_url

    2

    oss://example-bucket/example.pdf

    3

    NULL

  • Test query

    SELECT 
        id,
        FETCH_CONTENT(uri) AS `value`
    FROM 
        T1;
  • Test result

    id (INT)

    value (VARBINARY)

    1

    x'ffd8ffe00010......'

    2

    x'aaffd8ffe000......'

    3

    NULL

Example 2: Return NULL when a download fails

  • Test data

    Table 1. T1

    input

    uri (VARCHAR)

    1

    http://example.com/image_url

    2

    oss://example-bucket/example.pdf

    3

    invalid://path

  • Use TRY_FETCH_CONTENT to download files. If a download fails, the content of that record returns NULL, and the job is not interrupted by the failure.

    SELECT
      id,
      TRY_FETCH_CONTENT(uri) AS content
    FROM T2;
  • Test result

    id (INT)

    value (VARBINARY)

    1

    x'ffd8ffe00010......'

    2

    NULL

    3

    NULL

  • You can filter out records that failed to download to avoid passing NULL to downstream multimodal inference functions.

    SELECT id, content
    FROM (
      SELECT
        id,
        TRY_FETCH_CONTENT(uri) AS content
      FROM T2
    )
    WHERE content IS NOT NULL;

Example 3: Specify the concurrency

The following example sets the content-fetching concurrency of each operator instance to 8. The 8 must be an integer literal in the SQL statement.

SELECT
  id,
  TRY_FETCH_CONTENT(uri, 8) AS content
FROM T2;

The following calls are invalid and cause errors at the SQL validation stage.

-- concurrency cannot reference a column.
SELECT TRY_FETCH_CONTENT(uri, concurrency_column) FROM T3;

-- Valid values of concurrency: 1 to 1024.
SELECT TRY_FETCH_CONTENT(uri, 0) FROM T3;
SELECT TRY_FETCH_CONTENT(uri, 1025) FROM T3;

References