在Hive中以nano secods创建当前时间戳的新列

时间:2017-12-18 04:08:52

标签: sql hadoop hive hiveql unix-timestamp

我想在Hive表中创建一个列,当前时间戳为纳秒。我如何在插入数据时这样做。?

1 个答案:

答案 0 :(得分:1)

the current <template> <div repeat.for="field of fields"> <mdfield view-model.ref="<what goes here?>"></mdfield> </div> </template> functions in hive, does not give time in nano seconds.

But you can always create your own functions using hive UDF to handle the nano seconds timestamp.

Below is the example of UDF, which will return the current_timestamp value of the nano time.

long

Create a Jar out of the above Java code(say tonanotime.jar) and add the jar to create the udf function to return current nano time.

import org.apache.hadoop.hive.ql.exec.UDF;
import org.apache.hadoop.hive.ql.udf.UDFType;

@UDFType(stateful = true)
public class NanoTimeUdf extends UDF{

    public long evaluate() {
        return System.nanoTime();
    }

}

Now, the ADD JAR /home/amit/tonanotime.jar; create TEMPORARY FUNCTION toNanoTime AS 'NanoTimeUdf'; function is available, you can use in select query to insert into the new table like: e.g

toNanoTime