from_unixtime认为数据是字符串,其中数据是hadoop配置单元中的int / bigint

时间:2016-07-29 15:40:24

标签: hadoop hive hiveql

我的代码如下..

SELECT
        to_date(from_unixtime(time_first_touch)) AS sDate
    FROM (
SELECT
            MIN(GET_JSON_OBJECT(swanviraw.textcol,'$.ev_time')) as time_first_touch,
            COUNT(*) as number_of_events
        FROM swanviraw
    ) v

它抛出一个错误 - 编译语句时出错:FAILED:SemanticException [错误10014]:第2:10行错误的参数' time_first_touch':没有类org.apache.hadoop.hive.ql的匹配方法.udf.UDFFromUnixTime with(string)。可能的选择: FUNC (bigint) FUNC (bigint,string) FUNC (int) FUNC (int,string )[ERROR_STATUS]

现在,重点是以下查询正常工作.. ev_time具有int / bigint值,因为MIN在以下内容中完美运行..

 SELECT
                    MIN(GET_JSON_OBJECT(swanviraw.textcol,'$.ev_time')) as time_first_touch,
                    COUNT(*) as number_of_events
                FROM swanviraw

真心感谢任何帮助。

由于

1 个答案:

答案 0 :(得分:0)

作为GET_JSON_OBJECT returns json string,并且错误表明from_unixtime期望intbigint,您需要将time_first_touch转换为{{ 1}}:

bigint

OR

SELECT
        to_date(from_unixtime(time_first_touch)) AS sDate
    FROM (
SELECT
            MIN(cast(GET_JSON_OBJECT(swanviraw.textcol,'$.ev_time') as bigint)) as time_first_touch,
            COUNT(*) as number_of_events
        FROM swanviraw
    ) as v