Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/tinybird/datasources/dub_audit_logs.datasource
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
TOKEN dub_tinybird_token APPEND
TOKEN "dub_tinybird_token" APPEND


SCHEMA >
`id` String `json:$.id`,
Expand Down
8 changes: 6 additions & 2 deletions packages/tinybird/datasources/dub_click_events.datasource
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
TOKEN dub_tinybird_token APPEND
TOKEN "dub_tinybird_token" APPEND


SCHEMA >
`timestamp` DateTime64(3) `json:$.timestamp`,
Expand Down Expand Up @@ -31,7 +32,10 @@ SCHEMA >
`qr` UInt8 `json:$.qr`,
`continent` LowCardinality(String) `json:$.continent`,
`vercel_region` Nullable(String) `json:$.vercel_region`,
`trigger` String `json:$.trigger`
`trigger` String `json:$.trigger`,
`workspace_id` Nullable(String) `json:$.workspace_id`,
`domain` Nullable(String) `json:$.domain`,
`key` Nullable(String) `json:$.key`

ENGINE "MergeTree"
ENGINE_PARTITION_KEY "toYYYYMM(timestamp)"
Expand Down
28 changes: 16 additions & 12 deletions packages/tinybird/datasources/dub_click_events_id.datasource
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,37 @@
SCHEMA >
`timestamp` DateTime64(3),
`click_id` String,
`workspace_id` LowCardinality(String),
`link_id` String,
`domain` String,
`key` String,
`url` String,
`continent` LowCardinality(String),
`country` LowCardinality(String),
`city` String,
`region` String,
`city` LowCardinality(String),
`region` LowCardinality(String),
`latitude` String,
`longitude` String,
`device` LowCardinality(String),
`browser` LowCardinality(String),
`os` LowCardinality(String),
`trigger` String,
`ua` String,
`referer` String,
`referer_url` String,
`ip` String,
`identity_hash` String,
`device_model` LowCardinality(String),
`device_vendor` LowCardinality(String),
`browser` LowCardinality(String),
`browser_version` String,
`os` LowCardinality(String),
`os_version` String,
`engine` LowCardinality(String),
`engine_version` String,
`cpu_architecture` LowCardinality(String),
`ua` String,
`bot` UInt8,
`referer` String,
`referer_url` String,
`identity_hash` Nullable(String),
`ip` String,
`qr` UInt8,
`trigger` String
`bot` UInt8

ENGINE "MergeTree"
ENGINE_PARTITION_KEY "toYYYYMM(timestamp)"
ENGINE_PARTITION_KEY "tuple()"
ENGINE_SORTING_KEY "click_id"
ENGINE_SETTINGS "index_granularity = 256"
22 changes: 16 additions & 6 deletions packages/tinybird/datasources/dub_click_events_mv.datasource
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,36 @@
SCHEMA >
`timestamp` DateTime64(3),
`click_id` String,
`workspace_id` LowCardinality(String),
`link_id` String,
`domain` String,
`key` String,
`url` String,
`continent` LowCardinality(String),
`country` LowCardinality(String),
`city` String,
`region` String,
`city` LowCardinality(String),
`region` LowCardinality(String),
`latitude` String,
`longitude` String,
`device` LowCardinality(String),
`browser` LowCardinality(String),
`os` LowCardinality(String),
`trigger` String,
`engine` LowCardinality(String),
`ua` String,
`identity_hash` String,
`referer` String,
`referer_url` String,
`ip` String,
`qr` UInt8
`identity_hash` String,
`device_model` LowCardinality(String),
`device_vendor` LowCardinality(String),
`browser_version` String,
`os_version` String,
`engine` LowCardinality(String),
`engine_version` String,
`cpu_architecture` LowCardinality(String),
`qr` UInt8,
`bot` UInt8

ENGINE "MergeTree"
ENGINE_PARTITION_KEY "toYYYYMM(timestamp)"
ENGINE_SORTING_KEY "link_id, timestamp"
ENGINE_SORTING_KEY "workspace_id, link_id, timestamp"
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
TOKEN dub_tinybird_token APPEND
TOKEN "dub_tinybird_token" APPEND


