<@U0A71G31CDV> give me an example to load 3 tables...
# questions-and-troubleshooting
c
@Rocky give me an example to load 3 tables with the stram load, i need an example of /api/transaction/begin enpoint
r
To load data into multiple tables (e.g., 3 tables) using a single transaction, you must use the Stream Load transaction interface. This feature, specifically for multi-table transactions within a single database, is supported starting from StarRocks v4.0. The workflow involves five main steps: starting the transaction, performing three separate load calls, and then committing. Prerequisites * StarRocks Version: v4.0 or higher. * Header Requirement: You must include
-H "transaction_type:multi"
in every call (begin, load, and commit). * Consistency: All load calls within the same transaction must use the same parameters (like
format
or
column_separator
), except for the
table
name. Step 1: Begin the Transaction Call the
/api/transaction/begin
endpoint to start the transaction and get a
TxnId
. Even for multi-table transactions, you must specify a database and a label.
Copy code
bash
curl --location-trusted -u <username>:<password> \
    -H "label:multi_table_load_001" \
    -H "transaction_type:multi" \
    -H "db:test_db" \
    -H "Expect:100-continue" \
    -XPOST http://<FE_HOST>:<FE_HTTP_PORT>/api/transaction/begin
Step 2: Load Data into Table 1 Use the
/api/transaction/load
endpoint. Use the same label and same transaction_type.
Copy code
bash
curl --location-trusted -u <username>:<password> \
    -H "label:multi_table_load_001" \
    -H "transaction_type:multi" \
    -H "db:test_db" \
    -H "table:table1" \
    -T table1_data.csv \
    -XPUT http://<FE_HOST>:<FE_HTTP_PORT>/api/transaction/load
Step 3: Load Data into Table 2 Repeat the load call for the second table.
Copy code
bash
curl --location-trusted -u <username>:<password> \
    -H "label:multi_table_load_001" \
    -H "transaction_type:multi" \
    -H "db:test_db" \
    -H "table:table2" \
    -T table2_data.csv \
    -XPUT http://<FE_HOST>:<FE_HTTP_PORT>/api/transaction/load
Step 4: Load Data into Table 3 Repeat the load call for the third table.
Copy code
bash
curl --location-trusted -u <username>:<password> \
    -H "label:multi_table_load_001" \
    -H "transaction_type:multi" \
    -H "db:test_db" \
    -H "table:table3" \
    -T table3_data.csv \
    -XPUT http://<FE_HOST>:<FE_HTTP_PORT>/api/transaction/load
Step 5: Commit the Transaction Once all data is sent, call the
/api/transaction/commit
endpoint. The data will only become visible in all three tables after this call succeeds.
Copy code
bash
curl --location-trusted -u <username>:<password> \
    -H "label:multi_table_load_001" \
    -H "transaction_type:multi" \
    -H "db:test_db" \
    -XPOST http://<FE_HOST>:<FE_HTTP_PORT>/api/transaction/commit
Summary of Rules * Atomic: If any of the
load
calls fail or if you call
/api/transaction/rollback
, none of the data will be loaded into any of the 3 tables. * One Client: Currently, the transaction interface only supports concurrent data writes from a single client for a single transaction. * Single Database: v4.0 supports multi-table transactions within the same database. Multi-database transactions are not yet supported. References • loading/Stream_Load_transaction_interface.md