Hive 如何处理配置单元中单个数字的多次出现

Hive 如何处理配置单元中单个数字的多次出现,hive,hiveql,Hive,Hiveql,我想格式化来自源文件的日期。我正在处理垃圾值,因为此列可能包含0(可能是0、00或000等) 选择在(“”,'00','000')中捕获日期时的大小写,然后从测试表中的捕获时间(unix时间戳(捕获日期,'yyyyMMdd'),'yyyy-MM-dd')中选择NULL else作为capt 我不想增加列表中的垃圾值,而是希望以一种通用的方式处理它,这意味着如果我们收到任何数量的0,它应该填充为NULL 任何解决方案?处理非法日期文本似乎没有意义,因为它们在任何情况下都会产生空值(除非我们可能有7

我想格式化来自源文件的日期。我正在处理垃圾值,因为此列可能包含0(可能是0、00或000等)

选择在(“”,'00','000')中捕获日期时的大小写,然后从测试表中的捕获时间(unix时间戳(捕获日期,'yyyyMMdd'),'yyyy-MM-dd')中选择NULL else作为capt

我不想增加列表中的垃圾值,而是希望以一种通用的方式处理它,这意味着如果我们收到任何数量的0,它应该填充为NULL


任何解决方案?

处理非法日期文本似乎没有意义,因为它们在任何情况下都会产生空值(除非我们可能有7个或更多的零)

如果7个或更多的零是可选的-

hive> with test_table as (select stack(5,'','0','00','000000000000','20170831') as capture_date)
    > select  from_unixtime(unix_timestamp(regexp_replace(capture_date,'^0+$',''),'yyyyMMdd'),'yyyy-MM-dd') as capt_dt 
    > from    test_table
    > ;
OK
capt_dt
NULL
NULL
NULL
NULL
2017-08-31


感谢它的工作……有人怀疑为什么配置单元为1 0、2 0和3 0产生空值?@ashwini,因为
unix\u时间戳(捕获日期,'yyyyMMdd')
。只要它们小于7个零,
capture\u date
与模式
yyyyMMdd
hive> with test_table as (select stack(5,'','0','00','000000000000','20170831') as capture_date)
    > select  from_unixtime(unix_timestamp(regexp_replace(capture_date,'^0+$',''),'yyyyMMdd'),'yyyy-MM-dd') as capt_dt 
    > from    test_table
    > ;
OK
capt_dt
NULL
NULL
NULL
NULL
2017-08-31
hive> with test_table as (select stack(5,'','0','00','000000000000','20170831') as capture_date)
    > select  case 
    >             when capture_date not rlike '^0+$' 
    >             then from_unixtime(unix_timestamp(capture_date,'yyyyMMdd'),'yyyy-MM-dd')  
    >         end as capt_dt
    >         
    > from    test_table
    > ;
OK
capt_dt
NULL
NULL
NULL
NULL
2017-08-31