Add BEFORE/AFTER LOAD clauses to IXF and DBF commands.

This commit is contained in:
Dimitri Fontaine 2014-07-17 16:56:13 +02:00
parent f352b39284
commit 07b5aa3ed6
5 changed files with 46 additions and 12 deletions

View File

@ -127,7 +127,7 @@ pgloader-standalone:
--compress-core \ --compress-core \
--output $(PGLOADER) --output $(PGLOADER)
test: test: $(PGLOADER)
$(MAKE) PGLOADER=$(realpath $(PGLOADER)) -C test regress $(MAKE) PGLOADER=$(realpath $(PGLOADER)) -C test regress
deb: docs deb: docs

View File

@ -1345,7 +1345,10 @@ load database
(declare (ignore load dbf from)) (declare (ignore load dbf from))
source))) source)))
(defrule load-dbf-optional-clauses (* (or dbf-options gucs)) (defrule load-dbf-optional-clauses (* (or dbf-options
gucs
before-load
after-load))
(:lambda (clauses-list) (:lambda (clauses-list)
(alexandria:alist-plist clauses-list))) (alexandria:alist-plist clauses-list)))
@ -1356,13 +1359,16 @@ load database
(defrule load-dbf-file load-dbf-command (defrule load-dbf-file load-dbf-command
(:lambda (command) (:lambda (command)
(destructuring-bind (source pg-db-uri &key ((:dbf-options options)) gucs) (destructuring-bind (source pg-db-uri
&key ((:dbf-options options)) gucs before after)
command command
(destructuring-bind (&key dbname table-name &allow-other-keys) (destructuring-bind (&key dbname table-name &allow-other-keys)
pg-db-uri pg-db-uri
`(lambda () `(lambda ()
(let* ((state-before (pgloader.utils:make-pgstate)) (let* ((state-before (pgloader.utils:make-pgstate))
(*state* (pgloader.utils:make-pgstate)) (summary (null *state*))
(*state* (or *state* (pgloader.utils:make-pgstate)))
(state-after ,(when after `(pgloader.utils:make-pgstate)))
,@(pgsql-connection-bindings pg-db-uri gucs) ,@(pgsql-connection-bindings pg-db-uri gucs)
,@(batch-control-bindings options) ,@(batch-control-bindings options)
(source (source
@ -1388,12 +1394,19 @@ load database
:source source :source source
:target ,table-name))) :target ,table-name)))
,(sql-code-block dbname 'state-before before "before load")
(pgloader.sources:copy-from source (pgloader.sources:copy-from source
:state-before state-before :state-before state-before
,@(remove-batch-control-option options)) ,@(remove-batch-control-option options))
(report-full-summary "Total import time" *state* ,(sql-code-block dbname 'state-after after "after load")
:before state-before)))))))
;; reporting
(when summary
(report-full-summary "Total import time" *state*
:before state-before
:finally state-after))))))))
#| #|
@ -1417,7 +1430,10 @@ load database
(declare (ignore load ixf from)) (declare (ignore load ixf from))
source))) source)))
(defrule load-ixf-optional-clauses (* (or ixf-options gucs)) (defrule load-ixf-optional-clauses (* (or ixf-options
gucs
before-load
after-load))
(:lambda (clauses-list) (:lambda (clauses-list)
(alexandria:alist-plist clauses-list))) (alexandria:alist-plist clauses-list)))
@ -1428,13 +1444,16 @@ load database
(defrule load-ixf-file load-ixf-command (defrule load-ixf-file load-ixf-command
(:lambda (command) (:lambda (command)
(destructuring-bind (source pg-db-uri &key ((:ixf-options options)) gucs) (destructuring-bind (source pg-db-uri
&key ((:ixf-options options)) gucs before after)
command command
(destructuring-bind (&key dbname table-name &allow-other-keys) (destructuring-bind (&key dbname table-name &allow-other-keys)
pg-db-uri pg-db-uri
`(lambda () `(lambda ()
(let* ((state-before (pgloader.utils:make-pgstate)) (let* ((state-before (pgloader.utils:make-pgstate))
(*state* (pgloader.utils:make-pgstate)) (summary (null *state*))
(*state* (or *state* (pgloader.utils:make-pgstate)))
(state-after ,(when after `(pgloader.utils:make-pgstate)))
,@(pgsql-connection-bindings pg-db-uri gucs) ,@(pgsql-connection-bindings pg-db-uri gucs)
,@(batch-control-bindings options) ,@(batch-control-bindings options)
(source (source
@ -1460,12 +1479,18 @@ load database
:source source :source source
:target ,table-name))) :target ,table-name)))
,(sql-code-block dbname 'state-before before "before load")
(pgloader.sources:copy-from source (pgloader.sources:copy-from source
:state-before state-before :state-before state-before
,@(remove-batch-control-option options)) ,@(remove-batch-control-option options))
(report-full-summary "Total import time" *state* ,(sql-code-block dbname 'state-after after "after load")
:before state-before)))))))
(when summary
(report-full-summary "Total import time" *state*
:before state-before
:finally state-after))))))))
#| #|

View File

@ -16,6 +16,7 @@ REGRESS= allcols.load \
dbf.load \ dbf.load \
errors.load \ errors.load \
fixed.load \ fixed.load \
ixf.load \
overflow.load \ overflow.load \
partial.load \ partial.load \
serial.load \ serial.load \

View File

@ -1,4 +1,8 @@
LOAD IXF LOAD IXF
FROM data/nsitra.test1.ixf FROM data/nsitra.test1.ixf
INTO postgresql:///pgloader?nsitra.test1 INTO postgresql:///pgloader?nsitra.test1
WITH truncate, create table; WITH truncate, create table
BEFORE LOAD DO
$$ create schema if not exists nsitra; $$,
$$ drop table if exists nsitra.test1; $$;

View File

@ -0,0 +1,4 @@
1 77 77 foobar foobar baz baz
2 \N 88 \N abcdef \N ghijkl
3 179 179 FOOBAR FOOBAR BAZ BAZ
4 \N 179 \N FOOBAR \N BAZ