Last active
January 4, 2017 05:55
-
-
Save pavlov99/b4f5eeb14c99fb8bf2f81d9bf532598d to your computer and use it in GitHub Desktop.
Check groups overlap
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Data example: | |
// id group | |
// 1 A | |
// 2 A | |
// 2 B | |
// In this case object `2` belongs to both groups "A" and "B" | |
val overlappedGroups = groups.select($"id", $"group" as "_group") | |
groups | |
.join(overlappedGroups, (groups("id") === overlappedGroups("id")) && ($"group" < $"_group")) // NOTE: group A < group B, so duplicates (A,B) (B,A) would be removed. | |
.groupBy("group", "_group") | |
.count() | |
.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment