Skip to content

Teradata support in dbt-expectations#38

Open
vs255034 wants to merge 11 commits into
metaplane:mainfrom
vs255034:teradata_support
Open

Teradata support in dbt-expectations#38
vs255034 wants to merge 11 commits into
metaplane:mainfrom
vs255034:teradata_support

Conversation

@vs255034
Copy link
Copy Markdown

@vs255034 vs255034 commented Dec 8, 2025

Summary of Changes

This PR adds comprehensive Teradata adapter support to dbt-expectations, enabling all core data quality tests to run successfully on Teradata databases while maintaining backward compatibility with all existing adapters.

Why Do We Need These Changes

Teradata has several SQL syntax and functional differences compared to other databases that require adapter-specific implementations:

Key Teradata Limitations Addressed:
No nested CTEs: Teradata doesn't support WITH clauses inside other WITH clauses (Error 6926)
No boolean literals: Must use integers (1/0) instead of true/false (Error 5628)
Strict timestamp handling: Requires careful casting between DATE and TIMESTAMP types (Error 6760)
Limited date arithmetic: Doesn't support INTERVAL multiplication syntax (Error 3706)
DateTime operation restrictions: Hour-based dateadd operations in moving window calculations not supported (Error 5407)
FROM clause requirement: Literal SELECT statements require a FROM clause
Changes Implemented:

  1. Core Macro Adaptations (37 files changed)

Added Teradata-specific implementations using adapter dispatch pattern ({% if target.type == 'teradata' %})
Modified macros in categories:
Table shape tests: Flattened CTEs, added FROM clauses
Column value tests: Boolean literal replacements, datatype adjustments
Distributional tests: Alternative statistical calculations
Date/time tests: Conditional casting logic for DATE vs TIMESTAMP handling

  1. Integration Test Model Updates

Applied adapter dispatch to test models: data_test.sql, data_test_factored.sql, data_text.sql, timeseries_*.sql, window_function_test.sql
Added conditional date handling in timeseries_hourly.sql (current datetime for Teradata, midnight for others)
Updated schema.yml to disable incompatible hour-based moving stdevs test for Teradata

  1. Critical Macro Fixes

expect_row_values_to_have_data_for_every_n_datepart: Created Teradata-specific version with flattened CTEs, proper date arithmetic, and conditional formatting for day vs hour dateparts
get_base_dates (teradata_utils): Added conditional casting based on datepart (day uses DATE intermediate, hour preserves TIMESTAMP)
Various utility macros: md5, datatypes, groupby adaptations
Testing Results:
All dbt-expectations tests now pass on Teradata while maintaining full compatibility with existing adapters (PostgreSQL, Snowflake, BigQuery, Redshift, Spark, etc.)

Reviewers

@GuruM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants