如何使用HIVE自动获取列中的当前日期和时间(How to automatically get the current date and time in a column using HIVE)

嘿,我的HIVE表中有两列:

例如 :-

c1 : name c2 : age

现在,在创建表时,我想再声明两列,这些列会自动为我提供加载行的当前日期和时间。 例如: John 24 26/08/2015 11:15如何做到这一点?

Hey I have two columns in my HIVE table :

For example :-

c1 : name c2 : age

Now while creating a table I want to declare two more columns which automatically give me the current date and time when the row is loaded. eg: John 24 26/08/2015 11:15 How can this be done?

最满意答案

注意:您不能将多于1列设置为CURRENT_TIMESTAMP 。

这样,你不能在一列中设置CURRENT_TIMESTAMP

SQL:

CREATE TABLE IF NOT EXISTS `hive` ( `id` int(11) NOT NULL, `name` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL, `age` int(11) DEFAULT '0', `datecreated` timestamp NULL DEFAULT CURRENT_TIMESTAMP );

在此处输入图像描述

Hey i found a way to do it using shell script.

Heres how :

echo "$(date +"%Y-%m-%d-%T") $(wc -l /home/hive/landing/$line ) $dir " >> /home/hive/recon/fileinfo.txt

Here i get the date without spaces. In the end I upload the textfile to my hive table.

更多推荐