dbt-labs / dbt-labs/dbt-adapters

[Bug] Ensure column name is backticked during alter

Open
#468 0 comments 0 reactions 0 assignees View on GitHub
feature:quoting pkg:dbt-spark type:bug
Dominant language
Python
Stars
233
Forks
362
Avg merge
3d 22h
Merged PRs (30d)
9

Description

### Is this a new bug in dbt-spark?

- [X] I believe this is a new bug in dbt-spark
- [X] I have searched the existing issues, and I could not find an existing issue for this bug

### Current Behavior

When you define a model like the following and execute dbt run, new columns will be added if there are schema changes.
```
version: 2
models:
- name: table
config:
materialized: incremental
on_schema_change: append_new_columns
```

```
alter table `db`.`schema`.`table`
add columns (
new_column string
)
```

At this time, if the column name contains a hyphen, it will fail with the following error:
```
[INVALID_IDENTIFIER] The unquoted identifier column_name is invalid and must be back quoted as: `column_name`.
It would be helpful if you could either add an option to enclose column names with backticks when executing ALTER TABLE, or modify the SQL for ALTER TABLE itself.
```

### Expected Behavior

When executing alter table statement, column name is backticked.
```
alter table `db`.`schema`.`table`
add columns (
`new_column` string
)
```

### Steps To Reproduce

1. Create table with hyphen named columns
```
create table repro (
test-c string
)
```
2. Define model file as follows.
```
version: 2
models:
- name: table
config:
materialized: incremental
on_schema_change: append_new_columns
```
3. Run `dbt-run` and add new column

### Relevant log output

```shell
NA
```

### Environment

```markdown
- OS: macOS Ventura 13.2.1 (22D68)
- Python: Python 3.12.7
- dbt-core: 1.8.5
- dbt-spark: 1.8.0
```

### Additional Context

NA

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.