Skip to content

Commit 84f6b15

Browse files
authored
feat: add new columns to pr analyzed (IN-872) (#3662)
Signed-off-by: Gašper Grom <gasper.grom@gmail.com>
1 parent 2177419 commit 84f6b15

5 files changed

Lines changed: 81 additions & 2 deletions
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
SCHEMA >
2+
`id` String,
3+
`sourceId` String,
4+
`openedAt` DateTime64(3),
5+
`segmentId` String,
6+
`channel` String,
7+
`memberId` String,
8+
`organizationId` String,
9+
`gitChangedLinesBucket` String,
10+
`assignedAt` Nullable(DateTime64(3)),
11+
`reviewRequestedAt` Nullable(DateTime64(3)),
12+
`reviewedAt` Nullable(DateTime64(3)),
13+
`approvedAt` Nullable(DateTime64(3)),
14+
`closedAt` Nullable(DateTime64(3)),
15+
`mergedAt` Nullable(DateTime64(3)),
16+
`resolvedAt` Nullable(DateTime64(3)),
17+
`assignedInSeconds` Nullable(Int64),
18+
`reviewRequestedInSeconds` Nullable(Int64),
19+
`reviewedInSeconds` Nullable(Int64),
20+
`closedInSeconds` Nullable(Int64),
21+
`mergedInSeconds` Nullable(Int64),
22+
`resolvedInSeconds` Nullable(Int64),
23+
`platform` String,
24+
`numberOfPatchsets` Nullable(Int64),
25+
`snapshotId` DateTime
26+
27+
ENGINE ReplacingMergeTree
28+
ENGINE_PARTITION_KEY toYYYYMM(snapshotId)
29+
ENGINE_SORTING_KEY snapshotId, segmentId, channel, openedAt, gitChangedLinesBucket, sourceId, id
30+
ENGINE_TTL toDateTime(snapshotId) + toIntervalDay(1)

services/libs/tinybird/datasources/pull_requests_analyzed.datasource

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ DESCRIPTION >
1010
- `gitChangedLinesBucket` categorizes the PR size by lines changed.
1111
- `assignedAt`, `reviewRequestedAt`, `reviewedAt`, `approvedAt`, `closedAt`, `mergedAt`, `resolvedAt` track workflow stage timestamps (nullable).
1212
- `assignedInSeconds`, `reviewRequestedInSeconds`, `reviewedInSeconds`, `closedInSeconds`, `mergedInSeconds`, `resolvedInSeconds` are computed durations for each stage (nullable).
13+
- `platform` is the source platform (GitHub, GitLab, Gerrit, etc.) inherited from activities.
14+
- `numberOfPatchsets` is the count of patchsets for Gerrit changesets (nullable, only applicable to Gerrit).
1315

1416
TAGS "Pull request analytics", "Developer workflow metrics"
1517

@@ -35,6 +37,8 @@ SCHEMA >
3537
`closedInSeconds` Nullable(Int64),
3638
`mergedInSeconds` Nullable(Int64),
3739
`resolvedInSeconds` Nullable(Int64),
40+
`platform` String,
41+
`numberOfPatchsets` Nullable(Int64),
3842
`snapshotId` DateTime
3943

4044
ENGINE MergeTree

services/libs/tinybird/pipes/pull_request_analysis_baseline_merge_MV.pipe

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ SQL >
1414
gitChangedLinesBucket,
1515
memberId,
1616
organizationId,
17+
platform,
1718
updatedAt
1819
FROM activityRelations_enrich_clean_snapshot_MV_ds
1920
where
@@ -30,6 +31,7 @@ SQL >
3031
'merge_request-review-changes-requested',
3132
'changeset_comment-created',
3233
'patchset_comment-created',
34+
'patchset-created',
3335
'pull_request-reviewed',
3436
'merge_request-review-approved',
3537
'patchset_approval-created',
@@ -84,6 +86,11 @@ SQL >
8486
timestamp,
8587
type IN ('pull_request-opened', 'merge_request-opened', 'changeset-created')
8688
) AS organizationId,
89+
argMinIf(
90+
platform,
91+
timestamp,
92+
type IN ('pull_request-opened', 'merge_request-opened', 'changeset-created')
93+
) AS platform,
8794
minIf(
8895
timestamp, type IN ('pull_request-opened', 'merge_request-opened', 'changeset-created')
8996
) AS openedAt,
@@ -92,6 +99,7 @@ SQL >
9299
timestamp,
93100
type IN ('pull_request-opened', 'merge_request-opened', 'changeset-created')
94101
) AS openedUpdatedAt,
102+
toInt64(countIf(type = 'patchset-created')) AS numberOfPatchsets,
95103
argMin(
96104
updatedAt, if(type IN ('pull_request-assigned', 'merge_request-assigned'), timestamp, NULL)
97105
) AS assignedUpdatedAt,
@@ -243,6 +251,7 @@ SQL >
243251
'merge_request-review-changes-requested',
244252
'changeset_comment-created',
245253
'patchset_comment-created',
254+
'patchset-created',
246255
'merge_request-review-approved',
247256
'patchset_approval-created',
248257
'pull_request-closed',
@@ -354,6 +363,12 @@ SQL >
354363
IF(
355364
resolvedAt IS NULL, NULL, toUnixTimestamp(resolvedAt) - toUnixTimestamp(openedAt)
356365
) AS resolvedInSeconds,
366+
if(existing.platform != '', existing.platform, new.platform) as platform,
367+
if(
368+
new.numberOfPatchsets > 0,
369+
COALESCE(existing.numberOfPatchsets, 0) + new.numberOfPatchsets,
370+
existing.numberOfPatchsets
371+
) as numberOfPatchsets,
357372
toStartOfInterval(
358373
greatest(
359374
COALESCE(new.openedUpdatedAt, existing.snapshotId, toDateTime(0)),

services/libs/tinybird/pipes/pull_request_analysis_copy_pipe.pipe

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ SQL >
1111
segmentId,
1212
gitChangedLinesBucket,
1313
memberId,
14-
organizationId
14+
organizationId,
15+
platform
1516
FROM activityRelations_deduplicated_cleaned_ds
1617
WHERE type = 'pull_request-opened' OR type = 'merge_request-opened' OR type = 'changeset-created'
1718

@@ -86,6 +87,16 @@ SQL >
8687
OR type = 'changeset-abandoned'
8788
GROUP BY sourceParentId
8889

90+
NODE patchsets_count
91+
DESCRIPTION >
92+
Count the number of patchsets for each Gerrit changeset
93+
94+
SQL >
95+
SELECT sourceParentId, toInt64(COUNT(*)) AS numberOfPatchsets
96+
FROM activityRelations_deduplicated_cleaned_ds
97+
WHERE type = 'patchset-created'
98+
GROUP BY sourceParentId
99+
89100
NODE pull_request_analysis_results_merged
90101
SQL >
91102
SELECT
@@ -125,7 +136,9 @@ SQL >
125136
) AS mergedInSeconds,
126137
IF(
127138
resolvedAt IS NULL, NULL, toUnixTimestamp(resolvedAt) - toUnixTimestamp(openedAt)
128-
) AS resolvedInSeconds
139+
) AS resolvedInSeconds,
140+
pr_opened.platform,
141+
patchsets.numberOfPatchsets
129142
FROM pull_request_opened pr_opened
130143
LEFT JOIN pull_request_first_assigned AS assigned ON pr_opened.sourceId = assigned.sourceParentId
131144
LEFT JOIN
@@ -137,6 +150,7 @@ SQL >
137150
LEFT JOIN pull_request_first_closed AS closed ON pr_opened.sourceId = closed.sourceParentId
138151
LEFT JOIN pull_request_first_merged AS merged ON pr_opened.sourceId = merged.sourceParentId
139152
LEFT JOIN pull_request_first_resolved as resolved on pr_opened.sourceId = resolved.sourceParentId
153+
LEFT JOIN patchsets_count AS patchsets ON pr_opened.sourceId = patchsets.sourceParentId
140154

