Skip to content

Commit

Permalink
Improve sexp parser and standard symbols support.
Browse files Browse the repository at this point in the history
Also add split-sequence to the list of special cases that we can use and is
not found in the pgloader.transforms package.

Fixes dimitri#965.
  • Loading branch information
dimitri committed May 14, 2019
1 parent 501cbed commit 12e7880
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 6 deletions.
24 changes: 18 additions & 6 deletions src/parsers/command-sexp.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -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 #\\ #\")))

Expand All @@ -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)))

Expand Down
1 change: 1 addition & 0 deletions test/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
29 changes: 29 additions & 0 deletions test/csv-using-sexp.load
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions test/regress/expected/csv-using-sexp.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
1 Hello World
2 Hello World
2 foobar foobaz

0 comments on commit 12e7880

Please sign in to comment.