VARIANT
Load CSV or JSON data into VARIANT columns with Stream Load, then query the values and inspect inferred subcolumns.
Before you start
Create or select the target database, and use a warehouse SQL user with the required table and load permissions. Copy the Stream Load request URL from Connection Methods. Replace <endpoint> with its scheme, host, and port, and preserve HTTPS when it is required. Replace <username> with your warehouse SQL username. The curl commands prompt for your password.
Choose one input-format procedure for each sample table, or recreate the sample table before trying another procedure. The displayed rows and timings illustrate the source examples. They are not measurements from your warehouse.
Target audience and prerequisite reading
Before reading this document, choose the reference that best matches your needs:
| Your need | Recommended reading |
|---|---|
| Quickly complete a CSV / JSON load | Continue with this document |
| Choose between the default mode, Sparse, DOC mode, or Schema Template | VARIANT Usage and Configuration Guide |
| Look up VARIANT query syntax, indexes, limitations, or configuration reference | VARIANT |
Limitations
- The procedures below cover CSV and JSON input. Other encodings require matching reader and schema support. Core 26.1.3 also documents Variant V2 reads through supported Iceberg and Paimon paths. Do not assume that any Parquet or ORC file maps directly to a warehouse
VARIANTcolumn.
Storage format recommendation (V3)
Core 26.1.1 adds Storage Format V3 for wide tables. For a new VARIANT table with many subcolumns, consider V3 and check that your warehouse version supports it. For the design rationale, see Storage Format V3.
Enable it explicitly through PROPERTIES when creating the table:
CREATE TABLE table_v3 (
id BIGINT,
data VARIANT
)
DISTRIBUTED BY HASH(id) BUCKETS 32
PROPERTIES (
"storage_format" = "V3"
);
Load CSV data
Step 1: Prepare the data
Create a CSV file named test_variant.csv with the following content:
14186154924|PushEvent|{"avatar_url":"https://avatars.githubusercontent.com/u/282080?","display_login":"brianchandotcom","gravatar_id":"","id":282080,"login":"brianchandotcom","url":"https://api.github.com/users/brianchandotcom"}|{"id":1920851,"name":"brianchandotcom/liferay-portal","url":"https://api.github.com/repos/brianchandotcom/liferay-portal"}|{"before":"abb58cc0db673a0bd5190000d2ff9c53bb51d04d","commits":[""],"distinct_size":4,"head":"91edd3c8c98c214155191feb852831ec535580ba","push_id":6027092734,"ref":"refs/heads/master","size":4}|1|2020-11-14 02:00:00
Step 2: Create the table in the database
Run the following SQL statement to create the table:
CREATE TABLE IF NOT EXISTS testdb.test_variant (
id BIGINT NOT NULL,
type VARCHAR(30) NULL,
actor VARIANT NULL,
repo VARIANT NULL,
payload VARIANT NULL,
public BOOLEAN NULL,
created_at DATETIME NULL,
INDEX idx_payload (`payload`) USING INVERTED PROPERTIES("parser" = "english") COMMENT 'inverted index for payload'
)
DUPLICATE KEY(`id`)
DISTRIBUTED BY HASH(id) BUCKETS 10;
Step 3: Load the data
Using Stream Load as an example, load the data with the following command:
curl --location-trusted -u "<username>" -T test_variant.csv -H "column_separator:|" "<endpoint>/api/testdb/test_variant/_stream_load"
Illustrative successful response. Labels, transaction IDs, byte counts, and timings vary:
{
"TxnId": 12,
"Label": "96cd6250-9c78-4a9f-b8b3-2b7cef0dd606",
"Comment": "",
"TwoPhaseCommit": "false",
"Status": "Success",
"Message": "OK",
"NumberTotalRows": 1,
"NumberLoadedRows": 1,
"NumberFilteredRows": 0,
"NumberUnselectedRows": 0,
"LoadBytes": 660,
"LoadTimeMs": 213,
"BeginTxnTimeMs": 0,
"StreamLoadPutTimeMs": 6,
"ReadDataTimeMs": 0,
"WriteDataTimeMs": 183,
"ReceiveDataTimeMs": 14,
"CommitAndPublishTimeMs": 20
}
Step 4: Verify the loaded data
Use the following SQL query to confirm that the data has been written:
mysql> select * from testdb.test_variant\G
*************************** 1. row ***************************
id: 14186154924
type: PushEvent
actor: {"avatar_url":"https://avatars.githubusercontent.com/u/282080?","display_login":"brianchandotcom","gravatar_id":"","id":282080,"login":"brianchandotcom","url":"https://api.github.com/users/brianchandotcom"}
repo: {"id":1920851,"name":"brianchandotcom/liferay-portal","url":"https://api.github.com/repos/brianchandotcom/liferay-portal"}
payload: {"before":"abb58cc0db673a0bd5190000d2ff9c53bb51d04d","commits":[""],"distinct_size":4,"head":"91edd3c8c98c214155191feb852831ec535580ba","push_id":6027092734,"ref":"refs/heads/master","size":4}
public: 1
created_at: 2020-11-14 02:00:00
Load JSON data
Step 1: Prepare the data
Create a JSON file named test_variant.json with the following content:
{"id": "14186154924","type": "PushEvent","actor": {"id": 282080,"login":"brianchandotcom","display_login": "brianchandotcom","gravatar_id": "","url": "https://api.github.com/users/brianchandotcom","avatar_url": "https://avatars.githubusercontent.com/u/282080?"},"repo": {"id": 1920851,"name": "brianchandotcom/liferay-portal","url": "https://api.github.com/repos/brianchandotcom/liferay-portal"},"payload": {"push_id": 6027092734,"size": 4,"distinct_size": 4,"ref": "refs/heads/master","head": "91edd3c8c98c214155191feb852831ec535580ba","before": "abb58cc0db673a0bd5190000d2ff9c53bb51d04d","commits": [""]},"public": true,"created_at": "2020-11-14 02:00:00"}
Step 2: Create the table in the database
Run the following SQL statement to create the table:
CREATE TABLE IF NOT EXISTS testdb.test_variant (
id BIGINT NOT NULL,
type VARCHAR(30) NULL,
actor VARIANT NULL,
repo VARIANT NULL,
payload VARIANT NULL,
public BOOLEAN NULL,
created_at DATETIME NULL,
INDEX idx_payload (`payload`) USING INVERTED PROPERTIES("parser" = "english") COMMENT 'inverted index for payload'
)
DUPLICATE KEY(`id`)
DISTRIBUTED BY HASH(id) BUCKETS 10;
Step 3: Load the data
Using Stream Load as an example, load the data with the following command:
curl --location-trusted -u "<username>" -T test_variant.json -H "format:json" "<endpoint>/api/testdb/test_variant/_stream_load"
Illustrative successful response. Labels, transaction IDs, byte counts, and timings vary:
{
"TxnId": 12,
"Label": "96cd6250-9c78-4a9f-b8b3-2b7cef0dd606",
"Comment": "",
"TwoPhaseCommit": "false",
"Status": "Success",
"Message": "OK",
"NumberTotalRows": 1,
"NumberLoadedRows": 1,
"NumberFilteredRows": 0,
"NumberUnselectedRows": 0,
"LoadBytes": 660,
"LoadTimeMs": 213,
"BeginTxnTimeMs": 0,
"StreamLoadPutTimeMs": 6,
"ReadDataTimeMs": 0,
"WriteDataTimeMs": 183,
"ReceiveDataTimeMs": 14,
"CommitAndPublishTimeMs": 20
}
Step 4: Verify the loaded data
Use the following SQL query to confirm that the data has been written:
mysql> select * from testdb.test_variant\G
*************************** 1. row ***************************
id: 14186154924
type: PushEvent
actor: {"avatar_url":"https://avatars.githubusercontent.com/u/282080?","display_login":"brianchandotcom","gravatar_id":"","id":282080,"login":"brianchandotcom","url":"https://api.github.com/users/brianchandotcom"}
repo: {"id":1920851,"name":"brianchandotcom/liferay-portal","url":"https://api.github.com/repos/brianchandotcom/liferay-portal"}
payload: {"before":"abb58cc0db673a0bd5190000d2ff9c53bb51d04d","commits":[""],"distinct_size":4,"head":"91edd3c8c98c214155191feb852831ec535580ba","push_id":6027092734,"ref":"refs/heads/master","size":4}
public: 1
created_at: 2020-11-14 02:00:00
Step 5: Verify type inference
By default, DESC only shows the top-level VARIANT column and does not expand the inner subcolumns:
mysql> desc test_variant;
+------------------------------------------------------------+------------+------+-------+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+------------------------------------------------------------+------------+------+-------+---------+-------+
| id | BIGINT | No | true | NULL | |
| type | VARCHAR(*) | Yes | false | NULL | NONE |
| actor | VARIANT | Yes | false | NULL | NONE |
| created_at | DATETIME | Yes | false | NULL | NONE |
| payload | VARIANT | Yes | false | NULL | NONE |
| public | BOOLEAN | Yes | false | NULL | NONE |
+------------------------------------------------------------+------------+------+-------+---------+-------+
6 rows in set (0.07 sec)
After enabling describe_extend_variant_column, you can view the subcolumn types inferred from the VARIANT column:
mysql> set describe_extend_variant_column = true;
Query OK, 0 rows affected (0.01 sec)
mysql> desc test_variant;
+------------------------------------------------------------+------------+------+-------+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+------------------------------------------------------------+------------+------+-------+---------+-------+
| id | BIGINT | No | true | NULL | |
| type | VARCHAR(*) | Yes | false | NULL | NONE |
| actor | VARIANT | Yes | false | NULL | NONE |
| actor.avatar_url | TEXT | Yes | false | NULL | NONE |
| actor.display_login | TEXT | Yes | false | NULL | NONE |
| actor.id | INT | Yes | false | NULL | NONE |
| actor.login | TEXT | Yes | false | NULL | NONE |
| actor.url | TEXT | Yes | false | NULL | NONE |
| created_at | DATETIME | Yes | false | NULL | NONE |
| payload | VARIANT | Yes | false | NULL | NONE |
| payload.action | TEXT | Yes | false | NULL | NONE |
| payload.before | TEXT | Yes | false | NULL | NONE |
| payload.comment.author_association | TEXT | Yes | false | NULL | NONE |
| payload.comment.body | TEXT | Yes | false | NULL | NONE |
....
+------------------------------------------------------------+------------+------+-------+---------+-------+
406 rows in set (0.07 sec)
You can also display the inference results per partition:
DESCRIBE ${table_name} PARTITION ($partition_name);
FAQ
Q1: Which data formats does VARIANT support for loading?
This guide demonstrates CSV and JSON. For other source encodings, verify the reader and schema mapping for your warehouse version. Variant V2 support in Core 26.1.3 does not guarantee compatibility with every external file encoding.
Q2: When should you choose storage format V3?
V3 is an option for wide tables with many VARIANT subcolumns, rather than a requirement for all VARIANT data. It is documented from Core 26.1.1. Review Storage Format V3 before choosing it.
Q3: Why does DESC not show the subcolumns inferred from VARIANT?
By default, DESC only displays the top-level VARIANT column. First run:
SET describe_extend_variant_column = true;
After that, running DESC again shows all inferred subcolumns and their types. You can also view them per partition with DESCRIBE ${table_name} PARTITION ($partition_name).
Q4: How do the table creation statements differ between the CSV and JSON loading methods?
The two examples use the same table schema. Storage replication is managed by VeloDB Cloud. Choose one input format for the sample table. The Stream Load headers differ:
| Format | Key Header |
|---|---|
| CSV | -H "column_separator:|" |
| JSON | -H "format:json" |
Q5: How do you confirm whether a Stream Load succeeded?
Check the Status field in the returned JSON:
StatusofSuccessindicates a successful load.NumberLoadedRowsshould equalNumberTotalRows, andNumberFilteredRowsshould be0.
Common errors
- Authentication or connection failure: Check the generated warehouse endpoint, TLS requirements, SQL user permissions, and network access. For remote files, also check source credentials and reachability.
- Filtered rows or parsing errors: Check the input format, delimiters, field mappings, and target column types. Inspect the returned load error before retrying. Raising the filter tolerance can discard data.
- Unexpected duplicate rows: These examples use independent loads. Check the table model and existing rows before rerunning a sample.