简体   繁体   English

在配置单元表中导入系统名称,系统当前日期,时间

[英]importing system name,system current date,time in hive table

I want to create a table sample and it should have 9 columns and the data which I am loading has only 6 columns.I want to add my Linux system name, Linux current system date, Linux current time into my first three columns and then load the rest of the data into their respective columns.Then my final table should look like this.could anyone help me, please NOTE: Here the sys_name|sys_date|sys_time| 我想创建一个表样本,它应该有9列,我正在加载的数据只有6列。我想在前三列中添加我的Linux系统名称,Linux当前系统日期,Linux当前时间,然后加载其余的数据分别放在各自的列中。然后,我的最终表应如下所示。任何人都可以帮助我,请注意:此处的sys_name | sys_date | sys_time | columns data is imported from the Linux system and for the rest of the column's data is from actual data from data set. 列数据是从Linux系统导入的,其余列数据是来自数据集中的实际数据的。

select * from sample;

sys_name|sys_date|sys_time|column4|column5|column6|column7|column8|column9|
linux   2017-03-09 21:00 data4   data5    data6   data7  data8     data9
linux   2017-03-09 22:00 data4,4 data5,5  data6,6 data7,7 data8,8  data9,9

使用Alter table#sample添加列

 ALTER TABLE #sample ADD sys_name VARCHAR(20) NULL, sys_date Date,some_name varchar(20) NULL; 

I'm assuming you have the columns from column4 to column9 in a separate table (If not, create an external table on top of the data) in that case, you can hardcode the first three columns in a select statment and load the data into your new table using the below "insert using select " statement 我假设您在单独的表中具有从column4到column9的列(如果没有,则在数据顶部创建一个外部表),则可以将select语句中的前三列硬编码并将数据加载到使用下面的“使用select插入”语句创建新表

create table sample(
sysname string,
sysdate date,
some_name string,
column4 string,
.
.
column9 string)
rowfromat delimited
fields terminated by '|'
stored as textfile;

Insert into table sample select 'linux' as sysname, date(current_timestamp) as sys_date, 'name' as some_name, col4, col5, col6, col7, col8, col9 from original_table

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM