Downloads a file from a URI and returns its content as a byte array.
Engine requirement
The FETCH_CONTENT function requires Ververica Runtime (VVR) 11.6.0 or later.
Syntax
VARBINARY FETCH_CONTENT(VARCHAR uri)
VARBINARY FETCH_CONTENT(VARCHAR uri, INTEGER httpRetryCount)
Parameters
|
Parameter |
Type |
Description |
|
uri |
VARCHAR |
The file URI. Supported schemes include HTTP, HTTPS, and any scheme supported by the Flink FileSystem:
|
|
httpRetryCount |
INTEGER |
Optional. Number of retries for HTTP/HTTPS requests. Default: 3. Throws an exception after all |
-
Returns NULL if
uriis NULL. For a non-NULLuri, a failed download throws an exception. -
If the
urispecifies an OSS path, configure access credentials as described in Configure bucket authentication. -
If
httpRetryCountis negative or NULL, the default value is used.
Return value
|
Type |
Description |
|
VARBINARY |
File content |
Example 1
-
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
-
Test data
Table 1. T2
id (INT)
uri (VARCHAR)
1
http://example.com/image_url
2
http://example.com/not_exist_image_url
-
Test query
SELECT id, FETCH_CONTENT(uri, 5) AS `value` FROM T2; -
Test result
id (INT)
value (VARBINARY)
1
x'ffd8ffe00010......'
If the URL does not exist, the function throws an exception after 5 retries:
Caused by: java.io.IOException: HTTP request failed with response code: 404 for URL
References
-
Built-in functions: Supported functions.
-
User-defined functions: UDFs and Manage user-defined functions (UDFs).