mirror of
https://github.com/dimitri/pgloader.git
synced 2025-08-07 23:07:00 +02:00
Improve error handling when applying Citus distribution rules.
Make it so that we generate a proper error message to the user when failing to figure out the PATH to the distribution key, rather than failing with an internal error about The value NIL is not of type PGLOADER.CATALOG:TABLE.
This commit is contained in:
parent
f07ac61269
commit
aa8ae159e2
@ -347,11 +347,16 @@
|
|||||||
|
|
||||||
;; apply catalog level transformations to support the database migration
|
;; apply catalog level transformations to support the database migration
|
||||||
;; that's CAST rules, index WHERE clause rewriting and ALTER commands
|
;; that's CAST rules, index WHERE clause rewriting and ALTER commands
|
||||||
|
(handler-case
|
||||||
(process-catalog copy catalog
|
(process-catalog copy catalog
|
||||||
:alter-table alter-table
|
:alter-table alter-table
|
||||||
:alter-schema alter-schema
|
:alter-schema alter-schema
|
||||||
:distribute distribute)
|
:distribute distribute)
|
||||||
|
|
||||||
|
(citus-rule-is-missing-from-list (e)
|
||||||
|
(log-message :fatal "~a" e)
|
||||||
|
(return-from copy-database)))
|
||||||
|
|
||||||
;; if asked, first drop/create the tables on the PostgreSQL side
|
;; if asked, first drop/create the tables on the PostgreSQL side
|
||||||
(handler-case
|
(handler-case
|
||||||
(progn
|
(progn
|
||||||
|
@ -298,7 +298,8 @@
|
|||||||
#:pgloader.monitor)
|
#:pgloader.monitor)
|
||||||
(:export #:citus-distribute-schema
|
(:export #:citus-distribute-schema
|
||||||
#:citus-format-sql-select
|
#:citus-format-sql-select
|
||||||
#:citus-backfill-table-p))
|
#:citus-backfill-table-p
|
||||||
|
#:citus-rule-is-missing-from-list))
|
||||||
|
|
||||||
(defpackage #:pgloader.utils
|
(defpackage #:pgloader.utils
|
||||||
(:use #:cl
|
(:use #:cl
|
||||||
|
@ -172,6 +172,18 @@
|
|||||||
;;; itself to the table-citus-rule slot so that we later know to generate a
|
;;; itself to the table-citus-rule slot so that we later know to generate a
|
||||||
;;; proper SELECT query that includes the backfilling.
|
;;; proper SELECT query that includes the backfilling.
|
||||||
;;;
|
;;;
|
||||||
|
(define-condition citus-rule-is-missing-from-list (error)
|
||||||
|
((rule :initarg :rule :accessor citus-rule))
|
||||||
|
(:report
|
||||||
|
(lambda (err stream)
|
||||||
|
(let ((*print-circle* nil))
|
||||||
|
(format stream
|
||||||
|
"Failed to add column ~s to table ~a for lack of a FROM clause in the distribute rule:~% distribute ~a using ~a from ?"
|
||||||
|
(column-name (citus-distributed-rule-using (citus-rule err)))
|
||||||
|
(format-table-name (citus-distributed-rule-table (citus-rule err)))
|
||||||
|
(format-table-name (citus-distributed-rule-table (citus-rule err)))
|
||||||
|
(column-name (citus-distributed-rule-using (citus-rule err))))))))
|
||||||
|
|
||||||
(defgeneric apply-citus-rule (rule)
|
(defgeneric apply-citus-rule (rule)
|
||||||
(:documentation "Apply a Citus distribution RULE to given TABLE."))
|
(:documentation "Apply a Citus distribution RULE to given TABLE."))
|
||||||
|
|
||||||
@ -206,28 +218,41 @@
|
|||||||
;; it up in the last entry of the FROM rule's list.
|
;; it up in the last entry of the FROM rule's list.
|
||||||
(let* ((last-from-rule (car (last (citus-distributed-rule-from rule))))
|
(let* ((last-from-rule (car (last (citus-distributed-rule-from rule))))
|
||||||
(column-definition
|
(column-definition
|
||||||
|
(when last-from-rule
|
||||||
(find (column-name (citus-distributed-rule-using rule))
|
(find (column-name (citus-distributed-rule-using rule))
|
||||||
(table-field-list last-from-rule)
|
(table-field-list last-from-rule)
|
||||||
:test #'string=
|
:test #'string=
|
||||||
:key #'column-name))
|
:key #'column-name)))
|
||||||
(new-column
|
(new-column
|
||||||
|
(when column-definition
|
||||||
(make-column :name (column-name column-definition)
|
(make-column :name (column-name column-definition)
|
||||||
:type-name (column-type-name column-definition)
|
:type-name (column-type-name column-definition)
|
||||||
:nullable (column-nullable column-definition)
|
:nullable (column-nullable column-definition)
|
||||||
:transform (column-transform column-definition))))
|
:transform (column-transform column-definition)))))
|
||||||
|
|
||||||
|
(if column-definition
|
||||||
|
(progn
|
||||||
;;
|
;;
|
||||||
;; Here also we need to add the new column to the PKEY definition,
|
;; Here also we need to add the new column to the PKEY
|
||||||
;; in first position.
|
;; definition, in first position.
|
||||||
;;
|
;;
|
||||||
(add-column-to-pkey table (column-name new-column))
|
(add-column-to-pkey table (column-name new-column))
|
||||||
|
|
||||||
;;
|
;;
|
||||||
;; We need to backfill the distribution key in the data, which
|
;; We need to backfill the distribution key in the data,
|
||||||
;; we're implementing with a JOIN when we SELECT from the source
|
;; which we're implementing with a JOIN when we SELECT from
|
||||||
;; table. We add the new field here.
|
;; the source table. We add the new field here.
|
||||||
;;
|
;;
|
||||||
(push new-column (table-field-list table))
|
(push new-column (table-field-list table))
|
||||||
(push new-column (table-column-list table))))))
|
(push new-column (table-column-list table)))
|
||||||
|
|
||||||
|
;;
|
||||||
|
;; We don't have any table-field-list in the citus rule,
|
||||||
|
;; meaning that the distribute ... using ... clause is lacking
|
||||||
|
;; the FROM part, and we need it.
|
||||||
|
;;
|
||||||
|
(error
|
||||||
|
(make-condition 'citus-rule-is-missing-from-list :rule rule)))))))
|
||||||
|
|
||||||
|
|
||||||
(defun add-column-to-pkey (table column-name)
|
(defun add-column-to-pkey (table column-name)
|
||||||
|
Loading…
Reference in New Issue
Block a user