【问题标题】:Issue with non-printable char while exporting CSV data (Windows-1252) to hive将 CSV 数据 (Windows-1252) 导出到 hive 时出现不可打印字符的问题
【发布时间】:2019-06-14 10:33:51
【问题描述】:

我正在尝试使用 OpenCSVSerde 在以下 CSV 数据集之上创建一个配置单元表

WITH SERDEPROPERTIES ("quoteChar"='\"', "separatorChar"=',')

但是 hive 表丢失了 £ 符号,并显示了替换字符

FWID,GENDER,Ethnicity,AgeAtPeriodEnd,RC_UnitCost,QUANTITY,ElemTypeDesc
2100001,F,White,WEEK,"£2,027.07",3455,AA - Community Meals
2100011,F,White,YEAR,"£75.00,488776",AA - Community Meals
2100044,M,White,WEEK,"£5.40,39.0",123,Ld-ExtDc - Day
2100044,M,White,WEEK,£5.40,9856,FF - Community Meals
2100044,M,White,WEEK,£5.40,"789,193",FF - Community Meals
2100044,M,White,WEEK,£5.40,"876,241",FE - Community Meals
2100044,M,White,WEEK,£5.40,3888,"Community Meals,ExtDc - Day"
2100044,M,White,WEEK,£5.40,235,Ld-ExtDc - Day
2100044,M,White,WEEK,£5.40,8789,FE - Community Meals
2100044,M,White,WEEK,"£10.07,027.7",16478,FE - Community Meals
2100051,F,White,WEEK,£470.00,12375,RG - Community Meals

另外,我尝试使用 LazySimpleSerDe 创建表

WITH SERDEPROPERTIES ( 'escape.delim'='\"', 'field.delim'=',', 'line.delim'='\n', 'serialization.encoding'='windows-1252')

在这种情况下,使用 £ 符号可以正确解析数据,但由于缺少 quotechar\",值的对齐方式不起作用。

请提出处理此问题的方法。

【问题讨论】:

    标签: csv hive mapr external-tables


    【解决方案1】:

    这是一种方法:

    1. 在 Notepad++ 中打开 CSV 文件并将编码转换为 UTF-8 并推送 文件到 HDFS。
    2. 使用以下属性创建外部表。
        ROW FORMAT SERDE 'org.apache.hadoop.hive.serde2.OpenCSVSerde'
        WITH SERDEPROPERTIES (
          'field.delim'=',',
          'line.delim'='\n',
          'serialization.format'=',',
          'serialization.encoding'='UTF-8')
        STORED AS INPUTFORMAT
          'org.apache.hadoop.mapred.TextInputFormat'
        OUTPUTFORMAT
          'org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat'
        TBLPROPERTIES("skip.header.line.count"="1")
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-01-11
      • 2022-11-26
      • 2021-05-28
      • 2012-03-27
      • 2016-04-12
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多