catalog.sql 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. -- Copyright 2020 Josh Wills. All rights reserved.
  2. -- Copyright Materialize, Inc. and contributors. All rights reserved.
  3. --
  4. -- Licensed under the Apache License, Version 2.0 (the "License");
  5. -- you may not use this file except in compliance with the License.
  6. -- You may obtain a copy of the License in the LICENSE file at the
  7. -- root of this repository, or online at
  8. --
  9. -- http://www.apache.org/licenses/LICENSE-2.0
  10. --
  11. -- Unless required by applicable law or agreed to in writing, software
  12. -- distributed under the License is distributed on an "AS IS" BASIS,
  13. -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. -- See the License for the specific language governing permissions and
  15. -- limitations under the License.
  16. {% macro materialize__get_catalog(information_schema, schemas) -%}
  17. {% set database = information_schema.database %}
  18. {{ adapter.verify_database(database) }}
  19. {%- call statement('catalog', fetch_result=True) -%}
  20. select
  21. d.name as table_database,
  22. s.name as table_schema,
  23. o.name as table_name,
  24. case when o.type = 'materialized-view' then 'materialized_view'
  25. --This macro is used for the dbt documentation. We use
  26. --the source type in mz_sources here instead of that
  27. --in mz_objects to correctly report subsources.
  28. when o.type = 'source' and so.type = 'subsource' then so.type
  29. when o.type = 'source' and so.type = 'progress' then so.type
  30. else o.type end as table_type,
  31. obj_desc.comment as table_comment,
  32. c.name as column_name,
  33. c.position as column_index,
  34. c.type as column_type,
  35. col_desc.comment as column_comment,
  36. r.name as table_owner
  37. from mz_objects o
  38. join mz_schemas s on o.schema_id = s.id
  39. join mz_databases d on s.database_id = d.id and d.name = '{{ database }}'
  40. join mz_columns c on c.id = o.id
  41. join mz_roles r on o.owner_id = r.id
  42. left join mz_sources so on o.id = so.id
  43. left outer join mz_internal.mz_comments obj_desc on (o.id = obj_desc.id and obj_desc.object_sub_id is null)
  44. left outer join mz_internal.mz_comments col_desc on (o.id = col_desc.id and col_desc.object_sub_id = c.position)
  45. where s.name in (
  46. {%- for schema in schemas -%}
  47. '{{ schema }}' {%- if not loop.last %}, {% endif -%}
  48. {%- endfor -%}
  49. )
  50. {%- endcall -%}
  51. {{ return(load_result('catalog').table) }}
  52. {%- endmacro %}