Implement parsing of the USING functions for data transformations.

This commit is contained in:
Dimitri Fontaine 2013-07-30 22:32:47 -07:00
parent 800df8e91d
commit 96e81d3f76

View File

@ -117,7 +117,8 @@ Here's a quick description of the format we're parsing here:
(def-keyword-rule "not") (def-keyword-rule "not")
(def-keyword-rule "to") (def-keyword-rule "to")
(def-keyword-rule "null") (def-keyword-rule "null")
(def-keyword-rule "default")) (def-keyword-rule "default")
(def-keyword-rule "using"))
(defrule kw-auto-increment (and "auto_increment" (* (or #\Tab #\Space))) (defrule kw-auto-increment (and "auto_increment" (* (or #\Tab #\Space)))
(:constant :auto-increment)) (:constant :auto-increment))
@ -372,10 +373,23 @@ Here's a quick description of the format we're parsing here:
(apply #'append source) (apply #'append source)
(list :type type :drop-default drop-default :drop-not-null drop-not-null)))) (list :type type :drop-default drop-default :drop-not-null drop-not-null))))
(defrule cast-rule (and cast-source cast-def) (defun function-name-character-p (char)
(or (member char #.(quote (coerce "/:.-%" 'list)))
(alphanumericp char)))
(defrule function-name (* (function-name-character-p character))
(:text t))
(defrule cast-function (and kw-using function-name)
(:lambda (function)
(destructuring-bind (using fname) function
(declare (ignore using))
(intern (string-upcase fname) :pgloader.transforms))))
(defrule cast-rule (and cast-source cast-def (? cast-function))
(:lambda (cast) (:lambda (cast)
(destructuring-bind (source target) cast (destructuring-bind (source target function) cast
(list :source source :target target)))) (list :source source :target target :using function))))
(defrule another-cast-rule (and #\, ignore-whitespace cast-rule) (defrule another-cast-rule (and #\, ignore-whitespace cast-rule)
(:lambda (source) (:lambda (source)
@ -421,9 +435,9 @@ LOAD FROM http:///tapoueh.org/db.t
create indexes, create indexes,
reset sequences; reset sequences;
SET guc_1 = 'value', guc_2 = 'other value'; SET guc_1 = 'value', guc_2 = 'other value';
CAST column col1 to timestamptz drop default, CAST column col1 to timestamptz drop default using zero-dates-to-null,
type varchar to text, type varchar to text,
type int with extra auto_increment to bigserial, type int with extra auto_increment to bigserial,
type datetime to timestamptz drop default, type datetime to timestamptz drop default using zero-dates-to-null,
type date drop not null drop default; type date drop not null drop default using zero-dates-to-null;
")) "))