dbt-labs / dbt-labs/dbt-adapters

[Bug] [Microbatch] _render_event_time_filtered compares timestamp column with string literal

Open
#365 1 comment 0 reactions 0 assignees View on GitHub
feature:microbatch triage:awaiting-response type:bug
Dominant language
Python
Stars
233
Forks
362
Avg merge
3d 22h
Merged PRs (30d)
9

Description

### Is this a new bug?

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

### Current Behavior

[_render_event_time_filtered](https://github.com/dbt-labs/dbt-adapters/blob/v1.10.3/dbt/adapters/base/relation.py#L254) compares a timestamp column with a string literal.

Currently, filter condition evaluates to something like:

```sql
event_time >= '2020-01-01 00:00:00+00:00'
```

Since `event_time` column is expected to be of a datetime type, this will only work on platforms that support implicit type coercion between strings and datetime types.

### Expected Behavior

`event_time` column is compared with a timestamp literal:
```sql
event_time >= timestamp '2020-01-01 00:00:00+00:00'
```

or with a value explicitly cast to a timestamp:
```sql
event_time >= cast('2020-01-01 00:00:00+00:00' as timestamp)
```

### Steps To Reproduce

Run incremental model with microbatch strategy and inspect queried sqls.

### Relevant log output

_No response_

### Environment

```markdown
dbt-adapters: v1.10.3
```

### Additional Context

It can be hardcoded in an f-string as below:
```python
filter = f"{event_time_filter.field_name} >= timestamp '{event_time_filter.start}'"
```

or maybe we could use [convert_datetime_type](https://github.com/dbt-labs/dbt-adapters/blob/v1.10.3/dbt/adapters/sql/impl.py#L90) function, which returns a datetime type specific to the adapter.

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.