Improve sexp parser and standard symbols support.

Also add split-sequence to the list of special cases that we can use and is
not found in the pgloader.transforms package.

Fixes #965.
This commit is contained in:
Dimitri Fontaine 2019-05-14 15:49:24 +02:00
parent 501cbed745
commit 12e788094b
4 changed files with 51 additions and 6 deletions

View File

@ -17,11 +17,23 @@
(defrule sexp-symbol (and (symbol-first-character-p character)
(* (symbol-character-p character)))
(:lambda (schars)
(pgloader.transforms:intern-symbol
(text schars)
'(("nil" . cl:nil)
("precision" . pgloader.transforms::precision)
("scale" . pgloader.transforms::scale)))))
(if (char= #\: (car schars))
(read-from-string (text schars))
(pgloader.transforms:intern-symbol
(text schars)
'(("nil" . cl:nil)
("cl:t" . cl:t)
("precision" . pgloader.transforms::precision)
("scale" . pgloader.transforms::scale)
("split-sequence" . split-sequence:split-sequence))))))
(defrule sexp-char (and #\# #\\
(alpha-char-p character)
(+ (or (alpha-char-p character)
(digit-char-p character)
#\_)))
(:lambda (char-name)
(read-from-string (text char-name))))
(defrule sexp-string-char (or (not-doublequote character) (and #\\ #\")))
@ -40,7 +52,7 @@
(cons car cdr)))
(defrule sexp-atom (and ignore-whitespace
(or sexp-string sexp-integer sexp-symbol))
(or sexp-char sexp-string sexp-integer sexp-symbol))
(:lambda (atom)
(bind (((_ a) atom)) a)))

View File

@ -20,6 +20,7 @@ REGRESS= allcols.load \
csv-nulls.load \
csv-temp.load \
csv-trim-extra-blanks.load \
csv-using-sexp.load \
csv.load \
copy.load \
copy-hex.load \

29
test/csv-using-sexp.load Normal file
View File

@ -0,0 +1,29 @@
/*
* See https://github.com/dimitri/pgloader/issues/965
*/
LOAD CSV
FROM INLINE(id,f1)
INTO postgresql:///pgloader
TARGET TABLE sexp
(
id,
f1 text using (format nil "~{~a~^ ~}"
(split-sequence #\Space f1 :remove-empty-subseqs cl:t))
)
WITH truncate,
fields terminated by ','
BEFORE LOAD DO
$$ drop table if exists sexp; $$,
$$ CREATE TABLE sexp
(
id int,
f1 text
)
$$;
1,Hello World
2,Hello World
2, foobar foobaz

View File

@ -0,0 +1,3 @@
1 Hello World
2 Hello World
2 foobar foobaz