141155
TYPE COPY
142156
TARGET_DATASOURCE pull_requests_analyzed

services/libs/tinybird/pipes/pull_request_analysis_initial_snapshot.pipe

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ SQL >
1212
gitChangedLinesBucket,
1313
memberId,
1414
organizationId,
15+
platform,
1516
updatedAt
1617
FROM activityRelations_deduplicated_cleaned_ds
1718
WHERE
@@ -111,6 +112,18 @@ SQL >
111112
)
112113
GROUP BY sourceParentId
113114

115+
NODE patchsets_count
116+
DESCRIPTION >
117+
Count the number of patchsets for each Gerrit changeset
118+
119+
SQL >
120+
SELECT sourceParentId, toInt64(COUNT(*)) AS numberOfPatchsets
121+
FROM activityRelations_deduplicated_cleaned_ds
122+
WHERE
123+
snapshotId = (select max(snapshotId) from activityRelations_deduplicated_cleaned_ds)
124+
AND type = 'patchset-created'
125+
GROUP BY sourceParentId
126+
114127
NODE pull_request_analysis_results_merged
115128
SQL >
116129
SELECT
@@ -151,6 +164,8 @@ SQL >
151164
IF(
152165
resolvedAt IS NULL, NULL, toUnixTimestamp(resolvedAt) - toUnixTimestamp(openedAt)
153166
) AS resolvedInSeconds,
167+
pr_opened.platform,
168+
patchsets.numberOfPatchsets,
154169
toStartOfInterval(
155170
greatest(
156171
pr_opened.updatedAt,
@@ -176,6 +191,7 @@ SQL >
176191
LEFT JOIN pull_request_first_closed AS closed ON pr_opened.sourceId = closed.sourceParentId
177192
LEFT JOIN pull_request_first_merged AS merged ON pr_opened.sourceId = merged.sourceParentId
178193
LEFT JOIN pull_request_first_resolved as resolved on pr_opened.sourceId = resolved.sourceParentId
194+
LEFT JOIN patchsets_count AS patchsets ON pr_opened.sourceId = patchsets.sourceParentId
179195

180196
TYPE COPY
181197
TARGET_DATASOURCE pull_requests_analyzed

0 commit comments

Comments
 (0)