dboutput
Converts input data into SQL queries and loads them into an external database server. The JDBC profile must be configured in advance.
Command properties
| Item | Description |
|---|---|
| Command type | Processing query |
| Required permission | JDBC profile usage permission |
| License usage | N/A |
| Parallel execution | Not supported |
| Distributed execution | Runs on Control Node (reducer) |
Syntax
Options
type={insert|update}- SQL query type to execute. Default:
insert
insert: Executes INSERT statements.update: Runs a SELECT query based on key fields. If the record exists, executes UPDATE; if not, executes INSERT.
database=STR- Name of the database or schema to switch to after connecting.
table=STR- Name of the target table to load data into.
batchsize=INT- Transaction batch size. A larger batch size is more efficient because more records are committed at once, but the number of records rolled back on transaction failure also increases. A value of 2,000 is recommended. Without specifying a batch size, each record is auto-committed individually, which can be very slow. Default:
1 rowretry=BOOL- Whether to retry on a per-row basis when a batch transaction fails. When set to
t, the failed batch is broken into individual rows for retry. This may reduce performance but minimizes data loss. Default:f stoponfail=BOOL- Whether to cancel the query on commit failure. When set to
t, the entire query is cancelled when a commit fails. Ifstoponfail=t, therowretryoption is ignored. Default:f
Target
PROFILE- JDBC connection profile name. Connection profiles can be configured in the web console.
[+]FIELD, ...- List of fields to load into the database. Separate multiple fields with commas (
,). Prefix a field name with+to designate it as a key field. Field names must match the column names of the target table.
Input fields
| Field | Type | Required | Description |
|---|---|---|---|
| FIELD list | All | Required | Fields matching the names specified in FIELD. Date type is automatically converted to SQL Timestamp. |
Error codes
Parse errors
| Error code | Message | Description |
|---|---|---|
| 12200 | Invalid JDBC profile name: [jdbc_profile] | A non-existent JDBC profile is specified. |
| 12201 | No permission to use JDBC profile. | No usage permission for the JDBC profile. |
| 12202 | Invalid query. | The field list ends with a comma or has other syntax errors. |
| 12203 | Enter the table option. | The table option is not specified. |
| 12204 | Enter a field. | No fields to load are specified. |
| 12205 | Enter a key field for update. | type=update is specified but no key field (with + prefix) is given. |
Runtime errors
N/A
Description
The dboutput command converts all records passed from the previous command into SQL queries and loads them into an external database.
With type=insert (default), each record is converted to an INSERT statement and executed. When key fields are specified, records with duplicate key values within the same batch are ignored.
With type=update, a SELECT COUNT(*) query is run first based on key fields. If the matching record exists, an UPDATE statement is executed; otherwise, an INSERT statement is executed. When only key fields are specified with no non-key fields, records that already exist are ignored.
When a batch transaction fails, behavior depends on the stoponfail and rowretry options:
stoponfail=t: The entire query is cancelled.rowretry=t: The failed batch is broken into individual rows for retry. If a row fails,_error_msg,_error_code, and_sql_statefields are added to that record.- Both options are
f: All records in the failed batch receive the error fields.
The connection is automatically re-established if it is lost.
In a distributed environment, execution runs on the Control Node.
Examples
-
Loading data in INSERT mode
json "[{'name': 'Alice', 'age': 30}, {'name': 'Bob', 'age': 25}]" | dboutput mydb table=employees name, ageInserts
nameandagefields into theemployeestable in the database connected via themydbprofile. -
Loading with a specified batch size
table duration=1d web_logs | dboutput mydb batchsize=2000 table=access_logs src_ip, method, status, bytesLoads large amounts of data efficiently with a batch size of 2,000.
-
Loading data in UPDATE mode
json "[{'id': 1, 'name': 'Alice', 'score': 95}, {'id': 2, 'name': 'Bob', 'score': 88}]" | dboutput mydb type=update table=students +id, name, scoreUses the
idfield as the key to UPDATE if the record exists, or INSERT if it does not. -
Enabling per-row retry
table duration=1h web_logs | dboutput mydb batchsize=2000 rowretry=t table=access_logs src_ip, method, status, bytesRetries on a per-row basis when a batch transaction fails to minimize data loss.
-
Switching the database schema
json "[{'item': 'widget', 'qty': 100}]" | dboutput mydb database=inventory table=items item, qtySwitches to the
inventorydatabase after connecting and loads the data.