I have a model, where videos is main table, with playbacks joined to it. Each playback has playback_key (set as primary key in model) and I want to test for its uniqueness.
I based my test on uniqueness example from docs:
test: playback_key_is_unique {
explore_source: analytics {
column: key {
field: playbacks.playback_key
}
column: count {
field: playbacks.count
}
sorts: [playbacks.count: desc]
limit: 1
}
assert: playback_key_is_unique {
expression: ${playbacks.count} = 1 ;; # generated query does count(distinct), why?
}
}
This generates following SQL:
SELECT
playbacks.playback_key AS playbacks_playback_key,
COUNT(DISTINCT playbacks.playback_key ) AS playbacks_count
FROM `analytics.videos` AS videos_new
FULL OUTER JOIN `analytics.playbacks` AS playbacks ON playbacks.video_id = videos_new.id
GROUP BY
1
ORDER BY
2 DESC
LIMIT 1
The problem is, this will always pass due to count(distinct) and test is invalid.
I can’t figure out how to fix this, so it generates the usual count() instead of distinct.