Skip to main content

ExecuteSQLRecord

描述:

执行SQL查询. 查询结果会通过写记录器RecordWrite去处理. 返回的数据流支持任意大的结果. 组件可以定时执行,也可以写计划任务表达式, 用标准的定时方法, 或者可以被输入流文件触发. 如果被输入的流文件触发, 那么输入流文件的属性全部都可以被查询SQL使用, 查询语句可以用问号代替参数,然后输入的数据流文件必须以这样的格式命名 sql.args.N.type 和 sql.args.N.value,其中N是正整数,参数 sql.args.N.type 是表示JDBC类型的数字. 流文件的内容预计是UTF-8格式的.流文件的属性'executesql.row.count'表示查询结果的行数。

标签:

sql, select, jdbc, query, database, record, 数据库,查询

参数:

如下列表中,必填参数则标识为加粗. 其他未加粗参数,则表示为可选参数。表中同时提到参数默认值设置, 并且 参数还支持 表达式语言.

名字默认值允许值列表描述
数据库连接池服务控制器服务API:
DBCPService
实现:
DBCPConnectionPoolLookup
DBCPConnectionPool
数据库连接池服务用来获得数据库连接
前置查询在执行主SQL查询之前执行的以分号分隔的查询列表。例如,在主查询之前设置会话属性。如果没有错误,这些查询的结果/输出将被抑制。

支持表达式语言 (支持流属性和变量)
数据库查询执行数据库查询语句. 查询可以是空的,也可以是常量, 或者使用表达式表示数据流文件中的属性. 如果设置了SQL,那么输出流就会被重置为查询结果,抛弃输入的数据流文件. 如果不设置此项,那么需要输入的数据流文件内容包括SQL语句。

支持表达式语言 (支持流属性和变量)
后置查询在执行主SQL查询之后执行的以分号分隔的查询列表。例如在主查询后设置会话属性。如果没有错误,这些查询的结果/输出将被抑制。

支持表达式语言 (支持流属性和变量)
最大等待时间0 seconds最大等待SQL查询执行的时间 , 0表示不限制. 最大时间小于1秒,则相当于1秒.

支持表达式语言 (支持流属性和变量)
写入服务控制器服务API:
RecordSetWriterFactory
实现:
CSVRecordSetWriter
FreeFormTextRecordSetWriter
AvroRecordSetWriter
JsonRecordSetWriter
XMLRecordSetWriter
ParquetRecordSetWriter
ScriptedRecordSetWriter
指定用于将结果写入数据流的服务
规范化表/列名false
- true
- false
是否改变一些不兼容avro格式的特殊字符,为了适应Avro格式,比如冒号、句号会被改成下划线。
使用Avro数据类型
- 是
- 否
是否使用Avro逻辑的数据类型,比如 时间,数字,日期等格式,如果否,那么将以字符串代替原有的数据类型。如果是,逻辑数据类型将基于如下规则:'DECIMAL/NUMBER' 对应 'decimal','DATE' 对应 'date-millis','TIME' 对应 'time-millis', 'TIMESTAMP' 对应 'timestamp-millis'。
单个FlowFile中包含的最大结果行数0单个FlowFile中包含的最大结果行数。这将允许您将非常大的结果集分解为多个flowfile。如果指定的值为零,那么所有的行都在一个FlowFile中返回。

支持表达式语言 (支持流属性和变量)
批量输出大小0提交流程会话之前要排队的输出FlowFiles的数量。当设置为0时,当所有结果集行都已处理,输出FlowFiles准备好传输到下游关系时,会话将被提交。对于大型结果集,这可能会导致处理器执行结束时传输大量flowfile。如果设置了该属性,那么当指定数量的FlowFiles准备传输时,会话将被提交,从而将FlowFiles释放到下游关系。注意:片段。当设置此属性时,将不会在FlowFiles上设置count属性。

支持表达式语言 (支持流属性和变量)
查询大小0每次从结果集中提取的结果行数。这是对数据库驱动程序的一个提示,可能不被尊重和/或准确。如果指定的值是零,那么提示将被忽略。

支持表达式语言 (支持流属性和变量)

连线:

名字描述
success当成功执行SQL并返回结果,将输出数据流到此连线
failure当执行SQL失败,将惩罚输入数据流并输出原始数据流到此连线

读取属性:

名字描述
sql.args.N.type输入的数据流被用来参数化查询. 每个参数的类型用一个数字来代表参数的JDBC类型.
sql.args.N.value输入的数据流被用来参数化查询. 参数设置成 sql.args.1.value, sql.args.2.value, sql.args.3.value 等等. 参数值sql.args.1.value的数据类型是 sql.args.1.type.
sql.args.N.format输入的数据流被用来参数化查询.参数格式,例如日期格式:yyyy-MM-dd

写入属性:

名字描述
executesql.row.count查询返回的行数
executesql.query.duration查询过程所持续的时间(毫秒)
executesql.query.executiontimeDuration of the query execution time in milliseconds
executesql.query.fetchtimeDuration of the result set fetch time in milliseconds
executesql.resultset.index如果返回多个结果集,那么返回第一个,序号是0
executesql.error.messageIf processing an incoming flow file causes an Exception, the Flow File is routed to failure and this attribute is set to the exception message.
fragment.identifierIf 'Max Rows Per Flow File' is set then all FlowFiles from the same query result set will have the same value for the fragment.identifier attribute. This can then be used to correlate the results.
fragment.countIf 'Max Rows Per Flow File' is set then this is the total number of FlowFiles produced by a single ResultSet. This can be used in conjunction with the fragment.identifier attribute in order to know how many FlowFiles belonged to the same incoming ResultSet. If Output Batch Size is set, then this attribute will not be populated.
fragment.indexIf 'Max Rows Per Flow File' is set then the position of this FlowFile in the list of outgoing FlowFiles that were all derived from the same result set FlowFile. This can be used in conjunction with the fragment.identifier attribute to know which FlowFiles originated from the same query result set and in what order FlowFiles were produced
input.flowfile.uuidIf the processor has an incoming connection, outgoing FlowFiles will have this attribute set to the value of the input FlowFile's UUID. If there is no incoming connection, the attribute will not be added.
mime.typeSets the mime.type attribute to the MIME Type specified by the Record Writer.
record.countThe number of records output by the Record Writer.

状态管理:

该组件不保存状态。

限制:

该组件没有限制

输入流要求:

组件允许提供输入流。

系统资源考量:

未提供。