GenerateTableFetch 2025.10.2.19

捆绑包

org.apache.nifi | nifi-standard-nar

描述

Generates SQL select queries that fetch "pages" of rows from a table. The partition size property, along with the table 's row count, determine the size and number of pages and generated FlowFiles. In addition, incremental fetching can be achieved by setting Maximum-Value Columns, which causes the processor to track the columns' maximum values, thus only fetching rows whose columns 'values exceed the observed maximums. This processor is intended to be run on the Primary Node only. This processor can accept incoming connections; the behavior of the processor is different whether incoming connections are provided: - If no incoming connection(s) are specified, the processor will generate SQL queries on the specified processor schedule. Expression Language is supported for many fields, but no FlowFile attributes are available. However the properties will be evaluated using the Environment/System properties. - If incoming connection(s) are specified and no FlowFile is available to a processor task, no work will be performed. - If incoming connection(s) are specified and a FlowFile is available to a processor task, the FlowFile's attributes may be used in Expression Language for such fields as Table Name and others. However, the Max-Value Columns and Columns to Return fields must be empty or refer to columns that are available in each specified table.

标签

database、fetch、generate、jdbc、query、select、sql

输入要求

ALLOWED

支持敏感的动态属性

false

属性

属性

描述

要返回的列

查询中使用的逗号分隔的列名列表。如果您的数据库需要对名称进行特殊处理(例如,加引号),则每个名称都应包含此类处理。如果没有提供列名,则将返回指定表中的所有列。NOTE:为确保增量提取正常工作,为给定表使用一致的列名非常重要。

数据库连接池服务

用于获取数据库连接的控制器服务。

数据库方言服务

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

最大等待时间

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

最大值列

A comma-separated list of column names. The processor will keep track of the maximum value for each column that has been returned since the processor started running. Using multiple columns implies an order to the column list, and each column 's values are expected to increase more slowly than the previous columns' values. Thus, using multiple columns implies a hierarchical structure of columns, which is usually used for partitioning tables. This processor can be used to retrieve only those rows that have been added/updated since the last retrieval. Note that some JDBC types such as bit/boolean are not conducive to maintaining maximum value, so columns of these types should not be listed in this property, and will result in error(s) during processing. If no columns are provided, all rows from the table will be considered, which could have a performance impact. NOTE: It is important to use consistent max-value column names for a given table for incremental fetch to work properly.

表名称

要查询的数据库表的名称。

db-fetch-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.

db-fetch-where-clause

构建 SQL 查询时,要在 WHERE 条件中添加的自定义子句。

gen-table-column-for-val-partitioning

列的名称,其值将用于分区。默认行为是使用偏移/限制策略,使用结果集中的行号进行分区,以获得要从数据库提取的“页”。但对于某些数据库,在适当的情况下使用列值本身来定义“页”可能会更有效。仅当默认查询表现不佳、没有最大值列或仅有一个类型可强制转换为长整数的最大值列(即其类型不是日期或时间戳),以及列值均匀分布且不稀疏时,才赢使用此属性,以获得最佳性能。

gen-table-custom-orderby-column

如果未提供最大值列,并且启用了分区,则用于对结果进行排序的列的名称。如果设置了最大值列或“分区大小 = 0”,则忽略此属性。NOTE:如果既未设置最大值列,也未设置 Custom ORDER BY 列,则根据数据库/驱动程序的不同,处理器可能会报告错误和/或生成的 SQL 可能导致行丢失和/或重复。这是因为如果没有明确的排序,对于每个分区的提取将按照任意顺序完成。

gen-table-fetch-partition-size

每个生成的 SQL 语句要提取的结果行数。表中的总行数除以分区大小得出生成的 SQL 语句数(即 FlowFiles)。值为零表示将生成单独一个 FlowFile,其 SQL 语句将提取表中的所有行。

gen-table-output-flowfile-on-zero-results

根据指定的属性,执行此处理器可能不会生成任何 SQL 语句。当此属性为 true 时,将生成一个空的 FlowFile(如果存在,则具有传入 FlowFile 的父项),并传输到“success”关系。当此属性为 false 时,不会生成任何输出 FlowFiles。

状态管理

范围

描述

CLUSTER

对指定表执行查询后,将保留指定列的最大值,以供将来执行查询时使用。这允许处理器仅提取那些最大值大于保留值的记录。这可用于增量提取、提取新添加的行等操作。若要清除最大值,请根据“状态管理”文档,清除处理器的状态

关系

名称

描述

failure

仅在 SQL 查询执行(使用传入 FlowFile)失败时使用此关系。传入的 FlowFile 将被惩罚并路由到此关系。如果未指定传入连接,则不使用此关系。

success

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

写入属性

名称

描述

generatetablefetch.sql.error

如果处理器有传入连接,并且处理传入 FlowFile 导致 SQL 异常,则 FlowFile 将路由到 failure,并且此属性将设置为异常消息。

generatetablefetch.tableName

要查询的数据库表的名称。

generatetablefetch.columnNames

查询中使用的逗号分隔的列名列表。

generatetablefetch.whereClause

用于获取预期行的查询中使用的 Where 子句。

generatetablefetch.maxColumnNames

逗号分隔式列名列表,用于跟踪自处理器开始运行以来返回的数据。

generatetablefetch.limit

SQL 语句要提取的结果行数。

generatetablefetch.offset

用于检索相应分区的偏移。

fragment.identifier

从同一个查询结果集生成的所有 FlowFiles 都将具有相同的 fragment.identifier 属性值。随后可以使用它来关联结果。

fragment.count

这是单个 ResultSet 产生的 FlowFiles 总数。这可以与 fragment.identifier 属性结合使用,以了解有多少个 FlowFiles 属于同一个传入 ResultSet。

fragment.index

这是此 FlowFile 在所有由同一执行生成的传出 FlowFiles 列表中的位置。这可以与 fragment.identifier 属性结合使用,以了解哪些 FlowFiles 源自同一执行,以及 FlowFiles 的生成顺序

另请参阅

语言: 中文