コード例 #1
0
ファイル: test_person_query.py プロジェクト: akbansa/posthog
def testdata(db, team):
    materialize("person", "email")
    _create_person(
        distinct_ids=["1"],
        team_id=team.pk,
        properties={
            "email": "*****@*****.**",
            "$os": "windows",
            "$browser": "chrome"
        },
    )
    _create_person(
        distinct_ids=["2"],
        team_id=team.pk,
        properties={
            "email": "*****@*****.**",
            "$os": "Mac",
            "$browser": "firefox"
        },
    )
    _create_person(
        distinct_ids=["3"],
        team_id=team.pk,
        properties={
            "email": "*****@*****.**",
            "$os": "windows",
            "$browser": "mozilla"
        },
    )
コード例 #2
0
        def fn_with_materialized(self, *args, **kwargs):
            # Don't run these tests under non-clickhouse classes even if decorated in base classes
            if not getattr(self, "RUN_MATERIALIZED_COLUMN_TESTS", False):
                return

            for prop in event_properties:
                materialize("events", prop)
            for prop in person_properties:
                materialize("person", prop)

            try:
                with self.capture_select_queries() as sqls:
                    fn(self, *args, **kwargs)
            finally:
                for prop in event_properties:
                    column_name = get_materialized_columns("events")[prop]
                    sync_execute(
                        f"ALTER TABLE events DROP COLUMN {column_name}")
                for prop in person_properties:
                    column_name = get_materialized_columns("person")[prop]
                    sync_execute(
                        f"ALTER TABLE person DROP COLUMN {column_name}")

            if verify_no_jsonextract:
                for sql in sqls:
                    self.assertNotIn("JSONExtract", sql)
                    self.assertNotIn("properties", sql)
コード例 #3
0
    def setup(self):
        for table, property in MATERIALIZED_PROPERTIES:
            if property not in get_materialized_columns(table):
                materialize(table, property)
                backfill_materialized_columns(
                    table, [property], backfill_period=timedelta(days=1_000))

        # :TRICKY: Data in benchmark servers has ID=2
        team = Team.objects.filter(id=2).first()
        if team is None:
            organization = Organization.objects.create()
            team = Team.objects.create(id=2,
                                       organization=organization,
                                       name="The Bakery")
        self.team = team

        cohort = Cohort.objects.filter(name="benchmarking cohort").first()
        if cohort is None:
            cohort = Cohort.objects.create(
                team_id=2,
                name="benchmarking cohort",
                groups=[{
                    "properties": [{
                        "key": "email",
                        "operator": "icontains",
                        "value": ".com",
                        "type": "person"
                    }]
                }],
            )
            cohort.calculate_people_ch(pending_version=0)
        self.cohort = cohort
コード例 #4
0
ファイル: test_person_query.py プロジェクト: GalDayan/posthog
def testdata(db, team):
    materialize("person", "email")
    _create_person(distinct_ids=["1"],
                   team_id=team.pk,
                   properties={"email": "*****@*****.**"})
    _create_person(distinct_ids=["2"],
                   team_id=team.pk,
                   properties={"email": "*****@*****.**"})
    _create_person(distinct_ids=["3"],
                   team_id=team.pk,
                   properties={"email": "*****@*****.**"})
コード例 #5
0
    def test_denormalised_props(self):
        filters = {
            "events": [
                {
                    "id": "user signed up",
                    "type": "events",
                    "order": 0,
                    "properties": [{
                        "key": "test_prop",
                        "value": "hi"
                    }],
                },
            ],
            "date_from":
            "2020-01-01",
            "properties": [{
                "key": "test_prop",
                "value": "hi"
            }],
            "date_to":
            "2020-01-14",
        }

        materialize("events", "test_prop")

        p1 = Person.objects.create(team_id=self.team.pk,
                                   distinct_ids=["p1"],
                                   properties={"key": "value"})
        _create_event(
            team=self.team,
            event="$pageview",
            distinct_id="p1",
            timestamp="2020-01-02T12:00:00Z",
            properties={"test_prop": "hi"},
        )

        p2 = Person.objects.create(team_id=self.team.pk,
                                   distinct_ids=["p2"],
                                   properties={"key_2": "value_2"})
        _create_event(
            team=self.team,
            event="$pageview",
            distinct_id="p2",
            timestamp="2020-01-02T12:00:00Z",
            properties={"test_prop": "hi"},
        )

        filter = Filter(data=filters)
        _, query = self._run_query(filter)
        self.assertIn("mat_test_prop", query)
コード例 #6
0
    def test_materialized_columns_checks(self):
        optimizer = lambda: ColumnOptimizer(FILTER_WITH_PROPERTIES, self.team.
                                            id)

        self.assertEqual(optimizer().event_columns_to_query, {"properties"})
        self.assertEqual(optimizer().person_columns_to_query, {"properties"})

        materialize("events", "event_prop")
        materialize("person", "person_prop")

        self.assertEqual(optimizer().event_columns_to_query,
                         {"mat_event_prop"})
        self.assertEqual(optimizer().person_columns_to_query,
                         {"pmat_person_prop"})