Hive 如何在apache配置单元中插入日期、布尔值字段值?

Hive 如何在apache配置单元中插入日期、布尔值字段值?,hive,bigdata,hiveql,Hive,Bigdata,Hiveql,这是我的示例数据集 #cust_id, #cust_name, #odr_date,#shipdt,#Courer,#recvd_dt,#returned or not,#returned dt,#reson of return GGYZ333519YS,Allison,01-01-2017,03-01-2017,Fedx,06-01-2017,**no**,null,null GGYZ333519YS,Allison,08-01-2017,10-01-2017,Delhivery,13-01

这是我的示例数据集

#cust_id,  #cust_name, #odr_date,#shipdt,#Courer,#recvd_dt,#returned or not,#returned dt,#reson of return
GGYZ333519YS,Allison,01-01-2017,03-01-2017,Fedx,06-01-2017,**no**,null,null
GGYZ333519YS,Allison,08-01-2017,10-01-2017,Delhivery,13-01-2017,**yes**,15-01-2017,Damaged Item
并创建了表结构

create table order
( 
cust_id string,
cust_name string,
order_date date,
ship_date date,
courier_name string,
received_date date,
is_returned boolean,
returned_date date,
reason string
)
row format delimited
fields terminated by ','
lines terminated by '\n'
stored as textfile;

使用load命令将数据加载到订单表中。正在为日期字段和布尔字段获取NULL。有什么想法吗?如何解决这个问题

日期应采用兼容格式“yyyy-MM-dd”,以便正确插入到日期中。和布尔值应为(TRUE,FALSE)之一

解决方案是将列定义为字符串,并在select期间进行转换,或者在加载到表中之前转换输入数据

这是在定义为字符串的select if列期间转换数据的方法:

select
      from_unixtime(unix_timestamp( returned_date ,'dd-MM-yyyy'), 'dd-MMM-yyyy') as returned_date,
      case when is_returned like '%no%' then false
           when is_returned like '%yes%' then true
           --else will be null by default
       end as is_returned 

谢谢你的意见。我已经加载了数据。我使用select语句获取空值。从订单中的unixtime(unix时间戳(返回日期,'MM-dd-yyyy'),'dd-MMM-yyyy')中选择@LearnHadoop使用字符串而不是日期重新创建表,以及Boolean如何使用insert语句将字符串格式的日期插入日期字段。在oracle中,我们必须使用日期函数。在hive?@LearnHadoop中,如果字符串的时间戳长于日期,则将其复制到日期。如果日期字符串的格式已正确为“yyyy-MM-dd”,则无需进行任何转换,您可以将其直接插入到日期中。使用我的答案中的解决方案转换日期格式。字符串应以yyyy-MM-dd格式插入日期