PutDatabaseRecord 2025.10.2.19

捆绑包

org.apache.nifi | nifi-standard-nar

描述

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 transaction. 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).

标签

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

输入要求

REQUIRED

支持敏感的动态属性

false

属性

属性

描述

列名转换模式

列名将使用此正则表达式实现标准化

列名转换策略

用于标准化表列名的策略。无论策略如何,列名都将采用大写形式,以执行不区分大小写的匹配

数据记录路径

如果指定,则此属性表示一个 RecordPath,将根据每条传入记录进行评估,通过评估 RecordPath 得出的记录将发送到数据库,而非发送整条传入的记录。如果未指定,则整条传入的记录将发布到数据库。

数据库方言服务

数据库方言服务,用于生成特定于某服务或供应商的语句。

删除键

逗号分隔式列名列表,用于唯一标识数据库中的某一行,用于 DELETE 语句。如果语句类型为 DELETE 且未设置此属性,则使用表的列。如果语句类型不是 DELETE,则忽略此属性

语句类型记录路径

指定一个 RecordPath,用于针对每条记录进行评估,以确定语句类型。RecordPath 应等同于 INSERT、UPDATE、UPSERT 或 DELETE。(同时支持 Debezium 风格的操作类型:“r”和“c”表示 INSERT,“u”表示 UPDATE,“d”表示 DELETE)

database-session-autocommit

设置在所用数据库连接上的自动提交模式。如果设置为 false,则将明确提交或回滚操作(分别基于成功或失败)。如果设置为 true,则驱动程序/数据库会自动处理提交/回滚。

db-type

Database Type for generating statements specific to a particular service or vendor. The Generic Type supports most cases but selecting a specific type enables optimal processing or additional features.

put-db-record-allow-multiple-statements

如果语句类型为“SQL”(在 statement.type 属性中设置),则此字段指示是否用分号分隔字段值并分别执行每条语句。如果任何语句导致错误,则回滚整组语句。如果语句类型不是“SQL”,则忽略此字段。

put-db-record-binary-format

将字符串值解码为二进制时要应用的格式。

put-db-record-catalog-name

The name of the database (or the name of the catalog, depending on the destination system) 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.

put-db-record-dcbp-service

用于获取与数据库的连接以发送记录的控制器服务。

put-db-record-field-containing-sql

如果语句类型为“SQL”(在 statement.type 属性中设置),则此字段表示记录中的哪个字段包含要执行的 SQL 语句。该字段的值必须是单独一条 SQL 语句。如果语句类型不是“SQL”,则忽略此字段。

put-db-record-max-batch-size

指定发送到数据库的每个批次中包含的 sql 语句数上限。如果值为零,则表示批次大小不受限制,所有语句都放在一个批次中,这可能导致在处理大量语句时出现内存使用率过高的问题。

put-db-record-query-timeout

允许正在运行的 SQL 语句运行的最长时间量,零表示没有限制。如果最长时间小于 1 秒,则视同为零。

put-db-record-quoted-identifiers

启用此选项将导致所有列名都被置于引号之间,从而允许您在表中使用保留字作为列名。

put-db-record-quoted-table-identifiers

启用此选项将导致表名被置于引号之间,以支持在表名中使用特殊字符。

put-db-record-record-reader

指定用于解析传入数据和确定数据架构的控制器服务。

put-db-record-schema-name

表所属的架构的名称。这可能不适用于您正在更新的数据库。在此类情况下,应将该字段留空。请注意,如果设置了该属性并且数据库区分大小写,则架构名称必须与数据库的架构名称完全匹配。

put-db-record-statement-type

Specifies the type of SQL Statement to generate. Please refer to the database documentation for a description of the behavior of each operation. Please note that some Database Types may not support certain Statement Types. 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.

put-db-record-table-name

该语句应影响的表的名称。请注意,如果数据库区分大小写,则表名称必须与数据库的表名称完全匹配。

put-db-record-translate-field-names

如果为 true,处理器将尝试将字段名称转换为指定表的相应列名称。如果为 false,则字段名称必须与列名称完全匹配,否则该列将不会更新

put-db-record-unmatched-column-behavior

如果传入记录没有数据库表所有列的字段映射,则此属性指定应如何处理这种情况

put-db-record-unmatched-field-behavior

如果传入记录的字段未映射到数据库表的任何列,则此属性指定应如何处理这种情况

put-db-record-update-keys

逗号分隔式列名列表,用于唯一标识数据库中的某一行,用于 UPDATE 语句。如果语句类型为 UPDATE 且未设置此属性,则使用表的主键。在这种情况下,如果不存在主键,则将无匹配的列行为设置为 FAIL,转换到 SQL 的操作将会失败。如果语句类型为 INSERT,则忽略此属性

rollback-on-failure

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.

table-schema-cache-size

指定应缓存多少个表架构

关系

名称

描述

failure

如果无法更新数据库,则将一个 FlowFile 路由到此关系,重试此操作也会失败,例如查询无效或违反完整性约束

retry

如果无法更新数据库,则将一个 FlowFile 路由到此关系,但再次尝试操作可能会成功

success

成功从 SQL 查询结果集创建了 FlowFile。

写入属性

名称

描述

putdatabaserecord.error

如果在处理过程中发生错误,FlowFile 将路由到 failure 或 retry,并且该属性将填充错误的原因。

用例

将记录插入到一个数据库

语言: 中文