UpdateDatabaseTable

Description:

This processor uses a JDBC connection and incoming records to generate any database table changes needed to support the incoming records. It expects a 'flat' record layout, meaning none of the top-level record fields has nested fields that are intended to become columns themselves.

Tags:

metadata, jdbc, database, table, update, alter

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.

Display NameAPI NameDefault ValueAllowable ValuesDescription
Record Readerrecord-readerController Service API:
RecordReaderFactory
Implementations: CEFReader
SyslogReader
ReaderLookup
ProtobufReader
Syslog5424Reader
CSVReader
GrokReader
WindowsEventLogReader
ScriptedReader
AvroReader
ParquetReader
JsonPathReader
ExcelReader
JsonTreeReader
YamlTreeReader
XMLReader
The service for reading incoming flow files. The reader is only used to determine the schema of the records, the actual records will not be processed.
Database Connection Pooling Serviceupdatedatabasetable-dbcp-serviceController Service API:
DBCPService
Implementations: HikariCPConnectionPool
HadoopDBCPConnectionPool
DBCPConnectionPool
DBCPConnectionPoolLookup
The Controller Service that is used to obtain connection(s) to the database
Database Typedb-typeGeneric
  • Generic Generates ANSI SQL
  • Oracle Generates Oracle compliant SQL
  • Oracle 12+ Generates Oracle compliant SQL for version 12 or greater
  • MS SQL 2012+ Generates MS SQL Compatible SQL, for version 2012 or greater
  • MS SQL 2008 Generates MS SQL Compatible SQL for version 2008
  • MySQL Generates MySQL compatible SQL
  • PostgreSQL Generates PostgreSQL compatible SQL
  • Phoenix Generates Phoenix compliant SQL
The type/flavor of database, used for generating database-specific code. In many cases the Generic type should suffice, but some databases (such as Oracle) require custom SQL clauses.
Catalog Nameupdatedatabasetable-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. Note that if the property is set and the database is case-sensitive, the catalog name must match the database's catalog name exactly.
Supports Expression Language: true (will be evaluated using flow file attributes and variable registry)
Schema Nameupdatedatabasetable-schema-nameThe name of the database schema that the table belongs to. This may not apply for the database that you are updating. In this case, leave the field empty. Note that if the property is set and the database is case-sensitive, the schema name must match the database's schema name exactly.
Supports Expression Language: true (will be evaluated using flow file attributes and variable registry)
Table Nameupdatedatabasetable-table-nameThe name of the database table to update. If the table does not exist, then it will either be created or an error thrown, depending on the value of the Create Table property.
Supports Expression Language: true (will be evaluated using flow file attributes and variable registry)
Create Table Strategyupdatedatabasetable-create-tableFail If Not Exists
  • Create If Not Exists Create a table with the given schema if it does not already exist
  • Fail If Not Exists If the target does not already exist, log an error and route the flowfile to failure
Specifies how to process the target table when it does not exist (create it, fail, e.g.).
Primary Key Fieldsupdatedatabasetable-primary-keysA comma-separated list of record field names that uniquely identifies a row in the database. This property is only used if the specified table needs to be created, in which case the Primary Key Fields will be used to specify the primary keys of the newly-created table. IMPORTANT: Primary Key Fields must match the record field names exactly unless 'Quote Column Identifiers' is false and the database allows for case-insensitive column names. In practice it is best to specify Primary Key Fields that exactly match the record field names, and those will become the column names in the created table.
Supports Expression Language: true (will be evaluated using flow file attributes and variable registry)

This Property is only considered if the [Create Table Strategy] Property has a value of "Create If Not Exists".
Translate Field Namesupdatedatabasetable-translate-field-namestrue
  • true
  • false
If true, the Processor will attempt to translate field names into the corresponding column names for the table specified, for the purposes of determining whether the field name exists as a column in the target table. NOTE: If the target table does not exist and is to be created, this property is ignored and the field names will be used as-is. If false, the field names must match the column names exactly, or the column may not be found and instead an error my be reported that the column already exists.
Update Field Namesupdatedatabasetable-update-field-namesfalse
  • true
  • false
This property indicates whether to update the output schema such that the field names are set to the exact column names from the specified table. This should be used if the incoming record field names may not match the table's column names in terms of upper- and lower-case. For example, this property should be set to true if the output FlowFile is destined for Oracle e.g., which expects the field names to match the column names exactly. NOTE: The value of the 'Translate Field Names' property is ignored when updating field names; instead they are updated to match the column name as returned by the database.
Record Writerupdatedatabasetable-record-writerController Service API:
RecordSetWriterFactory
Implementations: JsonRecordSetWriter
RecordSetWriterLookup
AvroRecordSetWriter
XMLRecordSetWriter
FreeFormTextRecordSetWriter
CSVRecordSetWriter
ParquetRecordSetWriter
ScriptedRecordSetWriter
Specifies the Controller Service to use for writing results to a FlowFile. The Record Writer should use Inherit Schema to emulate the inferred schema behavior, i.e. an explicit schema need not be defined in the writer, and will be supplied by the same logic used to infer the schema from the column types. If Create Table Strategy is set 'Create If Not Exists', the Record Writer's output format must match the Record Reader's format in order for the data to be placed in the created table location. Note that this property is only used if 'Update Field Names' is set to true and the field names do not all match the column names exactly. If no update is needed for any field names (or 'Update Field Names' is false), the Record Writer is not used and instead the input FlowFile is routed to success or failure without modification.

This Property is only considered if the [Update Field Names] Property has a value of "true".
Quote Table Identifiersupdatedatabasetable-quoted-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 and/or forcing the value of the Table Name property to match the target table name exactly.
Quote Column Identifiersupdatedatabasetable-quoted-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 and/or forcing the record field names to match the column names exactly.
Query Timeoutupdatedatabasetable-query-timeout0Sets the number of seconds the driver will wait for a query to execute. A value of 0 means no timeout. NOTE: Non-zero values may not be supported by the driver.
Supports Expression Language: true (will be evaluated using flow file attributes and variable registry)

Relationships:

NameDescription
successA FlowFile containing records routed to this relationship after the record has been successfully transmitted to the database.
failureA FlowFile containing records routed to this relationship if the record could not be transmitted to the database.

Reads Attributes:

None specified.

Writes Attributes:

NameDescription
output.tableThis attribute is written on the flow files routed to the 'success' and 'failure' relationships, and contains the target table name.
output.pathThis attribute is written on the flow files routed to the 'success' and 'failure' relationships, and contains the path on the file system to the table (or partition location if the table is partitioned).
mime.typeSets the mime.type attribute to the MIME Type specified by the Record Writer, only if a Record Writer is specified and Update Field Names is 'true'.
record.countSets the number of records in the FlowFile, only if a Record Writer is specified and Update Field Names is 'true'.

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.