Skip to content

Commit

Permalink
Merge branch 'main' into feature/AdapterOverrideUnspecifiedValue
Browse files Browse the repository at this point in the history
  • Loading branch information
steffen030 authored Sep 5, 2024
2 parents 9648bd7 + c310bc5 commit a2bee65
Show file tree
Hide file tree
Showing 25 changed files with 283 additions and 52 deletions.
13 changes: 13 additions & 0 deletions .changes/1.4.0.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
## dbt-adapters 1.4.0 - July 30, 2024

### Features

- render 'to' and 'to_columns' fields on foreign key constraints, and bump dbt-common lower bound to 1.6 ([#271](https://github.com/dbt-labs/dbt-adapters/issues/271))

### Fixes

- Incremental table varchar column definition changed ([#276](https://github.com/dbt-labs/dbt-adapters/issues/276))

### Under the Hood

- Rework record/replay to record at the database connection level. ([#244](https://github.com/dbt-labs/dbt-adapters/issues/244))
13 changes: 13 additions & 0 deletions .changes/1.4.1.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
## dbt-adapters 1.4.1 - August 09, 2024

### Fixes

- Use model alias for the CTE identifier generated during ephemeral materialization ([#5273](https://github.com/dbt-labs/dbt-adapters/issues/5273))

### Under the Hood

- Updating changie.yaml to add contributors and PR links ([#219](https://github.com/dbt-labs/dbt-adapters/issues/219))

### Contributors
- [@jeancochrane](https://github.com/jeancochrane) ([#5273](https://github.com/dbt-labs/dbt-adapters/issues/5273))
- [@leahwicz](https://github.com/leahwicz) ([#219](https://github.com/dbt-labs/dbt-adapters/issues/219))
6 changes: 6 additions & 0 deletions .changes/unreleased/Features-20240621-143024.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
kind: Features
body: Compare 'snapshot_get_time' and snapshot 'updated_at' data types
time: 2024-06-21T14:30:24.336219-04:00
custom:
Author: gshank
Issue: "242"
6 changes: 0 additions & 6 deletions .changes/unreleased/Under the Hood-20240625-110833.yaml

This file was deleted.

92 changes: 74 additions & 18 deletions .changie.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ headerPath: header.tpl.md
versionHeaderPath: ""
changelogPath: CHANGELOG.md
versionExt: md
envPrefix: CHANGIE_
envPrefix: "CHANGIE_"
versionFormat: '## dbt-adapters {{.Version}} - {{.Time.Format "January 02, 2006"}}'
kindFormat: '### {{.Kind}}'
changeFormat: |-
Expand All @@ -15,11 +15,11 @@ changeFormat: |-
{{- $IssueList = append $IssueList $changeLink }}
{{- end -}}
- {{.Body}} ({{ range $index, $element := $IssueList }}{{if $index}}, {{end}}{{$element}}{{end}})
kinds:
- label: Breaking Changes
- label: Features
- label: Fixes
- label: Docs
- label: Under the Hood
- label: Dependencies
changeFormat: |-
Expand All @@ -32,14 +32,14 @@ kinds:
- {{.Body}} ({{ range $index, $element := $PRList }}{{if $index}}, {{end}}{{$element}}{{end}})
skipGlobalChoices: true
additionalChoices:
- key: Author
label: GitHub Username(s) (separated by a single space if multiple)
type: string
minLength: 3
- key: PR
label: GitHub Pull Request Number (separated by a single space if multiple)
type: string
minLength: 1
- key: Author
label: GitHub Username(s) (separated by a single space if multiple)
type: string
minLength: 3
- key: PR
label: GitHub Pull Request Number (separated by a single space if multiple)
type: string
minLength: 1
- label: Security
changeFormat: |-
{{- $PRList := list }}
Expand All @@ -51,20 +51,22 @@ kinds:
- {{.Body}} ({{ range $index, $element := $PRList }}{{if $index}}, {{end}}{{$element}}{{end}})
skipGlobalChoices: true
additionalChoices:
- key: Author
label: GitHub Username(s) (separated by a single space if multiple)
type: string
minLength: 3
- key: PR
label: GitHub Pull Request Number (separated by a single space if multiple)
type: string
minLength: 1
- key: Author
label: GitHub Username(s) (separated by a single space if multiple)
type: string
minLength: 3
- key: PR
label: GitHub Pull Request Number (separated by a single space if multiple)
type: string
minLength: 1

newlines:
afterChangelogHeader: 1
afterKind: 1
afterChangelogVersion: 1
beforeKind: 1
endOfVersion: 1

custom:
- key: Author
label: GitHub Username(s) (separated by a single space if multiple)
Expand All @@ -74,3 +76,57 @@ custom:
label: GitHub Issue Number (separated by a single space if multiple)
type: string
minLength: 1


footerFormat: |
{{- $contributorDict := dict }}
{{- /* ensure all names in this list are all lowercase for later matching purposes */}}
{{- $core_team := splitList " " .Env.CORE_TEAM }}
{{- /* ensure we always skip snyk and dependabot in addition to the core team */}}
{{- $maintainers := list "dependabot[bot]" "snyk-bot"}}
{{- range $team_member := $core_team }}
{{- $team_member_lower := lower $team_member }}
{{- $maintainers = append $maintainers $team_member_lower }}
{{- end }}
{{- range $change := .Changes }}
{{- $authorList := splitList " " $change.Custom.Author }}
{{- /* loop through all authors for a single changelog */}}
{{- range $author := $authorList }}
{{- $authorLower := lower $author }}
{{- /* we only want to include non-core team contributors */}}
{{- if not (has $authorLower $maintainers)}}
{{- $changeList := splitList " " $change.Custom.Author }}
{{- $IssueList := list }}
{{- $changeLink := $change.Kind }}
{{- if or (eq $change.Kind "Dependencies") (eq $change.Kind "Security") }}
{{- $changes := splitList " " $change.Custom.PR }}
{{- range $issueNbr := $changes }}
{{- $changeLink := "[#nbr](https://github.com/dbt-labs/dbt-adapters/pull/nbr)" | replace "nbr" $issueNbr }}
{{- $IssueList = append $IssueList $changeLink }}
{{- end -}}
{{- else }}
{{- $changes := splitList " " $change.Custom.Issue }}
{{- range $issueNbr := $changes }}
{{- $changeLink := "[#nbr](https://github.com/dbt-labs/dbt-adapters/issues/nbr)" | replace "nbr" $issueNbr }}
{{- $IssueList = append $IssueList $changeLink }}
{{- end -}}
{{- end }}
{{- /* check if this contributor has other changes associated with them already */}}
{{- if hasKey $contributorDict $author }}
{{- $contributionList := get $contributorDict $author }}
{{- $contributionList = concat $contributionList $IssueList }}
{{- $contributorDict := set $contributorDict $author $contributionList }}
{{- else }}
{{- $contributionList := $IssueList }}
{{- $contributorDict := set $contributorDict $author $contributionList }}
{{- end }}
{{- end}}
{{- end}}
{{- end }}
{{- /* no indentation here for formatting so the final markdown doesn't have unneeded indentations */}}
{{- if $contributorDict}}
### Contributors
{{- range $k,$v := $contributorDict }}
- [@{{$k}}](https://github.com/{{$k}}) ({{ range $index, $element := $v }}{{if $index}}, {{end}}{{$element}}{{end}})
{{- end }}
{{- end }}
2 changes: 1 addition & 1 deletion .github/actions/build-hatch/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ runs:

- name: Upload artifacts
if: ${{ inputs.archive-name != '' }}
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: ${{ inputs.archive-name }}
path: ${{ inputs.working-dir }}dist/
Expand Down
2 changes: 1 addition & 1 deletion .github/actions/publish-pypi/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ runs:
steps:

- name: Download artifacts
uses: actions/download-artifact@v3
uses: actions/download-artifact@v4
with:
name: ${{ inputs.archive-name }}
path: dist/
Expand Down
2 changes: 1 addition & 1 deletion .github/actions/publish-results/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ runs:
run: echo "ts=$(date +'%Y-%m-%dT%H-%M-%S')" >> $GITHUB_OUTPUT #no colons allowed for artifacts
shell: bash

- uses: actions/upload-artifact@v3
- uses: actions/upload-artifact@v4
with:
name: ${{ inputs.file-name }}_python-${{ inputs.python-version }}_${{ steps.timestamp.outputs.ts }}.csv
path: ${{ inputs.source-file }}
2 changes: 1 addition & 1 deletion .github/actions/setup-hatch/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ runs:
using: composite
steps:
- name: Set up Python ${{ inputs.python-version }}
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: ${{ inputs.python-version }}

Expand Down
12 changes: 12 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,25 @@ updates:
schedule:
interval: "daily"
rebase-strategy: "disabled"
ignore:
- dependency-name: "*"
update-types:
- version-update:semver-patch
- package-ecosystem: "pip"
directory: "/dbt-tests-adapter"
schedule:
interval: "daily"
rebase-strategy: "disabled"
ignore:
- dependency-name: "*"
update-types:
- version-update:semver-patch
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "weekly"
rebase-strategy: "disabled"
ignore:
- dependency-name: "*"
update-types:
- version-update:semver-patch
29 changes: 29 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,35 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html),
and is generated by [Changie](https://github.com/miniscruff/changie).

## dbt-adapters 1.4.1 - August 09, 2024

### Fixes

- Use model alias for the CTE identifier generated during ephemeral materialization ([#5273](https://github.com/dbt-labs/dbt-adapters/issues/5273))

### Under the Hood

- Updating changie.yaml to add contributors and PR links ([#219](https://github.com/dbt-labs/dbt-adapters/issues/219))

### Contributors
- [@jeancochrane](https://github.com/jeancochrane) ([#5273](https://github.com/dbt-labs/dbt-adapters/issues/5273))
- [@leahwicz](https://github.com/leahwicz) ([#219](https://github.com/dbt-labs/dbt-adapters/issues/219))


## dbt-adapters 1.4.0 - July 30, 2024

### Features

- render 'to' and 'to_columns' fields on foreign key constraints, and bump dbt-common lower bound to 1.6 ([#271](https://github.com/dbt-labs/dbt-adapters/issues/271))

### Fixes

- Incremental table varchar column definition changed ([#276](https://github.com/dbt-labs/dbt-adapters/issues/276))

### Under the Hood

- Rework record/replay to record at the database connection level. ([#244](https://github.com/dbt-labs/dbt-adapters/issues/244))

## dbt-adapters 1.3.3 - July 09, 2024

### Fixes
Expand Down
3 changes: 2 additions & 1 deletion dbt-tests-adapter/dbt/tests/adapter/constraints/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,8 @@
- type: check
expression: id >= 1
- type: foreign_key
expression: {schema}.foreign_key_model (id)
to: ref('foreign_key_model')
to_columns: ["id"]
- type: unique
data_tests:
- unique
Expand Down
2 changes: 1 addition & 1 deletion dbt/adapters/__about__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version = "1.3.3"
version = "1.4.1"
3 changes: 0 additions & 3 deletions dbt/adapters/base/column.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,6 @@ def numeric_type(cls, dtype: str, precision: Any, scale: Any) -> str:
else:
return "{}({},{})".format(dtype, precision, scale)

def __repr__(self) -> str:
return "<Column {} ({})>".format(self.name, self.data_type)

@classmethod
def from_description(cls, name: str, raw_data_type: str) -> "Column":
match = re.match(r"([^(]+)(\([^)]+\))?", raw_data_type)
Expand Down
34 changes: 24 additions & 10 deletions dbt/adapters/base/impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -1602,8 +1602,13 @@ def render_column_constraint(cls, constraint: ColumnLevelConstraint) -> Optional
rendered_column_constraint = f"unique {constraint_expression}"
elif constraint.type == ConstraintType.primary_key:
rendered_column_constraint = f"primary key {constraint_expression}"
elif constraint.type == ConstraintType.foreign_key and constraint_expression:
rendered_column_constraint = f"references {constraint_expression}"
elif constraint.type == ConstraintType.foreign_key:
if constraint.to and constraint.to_columns:
rendered_column_constraint = (
f"references {constraint.to} ({', '.join(constraint.to_columns)})"
)
elif constraint_expression:
rendered_column_constraint = f"references {constraint_expression}"
elif constraint.type == ConstraintType.custom and constraint_expression:
rendered_column_constraint = constraint_expression

Expand Down Expand Up @@ -1682,20 +1687,29 @@ def render_model_constraint(cls, constraint: ModelLevelConstraint) -> Optional[s
rendering."""
constraint_prefix = f"constraint {constraint.name} " if constraint.name else ""
column_list = ", ".join(constraint.columns)
rendered_model_constraint = None

if constraint.type == ConstraintType.check and constraint.expression:
return f"{constraint_prefix}check ({constraint.expression})"
rendered_model_constraint = f"{constraint_prefix}check ({constraint.expression})"
elif constraint.type == ConstraintType.unique:
constraint_expression = f" {constraint.expression}" if constraint.expression else ""
return f"{constraint_prefix}unique{constraint_expression} ({column_list})"
rendered_model_constraint = (
f"{constraint_prefix}unique{constraint_expression} ({column_list})"
)
elif constraint.type == ConstraintType.primary_key:
constraint_expression = f" {constraint.expression}" if constraint.expression else ""
return f"{constraint_prefix}primary key{constraint_expression} ({column_list})"
elif constraint.type == ConstraintType.foreign_key and constraint.expression:
return f"{constraint_prefix}foreign key ({column_list}) references {constraint.expression}"
rendered_model_constraint = (
f"{constraint_prefix}primary key{constraint_expression} ({column_list})"
)
elif constraint.type == ConstraintType.foreign_key:
if constraint.to and constraint.to_columns:
rendered_model_constraint = f"{constraint_prefix}foreign key ({column_list}) references {constraint.to} ({', '.join(constraint.to_columns)})"
elif constraint.expression:
rendered_model_constraint = f"{constraint_prefix}foreign key ({column_list}) references {constraint.expression}"
elif constraint.type == ConstraintType.custom and constraint.expression:
return f"{constraint_prefix}{constraint.expression}"
else:
return None
rendered_model_constraint = f"{constraint_prefix}{constraint.expression}"

return rendered_model_constraint

@classmethod
def capabilities(cls) -> CapabilityDict:
Expand Down
7 changes: 5 additions & 2 deletions dbt/adapters/base/relation.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,8 +241,11 @@ def create_ephemeral_from(
relation_config: RelationConfig,
limit: Optional[int] = None,
) -> Self:
# Note that ephemeral models are based on the name.
identifier = cls.add_ephemeral_prefix(relation_config.name)
# Note that ephemeral models are based on the identifier, which will
# point to the model's alias if one exists and otherwise fall back to
# the filename. This is intended to give the user more control over
# the way that the CTE name is constructed
identifier = cls.add_ephemeral_prefix(relation_config.identifier)
return cls.create(
type=cls.CTE,
identifier=identifier,
Expand Down
4 changes: 2 additions & 2 deletions dbt/adapters/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ def get_include_paths(self, name: Optional[str]) -> List[Path]:
def get_adapter_type_names(self, name: Optional[str]) -> List[str]:
return [p.adapter.type() for p in self.get_adapter_plugins(name)]

def get_adapter_constraint_support(self, name: Optional[str]) -> List[str]:
def get_adapter_constraint_support(self, name: Optional[str]) -> Dict[str, str]:
return self.lookup_adapter(name).CONSTRAINT_SUPPORT # type: ignore


Expand Down Expand Up @@ -251,7 +251,7 @@ def get_adapter_type_names(name: Optional[str]) -> List[str]:
return FACTORY.get_adapter_type_names(name)


def get_adapter_constraint_support(name: Optional[str]) -> List[str]:
def get_adapter_constraint_support(name: Optional[str]) -> Dict[str, str]:
return FACTORY.get_adapter_constraint_support(name)


Expand Down
8 changes: 8 additions & 0 deletions dbt/include/global_project/macros/adapters/timestamps.sql
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@
{{ current_timestamp() }}
{% endmacro %}

{% macro get_snapshot_get_time_data_type() %}
{% set snapshot_time = adapter.dispatch('snapshot_get_time', 'dbt')() %}
{% set time_data_type_sql = 'select ' ~ snapshot_time ~ ' as dbt_snapshot_time' %}
{% set snapshot_time_column_schema = get_column_schema_from_query(time_data_type_sql) %}
{% set time_data_type = snapshot_time_column_schema[0].dtype %}
{{ return(time_data_type or none) }}
{% endmacro %}

---------------------------------------------

/* {#
Expand Down
Loading

0 comments on commit a2bee65

Please sign in to comment.