使用 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?

查看:128
本文介绍了使用 Spark 引擎执行 SQL 时,如何在 hive UDF 中获取 Spark 的 partitionId 或 taskContext?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

比如我们用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:

  1. 如何使用 MR 执行引擎在 Hive UDF 中获取 taskId;
  2. 如何使用 Spark 执行引擎在 Hive UDF 中获取 taskContext 和 partitionId.

希望它对你有用!

这篇关于使用 Spark 引擎执行 SQL 时,如何在 hive UDF 中获取 Spark 的 partitionId 或 taskContext?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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