CREATE TABLE test_dev_db.datetable
(Id string,
Name string,
user_date string
)
ROW FORMAT DELIMITED
FIELDS TERMINATED BY ','
STORED AS orc
;
INSERT INTO TABLE test_dev_db.datetable VALUES
('1904287', 'Christopher Rodriguez', 'Jan 11, 2003'),
('963915', 'Thomas Stewart', '6/17/1969'),
('2236067', 'John Nelson', '08/22/54');
set hive.cli.print.header=true;
select Id,Name,user_date,
CASE WHEN user_date rlike '[a-zA-Z]{3} [0-9]{2}, [0-9]{4}'
THEN
to_date(from_unixtime(UNIX_TIMESTAMP(user_date,'MMM dd,yyyy')))
WHEN user_date rlike '[0-9]{1}/[0-9]{2}/[0-9]{4}'
THEN
to_date(from_unixtime(UNIX_TIMESTAMP(user_date,'MM/dd/yyyy')))
WHEN user_date rlike '[0-9]{2}/[0-9]{2}/[0-9]{2}'
THEN
to_date(from_unixtime(UNIX_TIMESTAMP('08/22/54','MM/dd/yyyy')))
end as format_date
from test_dev_db.datetable;
id name user_date format_date
1904287 Christopher Rodriguez Jan 11, 2003 2003-01-11
963915 Thomas Stewart 6/17/1969 1969-06-17
2236067 John Nelson 08/22/54 0054-08-22
Time taken: 0.467 seconds, Fetched: 3 row(s)
1条答案
按热度按时间yacmzcpb1#
你的第三次约会对我来说似乎是无效的,它可能有好几年的组合。