在hive和impala中创建具有不同分隔符的表

zy1mlcev  于 2021-06-25  发布在  Hive
关注(0)|答案(1)|浏览(635)

我需要你的帮助在Hive和 Impala 的table。我的问题是我必须插入以下数据:

HD_4K;Number_Channel;ID_Channels;Type;Name_Channel; 

   4K; 45; "1;2;3;4;5;6" ; Series ; Channel 1;  

   HD; 24; "1;6"; Film; Channel 2;

我想用“;”分隔字段但是“id\u channels”字段给我带来了问题,因为您的信息还涉及“;”
有人有什么办法解决这个问题吗?事先非常感谢:)
创建外部表通道(
hd_4k string,number_channel int,id_channels string,type string,name_channel string)行格式分隔字段,由“\u0059”行终止,由“\n”存储为textfile location“/database/channels/”tblproperties(“textfile.compress”=“snappy”);
当前频道表:(

HD_4K |    NUMBER_CHANNEL |  ID_CHANNELS   | TYPE  | NAME_CHANNELS  
(String)        (Int)            (String)    (String)     (String)
  4K              45                "1          2            3 
  HD              23                "1         6"          Film
  ""              ""                ""         ""           ""

梦想频道表

HD_4K |    NUMBER_CHANNEL |  ID_CHANNELS   | TYPE  | NAME_CHANNELS  
(String)        (Int)            (String)    (String)     (String)
  4K              45          "1;2;3;4;5;6"   Series   Cook Channel 
  HD              23              "1;6"        Film      Channel 1
  ""              ""                ""         ""           ""
sauutmhj

sauutmhj1#

您可以使用opencsvserde

CREATE EXTERNAL TABLE channels_csv(
HD_4K String, 
Number_Channel Int, 
ID_Channels String, 
Type String, 
Name_Channel String 
)
ROW FORMAT SERDE 'org.apache.hadoop.hive.serde2.OpenCSVSerde'
WITH SERDEPROPERTIES (
   "separatorChar" = ";",
   "quoteChar"     = "\""
)
LOCATION '/path/to/file' 
;

希望这有帮助

相关问题