-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Upload static cohort csv #2932
Merged
Merged
Upload static cohort csv #2932
Changes from 9 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
ff56ded
Upload static cohort using CSV, closes #2868
timgl ea482b0
Merge branch 'master' into upload-static-cohort-csv
timgl d18dce9
fix tests
timgl 09a5c71
Fix tests
timgl 4c3d4e0
Fix e2e test
timgl def8c4c
Avoid double inserts
timgl e0442e0
Speed up query
timgl 9945cdc
Move to params
timgl b1f1898
fix tests
timgl ac56920
Use JSON instead of protobuf
timgl e42c069
unused import
timgl 715cc17
produce instead of produce_proto
timgl edcb5b3
Insert directly into clickhouse, no need for kafka
fuziontech f1e0f27
a few quick fixes
fuziontech b66001e
insert in batch to clickhouse
fuziontech 3fa2148
test SQLi since we can't really trust what we are inserting
fuziontech 96b4a44
Extra check for duplicates
timgl 9f15703
Merge branch 'upload-static-cohort-csv' of github.com:PostHog/posthog…
timgl File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
from infi.clickhouse_orm import migrations | ||
|
||
from ee.clickhouse.sql.person import KAFKA_PERSON_STATIC_COHORT_TABLE_SQL, PERSON_STATIC_COHORT_TABLE_SQL | ||
|
||
operations = [ | ||
migrations.RunSQL(PERSON_STATIC_COHORT_TABLE_SQL), | ||
migrations.RunSQL(KAFKA_PERSON_STATIC_COHORT_TABLE_SQL), | ||
] |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,7 @@ | |
from posthog.models.filters import Filter | ||
from posthog.models.organization import Organization | ||
from posthog.models.person import Person | ||
from posthog.models.team import Team | ||
from posthog.models.utils import UUIDT | ||
from posthog.test.base import BaseTest | ||
|
||
|
@@ -192,3 +193,28 @@ def test_cohort_get_person_ids_by_cohort_id(self): | |
self.assertEqual(len(results), 2) | ||
self.assertIn(user1.uuid, results) | ||
self.assertIn(user3.uuid, results) | ||
|
||
def test_insert_by_distinct_id_or_email(self): | ||
Person.objects.create(team_id=self.team.pk, properties={"email": "[email protected]"}, distinct_ids=["1"]) | ||
Person.objects.create(team_id=self.team.pk, distinct_ids=["123"]) | ||
Person.objects.create(team_id=self.team.pk, distinct_ids=["2"]) | ||
# Team leakage | ||
team2 = Team.objects.create(organization=self.organization) | ||
Person.objects.create(team=team2, properties={"email": "[email protected]"}) | ||
|
||
cohort = Cohort.objects.create(team=self.team, groups=[], is_static=True) | ||
cohort.insert_users_by_list(["[email protected]", "123"]) | ||
cohort = Cohort.objects.get() | ||
results = get_person_ids_by_cohort_id(self.team, cohort.id) | ||
self.assertEqual(len(results), 2) | ||
self.assertEqual(cohort.is_calculating, False) | ||
|
||
# If we accidentally call calculate_people it shouldn't erase people | ||
cohort.calculate_people() | ||
results = get_person_ids_by_cohort_id(self.team, cohort.id) | ||
self.assertEqual(len(results), 2) | ||
|
||
# if we add people again, don't increase the number of people in cohort | ||
cohort.insert_users_by_list(["123"]) | ||
results = get_person_ids_by_cohort_id(self.team, cohort.id) | ||
self.assertEqual(len(results), 2) |
This file contains 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
This file contains 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
syntax = "proto3"; | ||
|
||
message PersonStaticCohort { | ||
string id = 1; | ||
string person_id = 2; | ||
uint64 cohort_id = 3; | ||
uint64 team_id = 4; | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
KAFKA_EVENTS = "clickhouse_events_proto" | ||
KAFKA_PERSON = "clickhouse_person" | ||
KAFKA_PERSON_UNIQUE_ID = "clickhouse_person_unique_id" | ||
KAFKA_PERSON_STATIC_COHORT = "clickhouse_static_cohort" | ||
KAFKA_SESSION_RECORDING_EVENTS = "clickhouse_session_recording_events" | ||
KAFKA_EVENTS_WAL = "events_write_ahead_log" |
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is perfect for a proto encoded table, but the table you have defined is json encoded.
Check out producing for persons to see what producing to a json table looks like
https://github.com/PostHog/posthog/blob/master/ee/clickhouse/models/person.py#L74