0
votes

My code is as below..

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

Its throwing an error- Error while compiling statement: FAILED: SemanticException [Error 10014]: Line 2:10 Wrong arguments 'time_first_touch': No matching method for class org.apache.hadoop.hive.ql.udf.UDFFromUnixTime with (string). Possible choices: FUNC(bigint) FUNC(bigint, string) FUNC(int) FUNC(int, string) [ERROR_STATUS]

Now, the point is the following query is working fine.. the ev_time has int/bigint values as MIN works perfectly in the following..

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

Any help is sincerely appreciated..

Thanks

1
MIN(unix_timestamp(GET_JSON_OBJECT(swanviraw.textcol,'$.ev_time'))) - have you tried this? - Ronak Patel
ev_time is unixtime, why to convert it again.. - Arnab
because GET_JSON_OBJECT returns json string...so MIN(unix_timestamp(GET_JSON_OBJECT(swanviraw.textcol,'$.ev_time'))) OR MIN(cast(GET_JSON_OBJECT(swanviraw.textcol,'$.ev_time') should work - cwiki.apache.org/confluence/display/Hive/… - Ronak Patel
MIN(GET_JSON_OBJECT(swanviraw.textcol,'$.ev_time')) is working.. the problem is happening in from_unixtime.. - Arnab
MIN(GET_JSON_OBJECT(swanviraw.textcol,'$.ev_time')) is returning string data type - you need to cast expected datatype by from_unixtime() which is int or bigint - Ronak Patel

1 Answers

0
votes

As GET_JSON_OBJECT returns json string, and as error indicates that from_unixtime expect int or bigint, you need to convert time_first_touch to bigint:

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

OR

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