Skip to content
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

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

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
57 changes: 44 additions & 13 deletions src/sources/mssql/mssql.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -62,32 +62,63 @@
;; If asked to MATERIALIZE VIEWS, now is the time to create them in MS
;; SQL, when given definitions rather than existing view names.
(when (and materialize-views (not (eq :all materialize-views)))
(create-matviews materialize-views mssql))
(create-matviews materialize-views mssql)
(format t "[fetch-metadata] Materialize Views: ~A~%" materialize-views)
)

(format t "[fetch-metadata] Original including: ~A~%" including)
(fetch-columns catalog mssql
:including including
: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
(format t "[fetch-metadata] Debugging view-names: ~A~%" names)
;; 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)
(format t "[fetch-metadata:do] Debugging schema-name: ~A~%" schema-name)
new-entry
)
))
)
(push-to-end view-name (cdr schema-entry))
(format t "[fetch-metadata] Debugging schema-entry: ~A~%" schema-entry)
(format t "[fetch-metadata] Debugging schema-name: ~A~%" schema-name)
;; (push-to-end view-name (cdr schema-entry))
)
)
(format t "[fetch-metadata] New including: ~A~%" including)
(format t "[fetch-metadata] New view-names: ~A~%" view-names)
(cond (view-names
(fetch-columns catalog mssql
:including including
:excluding excluding
:table-type :view))

((eq :all materialize-views)
(fetch-columns catalog mssql :table-type :view))))
(fetch-columns catalog mssql :table-type :view)))
)

(when create-indexes
(fetch-indexes catalog mssql
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;