SCHEMA >
`timestamp` DateTime64(3) `json:$.timestamp` DEFAULT now(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
TOKEN dub_tinybird_token APPEND
TOKEN "dub_tinybird_token" APPEND


SCHEMA >
`timestamp` DateTime64(3) `json:$.timestamp` DEFAULT now(),
Expand Down
9 changes: 7 additions & 2 deletions packages/tinybird/datasources/dub_lead_events.datasource
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
TOKEN dub_tinybird_token APPEND
TOKEN "dub_tinybird_token" APPEND


SCHEMA >
`timestamp` DateTime64(3) `json:$.timestamp` DEFAULT now(),
Expand Down Expand Up @@ -30,7 +31,11 @@ SCHEMA >
`referer_url` String `json:$.referer_url`,
`ip` String `json:$.ip`,
`qr` UInt8 `json:$.qr`,
`metadata` String `json:$.metadata`
`metadata` String `json:$.metadata`,
`trigger` String `json:$.trigger`,
`domain` Nullable(String) `json:$.domain`,
`key` Nullable(String) `json:$.key`,
`workspace_id` Nullable(String) `json:$.workspace_id`

ENGINE "MergeTree"
ENGINE_PARTITION_KEY "toYYYYMM(timestamp)"
Expand Down
29 changes: 20 additions & 9 deletions packages/tinybird/datasources/dub_lead_events_mv.datasource
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,40 @@

SCHEMA >
`timestamp` DateTime64(3),
`event_id` String,
`event_name` String,
`click_id` String,
`workspace_id` LowCardinality(String),
`link_id` String,
`customer_id` String,
`domain` String,
`key` String,
`url` String,
Comment on lines +6 to 10
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

Non‑nullable fields may reject NULLs from the pipe.

workspace_id, domain, key are non‑nullable. If upstream join/coalesce yields NULL, inserts will fail. Either (a) make these columns Nullable, or (b) guarantee non‑NULLs in the pipe (see suggested fallbacks in dub_lead_events_pipe.pipe).

Option A (make columns nullable):

-    `workspace_id` LowCardinality(String),
+    `workspace_id` LowCardinality(Nullable(String)),
-    `domain` String,
-    `key` String,
+    `domain` Nullable(String),
+    `key` Nullable(String),

Option B (keep non‑nullable): keep schema as‑is and adopt the pipe changes proposed earlier.

Also applies to: 11-15, 41-41


🏁 Script executed:

#!/bin/bash
# Locate and examine the datasource file
find . -name "dub_lead_events_mv.datasource" -type f 2>/dev/null | head -5

Length of output: 61


🏁 Script executed:

#!/bin/bash
# Locate and examine the pipe file
find . -name "dub_lead_events_pipe.pipe" -type f 2>/dev/null | head -5

Length of output: 51


🏁 Script executed:

#!/bin/bash
# Search for related files in tinybird datasources directory
fd -e datasource -e pipe . packages/tinybird/ 2>/dev/null | grep -E "(dub_lead|event)" | head -20

Length of output: 1066


🏁 Script executed:

#!/bin/bash
# Examine the datasource schema file
cat packages/tinybird/datasources/dub_lead_events_mv.datasource

Length of output: 1150


🏁 Script executed:

#!/bin/bash
# Examine the pipe file
cat packages/tinybird/pipes/dub_lead_events_pipe.pipe

Length of output: 1493


Address NULL handling for workspace_id, domain, key fields.

The datasource declares workspace_id, domain, and key as non-nullable, but the upstream pipe uses coalesce() without a final fallback. If both lead_event and link_metadata sources are NULL, coalesce() returns NULL, causing insert failures.

Choose one approach:

Option A (make columns nullable):

-    `workspace_id` LowCardinality(String),
+    `workspace_id` LowCardinality(Nullable(String)),
-    `domain` String,
-    `key` String,
+    `domain` Nullable(String),
+    `key` Nullable(String),

Option B (ensure non-NULL in pipe): Add fallback values (e.g., coalesce(..., '')) to guarantee non-NULL results before insert.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
`workspace_id` LowCardinality(String),
`link_id` String,
`customer_id` String,
`domain` String,
`key` String,
`url` String,
`workspace_id` LowCardinality(Nullable(String)),
`link_id` String,
`domain` Nullable(String),
`key` Nullable(String),
`url` String,
🤖 Prompt for AI Agents
In packages/tinybird/datasources/dub_lead_events_mv.datasource around lines 6 to
10, the fields `workspace_id`, `domain`, and `key` are declared as non-nullable
but upstream uses coalesce() without a final fallback so NULLs can be inserted;
either make those columns nullable (change types to Nullable(String) or
Nullable(LowCardinality(String)) as appropriate) or update the upstream pipe to
provide a non-NULL default (wrap the existing coalesce calls with a final
fallback like '', e.g., coalesce(..., '') ) so inserts never receive NULL for
these columns — pick one approach and apply consistently for all three fields.

`event_id` String,
`event_name` String,
`customer_id` String,
`metadata` String,
`continent` LowCardinality(String),
`country` LowCardinality(String),
`city` String,
`region` String,
`city` LowCardinality(String),
`region` LowCardinality(String),
`latitude` String,
`longitude` String,
`device` LowCardinality(String),
`browser` LowCardinality(String),
`os` LowCardinality(String),
`engine` LowCardinality(String),
`trigger` String,
`ua` String,
`referer` String,
`referer_url` String,
`qr` UInt8,
`ip` String,
`metadata` String
`device_model` LowCardinality(String),
`device_vendor` LowCardinality(String),
`browser_version` String,
`os_version` String,
`engine` LowCardinality(String),
`engine_version` String,
`cpu_architecture` LowCardinality(String),
`qr` UInt8,
`bot` UInt8

ENGINE "MergeTree"
ENGINE_PARTITION_KEY "toYYYYMM(timestamp)"
ENGINE_SORTING_KEY "link_id, timestamp"
ENGINE_SORTING_KEY "workspace_id, link_id, timestamp"
3 changes: 2 additions & 1 deletion packages/tinybird/datasources/dub_links_metadata.datasource
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
TOKEN dub_tinybird_token APPEND
TOKEN "dub_tinybird_token" APPEND


SCHEMA >
`timestamp` DateTime `json:$.timestamp` DEFAULT now(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@

SCHEMA >
`timestamp` DateTime,
`workspace_id` LowCardinality(String),
`link_id` String,
`domain` String,
`key` String,
`url` String,
`program_id` LowCardinality(String),
`partner_id` String,
`folder_id` String,
`tag_ids` Array(String),
`workspace_id` String,
`created_at` DateTime64(3),
`deleted` UInt8,
`program_id` String,
`tenant_id` String,
`partner_id` String,
`folder_id` String
`created_at` DateTime64(3),
`deleted` UInt8

ENGINE "ReplacingMergeTree"
ENGINE_PARTITION_KEY "toYYYYMM(timestamp)"
ENGINE_SORTING_KEY "link_id"
ENGINE_SORTING_KEY "workspace_id, link_id"
ENGINE_VER "timestamp"
ENGINE_IS_DELETED "deleted"

This file was deleted.

9 changes: 7 additions & 2 deletions packages/tinybird/datasources/dub_sale_events.datasource
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
TOKEN dub_tinybird_token APPEND
TOKEN "dub_tinybird_token" APPEND


SCHEMA >
`timestamp` DateTime64(3) `json:$.timestamp` DEFAULT now(),
Expand Down Expand Up @@ -34,7 +35,11 @@ SCHEMA >
`referer_url` String `json:$.referer_url`,
`ip` String `json:$.ip`,
`qr` UInt8 `json:$.qr`,
`metadata` String `json:$.metadata`
`metadata` String `json:$.metadata`,
`trigger` String `json:$.trigger`,
`domain` Nullable(String) `json:$.domain`,
`key` Nullable(String) `json:$.key`,
`workspace_id` Nullable(String) `json:$.workspace_id`

ENGINE "MergeTree"
ENGINE_PARTITION_KEY "toYYYYMM(timestamp)"
Expand Down
41 changes: 0 additions & 41 deletions packages/tinybird/datasources/dub_sale_events_id.datasource

This file was deleted.

30 changes: 21 additions & 9 deletions packages/tinybird/datasources/dub_sale_events_mv.datasource
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,44 @@

SCHEMA >
`timestamp` DateTime64(3),
`event_id` String,
`event_name` String,
`click_id` String,
`workspace_id` LowCardinality(String),
`link_id` String,
`domain` String,
`key` String,
`url` String,
`event_id` String,
Comment on lines +6 to +11
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

Nullability mismatch between raw and MV can break ingestion.

Raw source defines workspace_id/domain/key as Nullable(String); MV has non-nullable String/LowCardinality(String). Inserts with NULLs will fail unless the pipe coerces to ''. Align schemas or coalesce in the pipe.

Option A — align MV schema:

-    `workspace_id` LowCardinality(String),
+    `workspace_id` LowCardinality(Nullable(String)),
-    `domain` String,
+    `domain` Nullable(String),
-    `key` String,
+    `key` Nullable(String),

Option B — keep MV non-nullable and coalesce upstream:

-- In the MV-building pipe
COALESCE(workspace_id, '') AS workspace_id,
COALESCE(domain, '') AS domain,
COALESCE(`key`, '') AS `key`,

Please confirm which approach you prefer; I can propose a full diff once chosen.

Also applies to: 17-19, 28-41


I'll help you verify this review comment by examining the datasource files and checking for the nullability mismatch. Let me start by exploring the codebase.


---

🏁 Script executed:

```shell
#!/bin/bash
# Find datasource files related to dub_sale_events
fd -e datasource | grep -i "dub_sale_events"

Length of output: 116


🏁 Script executed:

#!/bin/bash
# List all files in the tinybird datasources directory
fd . packages/tinybird/datasources --type f | head -20

Length of output: 786


🏁 Script executed:

#!/bin/bash
# Show the MV datasource file content
cat packages/tinybird/datasources/dub_sale_events_mv.datasource

Length of output: 1268


🏁 Script executed:

#!/bin/bash
# Look for the raw datasource file
fd "dub_sale_events" packages/tinybird/datasources --type f

Length of output: 116


🏁 Script executed:

#!/bin/bash
# Search for pipe files that might reference these datasources
fd -e pipe packages/tinybird/ | xargs grep -l "dub_sale_events" 2>/dev/null | head -5

Length of output: 377



---

🏁 Script executed:

```shell
#!/bin/bash
# Show the raw datasource file content
cat packages/tinybird/datasources/dub_sale_events.datasource

Length of output: 1929


🏁 Script executed:

#!/bin/bash
# Search for pipe files related to dub_sale_events with corrected syntax
fd . packages/tinybird --full-path '.*dub_sale_events.*\.pipe'

Length of output: 2007


🏁 Script executed:

#!/bin/bash
# List all pipe files in tinybird
fd -e pipe packages/tinybird/

Length of output: 377


🏁 Script executed:

#!/bin/bash
# Check the MV pipe definition
fd "dub_sale_events_pipe" packages/tinybird/ -e pipe

Length of output: 49


🏁 Script executed:

#!/bin/bash
# Show the pipe file content to see NULL handling
cat packages/tinybird/pipes/dub_sale_events_pipe.pipe

Length of output: 2043


Nullability mismatch confirmed—pipe's COALESCE insufficient without default fallback.

The raw source defines workspace_id, domain, and key as Nullable(String), while the MV expects non-nullable variants. The pipe uses coalesce(sale_event.workspace_id, link_metadata.workspace_id), but this still returns NULL when both inputs are NULL, which will fail insertion into the non-nullable MV columns.

Choose and implement one approach:

  • Option A — update MV schema to accept NULLs (lines 7, 9, 10 in dub_sale_events_mv.datasource)
  • Option B — update pipe to coalesce with empty string default (lines 7–9 in dub_sale_events_pipe.pipe)

Apply the same fix to the other affected fields at lines 17–19 and 28–41 of the MV datasource if they have the same issue.

🤖 Prompt for AI Agents
In packages/tinybird/datasources/dub_sale_events_mv.datasource around lines 6–11
(and similarly check lines 17–19 and 28–41), the MV defines workspace_id,
domain, and key as non-nullable but the pipe's coalesce can still produce NULL;
fix this by updating the pipe
(packages/tinybird/datasources/dub_sale_events_pipe.pipe, around the referenced
pipe lines 7–9 and the other affected expressions) to use a safe default in
coalesce (e.g., coalesce(sale_event.workspace_id, link_metadata.workspace_id,
'') and coalesce(...) with '' for domain and key and any other affected fields)
so the MV inserts never receive NULL, or alternatively update the MV schema to
Nullable for the listed columns if you prefer Option A (apply the same chosen
approach to the other affected fields at MV lines 17–19 and 28–41).

`event_name` String,
`customer_id` String,
`payment_processor` LowCardinality(String),
`invoice_id` String,
`amount` UInt32,
`url` String,
`sale_type` String,
`metadata` String,
`continent` LowCardinality(String),
`country` LowCardinality(String),
`city` String,
`region` String,
`city` LowCardinality(String),
`region` LowCardinality(String),
`latitude` String,
`longitude` String,
`device` LowCardinality(String),
`browser` LowCardinality(String),
`os` LowCardinality(String),
`engine` LowCardinality(String),
`trigger` String,
`ua` String,
`referer` String,
`referer_url` String,
`qr` UInt8,
`ip` String,
`metadata` String
`device_model` LowCardinality(String),
`device_vendor` LowCardinality(String),
`browser_version` String,
`os_version` String,
`engine` LowCardinality(String),
`engine_version` String,
`cpu_architecture` LowCardinality(String),
`qr` UInt8,
`bot` UInt8

ENGINE "MergeTree"
ENGINE_PARTITION_KEY "toYYYYMM(timestamp)"
ENGINE_SORTING_KEY "link_id, timestamp"
ENGINE_SORTING_KEY "workspace_id, link_id, timestamp"
3 changes: 2 additions & 1 deletion packages/tinybird/datasources/dub_webhook_events.datasource
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
TOKEN dub_tinybird_token APPEND
TOKEN "dub_tinybird_token" APPEND


SCHEMA >
`timestamp` DateTime64(3) `json:$.timestamp` DEFAULT now(),
Expand Down
13 changes: 0 additions & 13 deletions packages/tinybird/endpoints/all_stats.pipe

This file was deleted.

Loading