使用 Spark 引擎执行 SQL 时,如何在 hive UDF 中获取 Spark 的 partitionId 或 taskContext? [英] How to get the partitionId or taskContext of Spark in hive UDF when SQL executed with Spark engine?
问题描述
比如我们用Spark引擎执行下面的SQL,我们需要my_udf(row)
返回 Spark 中的分区 ID.
For example, we execute the SQL below with Spark engine, we need my_udf(row)
return the partition id in Spark.
add jar hdfs:///dir/udf/udf.jar;
create temporary function my_udf as 'com.my.MyUDF';
select row, my_udf(row) from table;
我已经知道如何在 MR 引擎中执行的 Hive UDF 中获取 taskId:如何在 hive UDF 中获取 taskID 或 mapperID(类似于 Spark 中的 partitionID)?,但在 Spark 引擎中执行时无效.请告诉我如何在Hive UDF中获取Spark的partitionID或taskContext,非常感谢!
I have known how to get taskId in Hive UDF executed in MR engine: How to get the taskID or mapperID(something like partitionID in Spark) in a hive UDF? , but it does not effective when executed in Spark engine. Please tell me how to get partitionID or taskContext of Spark in Hive UDF, thanks very much !
推荐答案
我自己得到了正确答案,请看这里:如何在hive UDF中获取taskID或mapperID(类似于Spark中的partitionID)?
I have got the correct answer on my own, just look here : How to get the taskID or mapperID(something like partitionID in Spark) in a hive UDF?
上面的这个答案将向您介绍以下提示:
This answer above will introduce you the follow tips:
- 如何使用 MR 执行引擎在 Hive UDF 中获取 taskId;
- 如何使用 Spark 执行引擎在 Hive UDF 中获取 taskContext 和 partitionId.
希望它对你有用!
这篇关于使用 Spark 引擎执行 SQL 时,如何在 hive UDF 中获取 Spark 的 partitionId 或 taskContext?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!