All Products
Search
Document Center

MaxCompute:GET_BLOB_METADATA

Last Updated:Oct 09, 2026

The GET_BLOB_METADATA() function retrieves the metadata of a blob. You can use JSON functions to extract specific fields from the returned JSON object.

Common usage

GET_JSON_OBJECT(GET_BLOB_METADATA(blob_expr), '$.field_name');

Usage notes

  • The GET_BLOB_METADATA() function takes a single blob parameter.

  • You can extract fields from the returned JSON object.

  • Common fields include: content_type, content_length, checksum, is_compressed, content_encoding, storage_type, and blob_storage_tier.

  • content_length represents the length in bytes and is suitable for validation with lengthb().

  • is_compressed indicates whether the content is compressed, and content_encoding specifies the compression encoding.

  • The function returns NULL if the input blob is NULL or empty.

Syntax

JSON GET_BLOB_METADATA(blob_expr:BLOB)

Parameters

blob_expr (Required): An expression of the BLOB type.

  • The function accepts a single blob parameter.

  • The parameter must be a blob expression.

  • Common sources include the to_blob(...) function, a blob column in a table, or a blob column generated by a CREATE TABLE AS SELECT (CTAS) or INSERT SELECT statement.

Examples:

GET_BLOB_METADATA(to_blob('abcdef'))
GET_BLOB_METADATA(to_blob('hello world', 'text/plain'))
GET_BLOB_METADATA(b)

Return value

Returns a JSON object containing the metadata. The following table describes the common fields in this object.

Typically, you retrieve the value of a specific field instead of the entire object.

Field name

Description

content_type

The content type specified when the blob was created. Common use cases include:

  • Verify that the to_blob(..., content_type) expression was applied.

  • Distinguish between different types, such as text/plain and application/json.

content_length

The size of the blob content in bytes. For example:

  • For to_blob('abcdef'), the value is 6.

  • For to_blob(X'616263'), the value is 3.

  • to_blob('Chinese test') returns 12

  • For empty content, the value is 0.

checksum

A checksum of the content. You can use this field to determine if the content or storage object is consistent. Returns NULL if no checksum is available.

is_compressed

Indicates whether the blob is stored in a compressed format. Current observations show:

  • Small blobs created directly typically have a value of false.

  • Larger, persisted blobs may have a value of true.

  • Compression depends on the underlying storage and codec.

These examples do not represent all possible compression rules.

content_encoding

The name of the compression encoding.

  • If is_compressed = false, the value is NULL

  • If is_compressed = true, the actual codec name is returned.

storage_type

The storage type of the blob. This field is useful for troubleshooting the blob's storage format.

blob_storage_tier

The storage tier of the blob. Returns NULL if this information is unavailable.

NULL handling

  • When the input parameter is NULL or an empty blob

    The GET_BLOB_METADATA(blob_expr) function returns NULL in the following scenarios:

    • The input parameter itself is NULL.

    • The blob is empty.

    • The blob does not contain valid readable content.

    -- Returns: NULL
    SELECT GET_BLOB_METADATA(to_blob(CAST(null as binary)));
    
    -- In this case, if you try to extract a field, the result is also NULL.
    SELECT get_json_object(GET_BLOB_METADATA(to_blob(CAST(null as binary))), '$.content_length');
  • When a field in the returned result is NULL

    Even if GET_BLOB_METADATA(blob_expr) does not return NULL, some of its fields may be null.

    Common scenarios include:

    • content_type: The value is NULL if a content type is not specified.

    • checksum: Is NULL if no corresponding checksum is available.

    • content_encoding: Is NULL when uncompressed.

    • blob_storage_tier: Is NULL if no corresponding storage tier information is available.

  • The two scenarios for NULL values have distinct meanings:

    • The function returns NULL because the blob has no metadata to return.

    • A field is NULL: The metadata exists, but the field currently has no value.

Examples

Read metadata directly

SELECT GET_BLOB_METADATA(to_blob('abcdef'));

-- Return value:
{
    "checksum": null,
    "content_type": null,
    "storage_type": "MEMORY",
    "is_compressed": false,
    "content_length": 6,
    "content_encoding": null,
    "blob_storage_tier": "STANDARD"
}

Read the three most common fields

This is useful for quickly checking the content type, size in bytes, and compression status.

