복붙노트

[HADOOP] 빈 문자열은 하이브에서 null로 처리되지 않습니다.

HADOOP

빈 문자열은 하이브에서 null로 처리되지 않습니다.

다음 문을 이해하면 빈 문자열이나 빈 문자열이 하이브 열에 삽입되면 null로 처리된다는 것입니다.

TBLPROPERTIES('serialization.null.format'=''

기능을 테스트하기 위해 나는 테이블을 생성하고 파일을 '3'에 삽입했습니다. field3에서 null을 쿼리하면 그 기준을 가진 행이 없습니다.

빈 문자열을 null로 정확하게 만드는 것에 대한 올바른 이해가 있습니까 ??

CREATE TABLE CDR
(
field1                 string,
field2                 string,
field3                 string
)
ROW FORMAT DELIMITED FIELDS TERMINATED BY ',' LINES TERMINATED BY '\n'
**TBLPROPERTIES('serialization.null.format'='');**

insert overwrite table emmtest.cdr select **field1,field2,''** from emmtest.cdr_non_orc;

select * from emmtest.cdr where **field3 is null;**

마지막 명령문은 어떤 행도 반환하지 않았습니다. 그러나 필드 3에 빈 문자열이 있기 때문에 모든 행이 반환 될 것으로 예상됩니다.

해결법

  1. ==============================

    1.TBLPROPERTIES ( 'serialization.null.format'= '')는 다음을 의미합니다.

    TBLPROPERTIES ( 'serialization.null.format'= '')는 다음을 의미합니다.

    당신은 다른 것을하고 있습니다 - 쿼리에서 테이블에 빈 문자열을 삽입하고 있습니다. "있는 그대로"- 빈 문자열로 취급됩니다.

    세게 때리다

    hdfs dfs -mkdir /user/hive/warehouse/mytable
    echo Hello,,World | hdfs dfs -put - /user/hive/warehouse/mytable/data.txt
    

    하이브

    create table mytable (s1 string,s2 string,s3 string) 
    row format delimited 
    fields terminated by ','
    ;
    
    hive> select * from mytable;
    OK
    s1  s2  s3
    Hello       World
    
    hive> alter table mytable set tblproperties ('serialization.null.format'='');
    OK
    
    hive> select * from mytable;
    OK
    s1  s2  s3
    Hello   NULL    World
    
  2. from https://stackoverflow.com/questions/43263038/empty-string-is-not-treated-as-null-in-hive by cc-by-sa and MIT license