Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
- `generate_model_yaml` with `upstream_descriptions=True` now reads from upstream sources in addition to models.

## Fixes
- Fix handling of nested `STRUCT` fields in BigQuery ([#98](https://github.com/dbt-labs/dbt-codegen/issues/98), [#105](https://github.com/dbt-labs/dbt-codegen/pull/105))
- Fix `generate_source` behavior of applying a lowercase function to all object names ([#112](https://github.com/dbt-labs/dbt-codegen/issues/112))
- Column `description` fields are now correctly escaped in `generate_model_yaml` ([#142](https://github.com/dbt-labs/dbt-codegen/issues/142))

# dbt-codegen v0.11.0
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ want to subselect from all available tables within a given schema.
the database to your source definition
* `include_schema` (optional, default=False): Whether you want to add
the schema to your source definition
* `case_sensitive_tables` (optional, default=False): Whether you want table names to be
in lowercase, or to match the case in the source table
* `case_sensitive_cols` (optional, default=False): Whether you want column names to be
in lowercase, or to match the case in the source table

### Outputting to a file
If you use the `dbt run-operation` approach it is possible to output directly to a file by piping the output to a new file and using the `--quiet` CLI flag:
Expand Down
10 changes: 5 additions & 5 deletions macros/generate_source.sql
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@

{% endmacro %}

{% macro generate_source(schema_name, database_name=target.database, generate_columns=False, include_descriptions=False, include_data_types=True, table_pattern='%', exclude='', name=schema_name, table_names=None, include_database=False, include_schema=False) %}
{{ return(adapter.dispatch('generate_source', 'codegen')(schema_name, database_name, generate_columns, include_descriptions, include_data_types, table_pattern, exclude, name, table_names, include_database, include_schema)) }}
{% macro generate_source(schema_name, database_name=target.database, generate_columns=False, include_descriptions=False, include_data_types=True, table_pattern='%', exclude='', name=schema_name, table_names=None, include_database=False, include_schema=False, case_sensitive_tables=False, case_sensitive_cols=False) %}
{{ return(adapter.dispatch('generate_source', 'codegen')(schema_name, database_name, generate_columns, include_descriptions, include_data_types, table_pattern, exclude, name, table_names, include_database, include_schema, case_sensitive_tables, case_sensitive_cols)) }}
{% endmacro %}

{% macro default__generate_source(schema_name, database_name, generate_columns, include_descriptions, include_data_types, table_pattern, exclude, name, table_names, include_database, include_schema) %}
{% macro default__generate_source(schema_name, database_name, generate_columns, include_descriptions, include_data_types, table_pattern, exclude, name, table_names, include_database, include_schema, case_sensitive_tables, case_sensitive_cols) %}

{% set sources_yaml=[] %}
{% do sources_yaml.append('version: 2') %}
Expand Down Expand Up @@ -46,7 +46,7 @@
{% endif %}

{% for table in tables %}
{% do sources_yaml.append(' - name: ' ~ table | lower ) %}
{% do sources_yaml.append(' - name: ' ~ (table if case_sensitive_tables else table | lower)) %}
Copy link

Choose a reason for hiding this comment

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

Would it make sense to have the name still as lower case but add the uncased as identifier?

Copy link
Author

@jgillies jgillies Nov 2, 2023

Choose a reason for hiding this comment

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

Ah, I never knew about the distinction between table and identifier in sources. Makes sense to use identifier!

Copy link
Author

Choose a reason for hiding this comment

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

Actually, I believe this is assigning the relation's identifier to the table variable, so no change would be necessary to pick up the logic you're suggesting. Does that make sense?

{% set table_list= tables | map(attribute='identifier') %}

{% if include_descriptions %}
{% do sources_yaml.append(' description: ""' ) %}
{% endif %}
Expand All @@ -62,7 +62,7 @@
{% set columns=adapter.get_columns_in_relation(table_relation) %}

{% for column in columns %}
{% do sources_yaml.append(' - name: ' ~ column.name | lower ) %}
{% do sources_yaml.append(' - name: ' ~ (column.name if case_sensitive_cols else column.name | lower)) %}
{% if include_data_types %}
{% do sources_yaml.append(' data_type: ' ~ codegen.data_type_format_source(column)) %}
{% endif %}
Expand Down