helpers.sql 1.5 KB

1234567891011121314151617181920212223242526272829303132
  1. -- Copyright Materialize, Inc. and contributors. All rights reserved.
  2. --
  3. -- Licensed under the Apache License, Version 2.0 (the "License");
  4. -- you may not use this file except in compliance with the License.
  5. -- You may obtain a copy of the License in the LICENSE file at the
  6. -- root of this repository, or online at
  7. --
  8. -- http://www.apache.org/licenses/LICENSE-2.0
  9. --
  10. -- Unless required by applicable law or agreed to in writing, software
  11. -- distributed under the License is distributed on an "AS IS" BASIS,
  12. -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. -- See the License for the specific language governing permissions and
  14. -- limitations under the License.
  15. {% macro materialize__reset_csv_table(model, full_refresh, old_relation, agate_table, cluster) %}
  16. {% set sql = "" %}
  17. -- Allow setting a cluster configuration for seeds in `dbt_project.yml` or
  18. -- a .yml file in the seed target path. If no cluster is configured, use
  19. -- the target cluster from `profiles.yml`. If none exists, fall back to the
  20. -- default cluster configured for the connected user.
  21. {%- set cluster = model['config'].get('cluster', target.cluster) -%}
  22. {% if full_refresh %}
  23. {{ adapter.drop_relation(old_relation) }}
  24. {% set sql = create_csv_table(model, agate_table) %}
  25. {% else %}
  26. {{ truncate_relation_sql(old_relation, cluster) }}
  27. {% set sql = "delete from " ~ old_relation.render() %}
  28. {% endif %}
  29. {{ return(sql) }}
  30. {% endmacro %}