как создать внешнюю таблицу из файла csv с запятыми в поле цитаты в greenplum? - PullRequest
0 голосов
/ 05 мая 2020

Я пытаюсь создать внешнюю таблицу из csv вот так:

CREATE EXTERNAL TABLE hctest.ex_nkp
(
a text,
b text,
c text,
d text,
e text,
f text,
g text,
h text
)
LOCATION ('gpfdist://192.168.56.111:10000/performnkp.csv')
FORMAT 'CSV' (DELIMITER ',' HEADER);

CSV разделяется запятой (,) и выглядит так:

"Subject Username","Form Title","Form Start Date","Form End Date","Competency Name","Competency Description","Core Competency","Competency Official Rating"
"90008765","Performance Review - 2nd Semester 2019 for Ely Eisley","01/01/2019","31/12/2019","1. Uncompromising Integrity","<p>High ethical standards, low tolerance of unethical conduct.</p>","Yes","3"
"90008766","Performance Review - 2nd Semester 2019 for Ely Eisley","01/01/2019","31/12/2019","2. Team Synergy","<p>Passionately work together, ensuring completeness, to achieve common goals.</p>","Yes","3"
"90008767","Performance Review - 2nd Semester 2019 for Ely Eisley","01/01/2019","31/12/2019","3. Simplicity","<p>We do our utmost to deliver the easy to use solutions, exceeding customers&#39","","
"90008768","Performance Review - 2nd Semester 2019 for Ely Eisley","01/01/2019","31/12/2019","4. Exceptional Performance","<p>Highest level of performance, with a heart for people.</p>","Yes","3"

И я обнаружил ошибку:

ERROR:  extra data after last expected column  (seg0 slice1 192.168.56.111:6000 pid=14121)
DETAIL:  External table ex_nkp, line 5 of file gpfdist://192.168.56.111:10000/performnkp.csv

Как я могу решить эту проблему?

Ответы [ 2 ]

1 голос
/ 05 мая 2020

Похоже, ваш CSV-файл в строке 4 имеет неправильный формат. Обратите внимание, что в конце строки 4 стоит одинарная кавычка, и Greenplum интерпретирует ее как поле CSV с разрывом строки. Добавив недостающую цитату в строку 4, я могу прочитать файл в Greenplum.

"Subject Username","Form Title","Form Start Date","Form End Date","Competency Name","Competency Description","Core Competency","Competency Official Rating"
"90008765","Performance Review - 2nd Semester 2019 for Ely Eisley","01/01/2019","31/12/2019","1. Uncompromising Integrity","<p>High ethical standards, low tolerance of unethical conduct.</p>","Yes","3"
"90008766","Performance Review - 2nd Semester 2019 for Ely Eisley","01/01/2019","31/12/2019","2. Team Synergy","<p>Passionately work together, ensuring completeness, to achieve common goals.</p>","Yes","3"
"90008767","Performance Review - 2nd Semester 2019 for Ely Eisley","01/01/2019","31/12/2019","3. Simplicity","<p>We do our utmost to deliver the easy to use solutions, exceeding customers&#39","","
"90008768","Performance Review - 2nd Semester 2019 for Ely Eisley","01/01/2019","31/12/2019","4. Exceptional Performance","<p>Highest level of performance, with a heart for people.</p>","Yes","3"

Результирующий запрос:

fguerrero=# select * from ex_nkp ;
NOTICE:  HEADER means that each one of the data files has a header row
    a     |                           b                           |     c      |     d      |              e              |                                         f                                          |  g  | h
----------+-------------------------------------------------------+------------+------------+-----------------------------+------------------------------------------------------------------------------------+-----+---
 90008765 | Performance Review - 2nd Semester 2019 for Ely Eisley | 01/01/2019 | 31/12/2019 | 1. Uncompromising Integrity | <p>High ethical standards, low tolerance of unethical conduct.</p>                 | Yes | 3
 90008766 | Performance Review - 2nd Semester 2019 for Ely Eisley | 01/01/2019 | 31/12/2019 | 2. Team Synergy             | <p>Passionately work together, ensuring completeness, to achieve common goals.</p> | Yes | 3
 90008767 | Performance Review - 2nd Semester 2019 for Ely Eisley | 01/01/2019 | 31/12/2019 | 3. Simplicity               | <p>We do our utmost to deliver the easy to use solutions, exceeding customers&#39  |     |
 90008768 | Performance Review - 2nd Semester 2019 for Ely Eisley | 01/01/2019 | 31/12/2019 | 4. Exceptional Performance  | <p>Highest level of performance, with a heart for people.</p>                      | Yes | 3
(4 rows)

Сообщите мне, поможет ли это

0 голосов
/ 05 мая 2020

Вы можете указать «LOG ERRORS SEGMENT REJECT LIMIT 10» в определении внешней таблицы. Таким образом, сегмент будет пропускать строки с ошибками. Затем вы можете вернуться и проследить детали с помощью "select * from gp_read_error_log ('external_table_name');" Из примера видно, что у вас есть лишняя запятая в поле. Попробуйте указать QUOTE '"' после HEADER.

...