SELECT
  get_json_object(GET_BLOB_METADATA(to_blob('abcdef')), '$.content_type'),
  get_json_object(GET_BLOB_METADATA(to_blob('abcdef')), '$.content_length'),
  get_json_object(GET_BLOB_METADATA(to_blob('abcdef')), '$.is_compressed');

-- Return value:
+------------+------------+------------+
| _c0        | _c1        | _c2        | 
+------------+------------+------------+
| NULL       | 6          | false      | 
+------------+------------+------------+

Validate the application-written content type

SELECT get_json_object(
  GET_BLOB_METADATA(to_blob('{"key":"value"}', 'application/json')),
  '$.content_type'
);

-- This confirms that the specified content type was correctly set.
+--------------------+
| _c0                | 
+--------------------+
| application/json   | 
+--------------------+

Validate the content length

SELECT cast(
  get_json_object(GET_BLOB_METADATA(to_blob('中文测试')), '$.content_length') as bigint
);

-- Return value:
+------------+
| _c0        | 
+------------+
| 12         | 
+------------+

Validate consistency with LENGTHB()

SELECT
  LENGTHB(TO_BLOB('abcdef')),
  CAST(GET_JSON_OBJECT(GET_BLOB_METADATA(TO_BLOB('abcdef')), '$.content_length') AS BIGINT);

-- Return value:
+------------+------------+
| _c0        | _c1        |
+------------+------------+
| 6          | 6          |
+------------+------------+

Check persisted blob compression

  1. Prepare a test table.

    -- Create a table that contains a BLOB column.
    CREATE TABLE blob_table2 (
      col1 INT ,
      col2 BLOB
    )
    TBLPROPERTIES (
      "table.format.version"="2" 
    );
    
    -- Write data to the table.
    INSERT INTO blob_table2 VALUES (1, to_blob(repeat('aaa', 1000), 'application/json'));
    
    -- Read data from the table.
    SELECT col1,read_blob(col2) FROM blob_table2;
  2. Query the compression status.

    SELECT 
      get_json_object(GET_BLOB_METADATA(col2), '$.is_compressed') 
    FROM blob_table2;
    
    -- Return value:
    +------+
    | _c0  |
    +------+
    | true |
    +------+

    is_compressed indicates whether the blob is currently stored in a compressed format.

View the compression encoding

  1. Prepare a test table.

    -- Create a table that contains a BLOB column.
    CREATE TABLE blob_table2 (
      col1 INT ,
      col2 BLOB
    )
    TBLPROPERTIES (
      "table.format.version"="2" 
    );
    
    -- Write data to the table.
    INSERT INTO blob_table2 VALUES (1, to_blob(repeat('aaa', 1000), 'application/json'));
    
    -- Read data from the table.
    SELECT col1,read_blob(col2) FROM blob_table2;
  2. View the compression encoding.

    SELECT
      get_json_object(GET_BLOB_METADATA(col2), '$.is_compressed'),
      get_json_object(GET_BLOB_METADATA(col2), '$.content_encoding')
    FROM blob_table2;
    
    -- Return value:
    +------+------+
    | _c0  | _c1  |
    +------+------+
    | true | ZSTD |
    +------+------+
    • When uncompressed: content_encoding is NULL

    • During compression: content_encoding returns the specific codec name.

View storage information

  1. Prepare a test table.

    -- Create a table that contains a BLOB column.
    CREATE TABLE blob_table2 (
      col1 INT ,
      col2 BLOB
    )
    TBLPROPERTIES (
      "table.format.version"="2" 
    );
    
    -- Write data to the table.
    INSERT INTO blob_table2 VALUES (1, to_blob(repeat('aaa', 1000), 'application/json'));
    
    -- Read data from the table.
    SELECT col1,read_blob(col2) FROM blob_table2;
  2. View the storage information.

    SELECT
      get_json_object(GET_BLOB_METADATA(col2), '$.storage_type'),
      get_json_object(GET_BLOB_METADATA(col2), '$.blob_storage_tier')
    FROM blob_table2;
    
    -- Return value:
    +-------+----------+
    | _c0   | _c1      |
    +-------+----------+
    | PANGU | STANDARD |
    +-------+----------+

Usage with other functions

  • Use with to_blob to verify that a created blob contains the expected metadata.

  • Use with LENGTHB to validate that the length in the metadata matches the actual content length in bytes.

  • Use with read_blob; read_blob inspects the content, while GET_BLOB_METADATA inspects its metadata.

  • Use with GET_JSON_OBJECT. This is the most common and recommended usage.