使用多字符分隔符创建greenplum外部表

时间:2018-01-21 14:15:24

标签: greenplum

Greenplum外部表加载HDFS数据,数据如下:

    S1000001 ^ @ ^ 200001 ^ @ ^ 300001
    S1000002 ^ @ ^ 200002 ^ @ ^ 300002

分隔符是^ @ ^

在greenplum外部表模式加载时,只能使用单个分隔符,有没有办法自定义分隔符?最好有个例子,谢谢。

我尝试修改了greenplum源代码,在copy.c文件中修改了下面的代码,构建表可以成功,但数据错误。

/* single byte encoding such as ascii, latinx and other */
if (strlen(delim) != 1 && !delim_off)
   ereport(ERROR,
      (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
           errmsg("delimiter must be a single one-byte character, or \'off\'")));

1 个答案:

答案 0 :(得分:0)

Greenplum不支持多字节分隔符。你可以这样做。首先,选择一个在数据中不存在的字符。在这个例子中,我将使用'〜'但它可以是您的数据中不存在的任何字符。

create external table ext_example
(data text)
location ('<storage stuff here>')
format 'text' (delimiter as '~');

接下来,使用split_part提取所需的列。

insert into target_table (col1, col2, col3)
select split_part(data, '^ @ ^', 1) as col1,
       split_part(data, '^ @ ^', 2) as col2,
       split_part(data, '^ @ ^', 3) as col3
from ext_example;