Skip to content

fix: mssql should only load data for the views specified by materialize views #1559

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
33 changes: 22 additions & 11 deletions src/sources/mssql/mssql.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -69,17 +69,28 @@
:excluding excluding)

;; fetch view (and their columns) metadata, covering comments too
(let* ((view-names (unless (eq :all materialize-views)
(mapcar #'matview-source-name materialize-views)))
(including
(loop :for (schema-name . view-name) :in view-names
:do (let* ((schema-name (or schema-name "dbo"))
(schema-entry
(or (assoc schema-name including :test #'string=)
(progn (push (cons schema-name nil) including)
(assoc schema-name including
:test #'string=)))))
(push-to-end view-name (cdr schema-entry))))))
(let* (
(view-names
(progn
(let
((names (unless
(eq :all materialize-views)
(mapcar #'matview-source-name materialize-views))))
;; Debugging statement
;; Return the computed value for the let* binding
names)))
(including nil)
)
(loop :for (schema-name . view-name) :in view-names
:do (let* (
(schema-name (or schema-name "dbo"))
(schema-entry (or
(assoc schema-name including :test #'string=)
(let
((new-entry (cons schema-name nil))); Initially nil, intending to be a list
(push new-entry including)
new-entry))))
(push-to-end view-name (cdr schema-entry))))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What I mean is: completely clean up the debugging alterations, and this is the indentation that should appear here:

(let* ((view-names (unless (eq :all materialize-views)
                     (mapcar #'matview-source-name materialize-views)))
       (including nil))
  (loop :for (schema-name . view-name) :in view-names
        :do (let* ((schema-name (or schema-name "dbo"))
                   (schema-entry (or
                                  (assoc schema-name including :test #'string=)
                                  (let ((new-entry (cons schema-name nil)))
                                    (push new-entry including)
                                    new-entry))))
              (push-to-end view-name (cdr schema-entry))))
  …)

I don't fully understand what's changed here yet, though

(cond (view-names
(fetch-columns catalog mssql
:including including
Expand Down
8 changes: 4 additions & 4 deletions src/sources/mssql/sql/list-all-columns.sql
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@
on c.TABLE_SCHEMA = t.TABLE_SCHEMA
and c.TABLE_NAME = t.TABLE_NAME

where c.TABLE_CATALOG = '~a'
and t.TABLE_TYPE = '~a'
~:[~*~;and (~{~a~^~&~10t or ~})~]
~:[~*~;and (~{~a~^~&~10t and ~})~]
where c.TABLE_CATALOG = '~a'
and t.TABLE_TYPE = '~a'
~:[~*~;and (~{~a~^~&~10t or ~})~]
~:[~*~;and (~{~a~^~&~10t and ~})~]

order by c.table_schema, c.table_name, c.ordinal_position;