5

所以我有制表符分隔数据的外部表。一个简单的表格如下所示:

create external table if not exists categories
(id string, tag string, legid string, image string, parent string, created_date string, time_stamp int)
ROW FORMAT DELIMITED FIELDS TERMINATED BY '\t'
LOCATION 's3n://somewhere/';

现在我在末尾添加另一个字段,它将是一个逗号分隔的值列表。

有没有办法以与指定字段终止符相同的方式指定它,还是我必须依赖其中一个 serdes?

例如:

...list_of_names ARRAY<String>)
ROW FORMAT DELIMITED FIELDS TERMINATED BY '\t' ARRAY ELEMENTS SEPARATED BY ','
...

(我假设我需要为此使用 serde,但我认为询问没有任何害处)

4

1 回答 1

6

我不知道如何更新现有表来做到这一点,而是创建一个表;您可以在https://cwiki.apache.org/confluence/display/Hive/LanguageManual+DDL深入找到您正在寻找的内容。那里的一个片段

row_format
  : DELIMITED [FIELDS TERMINATED BY char] [COLLECTION ITEMS TERMINATED BY char]
        [MAP KEYS TERMINATED BY char] [LINES TERMINATED BY char]

我们创建表的一个例子是

CREATE TABLE IF NOT EXISTS visits
(
    ... Columns Removed...
)
    PARTITIONED BY (userdate STRING)
    ROW FORMAT DELIMITED
        FIELDS TERMINATED BY '\001'
        COLLECTION ITEMS TERMINATED BY '\002'
        MAP KEYS TERMINATED BY '\003'
    STORED AS TEXTFILE
;

您要查找的行是COLLECTION ITEMS TERMINATED BY charfor 数组。

hth

于 2011-06-07T20:26:26.697 回答