hive unix_timestamp()UDF提供多个值

时间:2013-08-05 20:42:31

标签: hadoop hive user-defined-functions

我正在使用HQL从hive表中提取一些数据,同时添加一个包含当前时间的额外行。

类似于:从myTable中选择col1,col2,col3,unix_timestamp();

我期待所有记录在第四列中具有相同的值。

我期待的是:

col1Value, col2Value, col3Value, col4Value, timeT
col1Value, col2Value, col3Value, col4Value, timeT
col1Value, col2Value, col3Value, col4Value, timeT
col1Value, col2Value, col3Value, col4Value, timeT
col1Value, col2Value, col3Value, col4Value, timeT
col1Value, col2Value, col3Value, col4Value, timeT

但是我得到这样的东西:

col1Value, col2Value, col3Value, col4Value, timeT1
col1Value, col2Value, col3Value, col4Value, timeT1
col1Value, col2Value, col3Value, col4Value, timeT1
col1Value, col2Value, col3Value, col4Value, timeT2
col1Value, col2Value, col3Value, col4Value, timeT2
col1Value, col2Value, col3Value, col4Value, timeT2
col1Value, col2Value, col3Value, col4Value, timeT2
col1Value, col2Value, col3Value, col4Value, timeT3
col1Value, col2Value, col3Value, col4Value, timeT3

数据集不是很大,只使用了一个映射器。所以我的问题是:

在一台机器中,unix_timestamp()是针对所选的每一行(hive映射器中的每一行)进行评估,还是评估一个值并用于所有行?

我正在使用MapR M5 / hive 0.9.0

1 个答案:

答案 0 :(得分:1)

根据LanguageManual:“UDF的评估方法的上下文是一次一行”。我相信这意味着您将在映射阶段为每个发出的记录评估一次unix_timestamp()调用。

也许您可以使用子查询来评估unix_timestamp()一次,然后将结果加入原始查询?

相关问题