Skip to content

fix(ingestion): normalize CRM UNION branch types to fix NO_COMMON_TYPE (#1709, #1708) - #1861

Merged
cyberantonz merged 1 commit into
constructorfabric:mainfrom
cyberantonz:fix/crm-union-no-common-type
Jul 23, 2026
Merged

fix(ingestion): normalize CRM UNION branch types to fix NO_COMMON_TYPE (#1709, #1708)#1861
cyberantonz merged 1 commit into
constructorfabric:mainfrom
cyberantonz:fix/crm-union-no-common-type

Conversation

@cyberantonz

@cyberantonz cyberantonz commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Closes #1709. Closes #1708.

Two CRM UNIONs mix incompatible numeric types, so a branch fails NO_COMMON_TYPE (ClickHouse Code 386). Both are pre-existing and masked only by the Int64/Float64-typed demo bronze; they fire on real Salesforce/HubSpot data.

#1709salesforce__crm_activities (staging)

The tasks CTE emits duration_seconds as Int64 (toInt64(CallDurationInSeconds)); the events CTE emits Float64 (DurationInMinutes * 60) because Airbyte infers DurationInMinutes as a float on real syncs → the tasks UNION ALL events has no supertype and class_crm_activities never builds (drops all CRM activity metrics).

Fix: toInt64(DurationInMinutes * 60). Int64 (not Float64) is deliberate — the hubspot__crm_activities sibling that unions into the same silver.class_crm_activities (via union_by_tag) already emits Nullable(Int64), so normalizing to Int64 keeps the cross-connector union consistent too.

#1708crm_bullet_rows (gold view, migration)

The deal_size branch passed coalesce(d.amount_home, 0) (Decimal(38,9)) while the other five UNION branches are Float64. ClickHouse resolves view column types at CREATE, so CREATE OR REPLACE VIEW threw — and since it runs inside 20260512000000_crm-gold-views.sql, every later migration silently never applied.

Fix: toFloat64(coalesce(d.amount_home, 0)) (matches the sibling branches; no-op when already Float64).

Verification

Static: both casts align each branch with its sibling/consumer type. The e2e metrics lane will confirm the models/gold still build. Note the current fixtures mask these (Int64/Float64-typed demo bronze) — a float-DurationInMinutes / Decimal-amount_home fixture would exercise the failing path directly and is a good follow-up.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Improved CRM reporting by standardizing activity duration values to the expected integer type.
    • Fixed deal size metric calculation by explicitly casting numeric outputs to a consistent floating-point type, reducing type-mismatch risks in combined CRM views.

@cyberantonz
cyberantonz requested a review from a team as a code owner July 23, 2026 02:53
@coderabbitai

coderabbitai Bot commented Jul 23, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: aa6feff2-e894-49fd-a2c2-3c4b506ad965

📥 Commits

Reviewing files that changed from the base of the PR and between 03ffe03e3221e1c412f2825fe7e83fee3950b901 and f4fdf29.

📒 Files selected for processing (2)
  • src/ingestion/connectors/crm/salesforce/dbt/salesforce__crm_activities.sql
  • src/ingestion/scripts/migrations/20260512000000_crm-gold-views.sql
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/ingestion/connectors/crm/salesforce/dbt/salesforce__crm_activities.sql
  • src/ingestion/scripts/migrations/20260512000000_crm-gold-views.sql

📝 Walkthrough

Walkthrough

CRM SQL models explicitly cast Salesforce event durations to Int64 and deal-size metrics to Float64, aligning numeric types across their respective UNION branches.

Changes

CRM numeric type normalization

Layer / File(s) Summary
Activity duration type alignment
src/ingestion/connectors/crm/salesforce/dbt/salesforce__crm_activities.sql
The Salesforce events branch casts minute-based durations to Int64 to match task durations.
Deal size metric type alignment
src/ingestion/scripts/migrations/20260512000000_crm-gold-views.sql
The deal_size metric casts the coalesced deal amount to Float64 to match other bullet-row metric branches.

Estimated code review effort: 2 (Simple) | ~10 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the CRM UNION type-normalization fix and references the affected issues.
Linked Issues check ✅ Passed The PR addresses both linked issues by casting the failing UNION branches to compatible types and preventing NO_COMMON_TYPE errors.
Out of Scope Changes check ✅ Passed The changes stay narrowly scoped to the two reported type mismatches and related comments, with no unrelated behavior changes.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

constructorfabric#1709, constructorfabric#1708)

Two CRM UNIONs mixed incompatible numeric types, so a branch failed
`NO_COMMON_TYPE` (ClickHouse Code 386):

- salesforce__crm_activities (constructorfabric#1709): tasks emit `duration_seconds` as Int64
  (`toInt64(CallDurationInSeconds)`), events as Float64
  (`DurationInMinutes * 60`) — and Airbyte infers DurationInMinutes as a float
  on real syncs. Cast events to `toInt64(DurationInMinutes * 60)` so both
  branches (and the hubspot sibling, which is Int64) share one type; the silver
  union_by_tag over both connectors stays consistent too.

- crm_bullet_rows gold view (constructorfabric#1708): the `deal_size` branch passed
  `coalesce(d.amount_home, 0)` (Decimal(38,9)) while the other five UNION
  branches are Float64, so `CREATE OR REPLACE VIEW` threw at migration time and
  aborted every later migration. Wrap it in `toFloat64(...)`.

Both are pre-existing latent bugs masked only by Int64/Float64-typed demo
bronze; they fire on real Salesforce/HubSpot data (or the placeholder Decimal
deal schema).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Signed-off-by: Anton Zelenov <antonz@constructor.tech>
@cyberantonz
cyberantonz force-pushed the fix/crm-union-no-common-type branch from 03ffe03 to f4fdf29 Compare July 23, 2026 05:22
@cyberantonz
cyberantonz enabled auto-merge (squash) July 23, 2026 05:35
@cyberantonz
cyberantonz merged commit 4ab5481 into constructorfabric:main Jul 23, 2026
35 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants