PutDatabaseRecord

Description:

The PutDatabaseRecord processor uses a specified RecordReader to input (possibly multiple) records from an incoming flow file. These records are translated to SQL statements and executed as a single batch. If any errors occur, the flow file is routed to failure or retry, and if the records are transmitted successfully, the incoming flow file is routed to success. The type of statement executed by the processor is specified via the Statement Type property, which accepts some hard-coded values such as INSERT, UPDATE, and DELETE, as well as 'Use statement.type Attribute', which causes the processor to get the statement type from a flow file attribute. IMPORTANT: If the Statement Type is UPDATE, then the incoming records must not alter the value(s) of the primary keys (or user-specified Update Keys). If such records are encountered, the UPDATE statement issued to the database may do nothing (if no existing records with the new primary key values are found), or could inadvertently corrupt the existing data (by changing records for which the new values of the primary keys exist).

Tags:

sql, record, jdbc, put, database, update, insert, delete

Properties:

In the list below, the names of required properties appear in bold. Any other properties (not in bold) are considered optional. The table also indicates any default values, and whether a property supports the NiFi Expression Language.

NameDefault ValueAllowable ValuesDescription
Record ReaderController Service API:
RecordReaderFactory
Implementations: Syslog5424Reader
AvroReader
JsonPathReader
ScriptedReader
XMLReader
GrokReader
JsonTreeReader
SyslogReader
CSVReader
Specifies the Controller Service to use for parsing incoming data and determining the data's schema.
Statement Type
  • UPDATE
  • INSERT
  • DELETE
  • Use statement.type Attribute
Specifies the type of SQL Statement to generate. If 'Use statement.type Attribute' is chosen, then the value is taken from the statement.type attribute in the FlowFile. The 'Use statement.type Attribute' option is the only one that allows the 'SQL' statement type. If 'SQL' is specified, the value of the field specified by the 'Field Containing SQL' property is expected to be a valid SQL statement on the target database, and will be executed as-is.
Database Connection Pooling ServiceController Service API:
DBCPService
Implementations: DBCPConnectionPoolLookup
DBCPConnectionPool
HiveConnectionPool
The Controller Service that is used to obtain a connection to the database for sending records.
Catalog NameThe name of the catalog that the statement should update. This may not apply for the database that you are updating. In this case, leave the field empty
Supports Expression Language: true (will be evaluated using flow file attributes and variable registry)
Schema NameThe name of the schema that the table belongs to. This may not apply for the database that you are updating. In this case, leave the field empty
Supports Expression Language: true (will be evaluated using flow file attributes and variable registry)
Table NameThe name of the table that the statement should affect.
Supports Expression Language: true (will be evaluated using flow file attributes and variable registry)
Translate Field Namestrue
  • true
  • false
If true, the Processor will attempt to translate field names into the appropriate column names for the table specified. If false, the field names must match the column names exactly, or the column will not be updated
Unmatched Field BehaviorIgnore Unmatched Fields
  • Ignore Unmatched Fields Any field in the document that cannot be mapped to a column in the database is ignored
  • Fail on Unmatched Fields If the document has any field that cannot be mapped to a column in the database, the FlowFile will be routed to the failure relationship
If an incoming record has a field that does not map to any of the database table's columns, this property specifies how to handle the situation
Unmatched Column BehaviorFail on Unmatched Columns
  • Ignore Unmatched Columns Any column in the database that does not have a field in the document will be assumed to not be required.  No notification will be logged
  • Warn on Unmatched Columns Any column in the database that does not have a field in the document will be assumed to not be required.  A warning will be logged
  • Fail on Unmatched Columns A flow will fail if any column in the database that does not have a field in the document.  An error will be logged
If an incoming record does not have a field mapping for all of the database table's columns, this property specifies how to handle the situation
Update KeysA comma-separated list of column names that uniquely identifies a row in the database for UPDATE statements. If the Statement Type is UPDATE and this property is not set, the table's Primary Keys are used. In this case, if no Primary Key exists, the conversion to SQL will fail if Unmatched Column Behaviour is set to FAIL. This property is ignored if the Statement Type is INSERT
Supports Expression Language: true (will be evaluated using flow file attributes and variable registry)
Field Containing SQLIf the Statement Type is 'SQL' (as set in the statement.type attribute), this field indicates which field in the record(s) contains the SQL statement to execute. The value of the field must be a single SQL statement. If the Statement Type is not 'SQL', this field is ignored.
Supports Expression Language: true (will be evaluated using flow file attributes and variable registry)
Quote Column Identifiersfalse
  • true
  • false
Enabling this option will cause all column names to be quoted, allowing you to use reserved words as column names in your tables.
Quote Table Identifiersfalse
  • true
  • false
Enabling this option will cause the table name to be quoted to support the use of special characters in the table name.
Max Wait Time0 secondsThe maximum amount of time allowed for a running SQL statement , zero means there is no limit. Max time less than 1 second will be equal to zero.
Supports Expression Language: true (will be evaluated using variable registry only)
Rollback On Failurefalse
  • true
  • false
Specify how to handle error. By default (false), if an error occurs while processing a FlowFile, the FlowFile will be routed to 'failure' or 'retry' relationship based on error type, and processor can continue with next FlowFile. Instead, you may want to rollback currently processed FlowFiles and stop further processing immediately. In that case, you can do so by enabling this 'Rollback On Failure' property. If enabled, failed FlowFiles will stay in the input relationship without penalizing it and being processed repeatedly until it gets processed successfully or removed by other means. It is important to set adequate 'Yield Duration' to avoid retrying too frequently.

Relationships:

NameDescription
retryA FlowFile is routed to this relationship if the database cannot be updated but attempting the operation again may succeed
successSuccessfully created FlowFile from SQL query result set.
failureA FlowFile is routed to this relationship if the database cannot be updated and retrying the operation will also fail, such as an invalid query or an integrity constraint violation

Reads Attributes:

NameDescription
statement.typeIf 'Use statement.type Attribute' is selected for the Statement Type property, the value of this attribute will be used to determine the type of statement (INSERT, UPDATE, DELETE, SQL, etc.) to generate and execute.

Writes Attributes:

NameDescription
putdatabaserecord.errorIf an error occurs during processing, the flow file will be routed to failure or retry, and this attribute will be populated with the cause of the error.

State management:

This component does not store state.

Restricted:

This component is not restricted.

Input requirement:

This component requires an incoming relationship.

System Resource Considerations:

None specified.