如何在 Apache NiFi 中将值从 executeSQL 动态传递到 SelectHiveQL [英] how to pass values dynamically in Apache NiFi from executeSQL to SelectHiveQL

查看:28
本文介绍了如何在 Apache NiFi 中将值从 executeSQL 动态传递到 SelectHiveQL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个表,一个在 mysql test.employee 中,另一个在 hive default.dept我想通过 test.employee 表的 empid 作为参数在 hive 表中查询并将数据存储到 HDFS

I have two tables one in mysql test.employee and other in hive default.dept I want to pass empid of test.employee table as a parameter to query in hive table and store data into HDFS

ExecuteSQL -> 从 test.employee 中选择 empid(给出 10 条记录)

ExecuteSQL -> select empid from test.employee (gives 10 records)

SelectHiveQL -> SELECT * FROM default.dept where empid = ${empid} (应该检索 10 条记录)

SelectHiveQL -> SELECT * FROM default.dept where empid = ${empid} (should retrieve 10 records)

此处为图片说明

推荐答案

您可以执行以下操作:

  1. ExecuteSQL - 检索员工记录
  2. ConvertAvroToJson - 用于稍后处理 empid
  3. SplitJson - 每行分成一个流文件
  4. EvaluateJsonPath - 将 empid 的值获取到流文件属性中
  5. ReplaceText - 将内容设置为 HiveQL 语句(使用您在上面所做的表达式语言)
  6. SelectHiveQL - 获取部门记录

请注意,这会为每个 empid 值执行 Hive SELECT,因此每次执行 SelectHiveQL 都会生成一条记录.我不确定(例如,给定 IN 子句的 HiveQL 语义)如何获取单个 HiveQL 语句,因为它是常量表"和 Hive 表之间的连接,更不用说 NiFi 处理了复杂,因为您不想要 SplitJson 并且可能必须一次处理所有记录(例如使用 ExecuteScript)

Note that this executes a Hive SELECT for each of the empid values, so each execution of SelectHiveQL will produce a single record. I'm not sure (given HiveQL semantics for the IN clause, for example) how to get a single HiveQL statement since it's kind of a join between a "table of constants" and the Hive table, not to mention the NiFi processing is more complex as you won't want the SplitJson and would likely have to process all the records at once (with ExecuteScript, e.g.)

这篇关于如何在 Apache NiFi 中将值从 executeSQL 动态传递到 SelectHiveQL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