mirror of
https://github.com/PostHog/posthog.git
synced 2024-11-28 18:26:15 +01:00
457e151f58
* Refactor column_optimizer to work differently * WIP: Use counter over set * Handle person filters in person query * Remove a dead argument * Use enum over parameter for determining behavior * Allow excluding person properties mode when handled in person query * Fix _get_person_query type * Use correct table for funnel_event_query * Remove unneeded override * Add extra typing * Filter by entity.properties in person query for trends * Handle error 184 due to naming clash * Better default for prop_filter_json_extract * Update column_optimizer tests for Counter * Handle person_props as extra_fields * Handle breakdowns and person property filter pushdown * Transform values correctly * Simplify get_entity_filtering_params * Fix funnel correlations * Solve caching issues in trend people queries * Remove @skip test * Add syrupy tests for parse_prop_clauses Can update these via --snapshot-update * Add snapshot tests for person queries * Add a few notes * Update test to avoid collision * Kill dead code * Handle PR comments * Update ee/clickhouse/queries/person_query.py Co-authored-by: Neil Kakkar <neilkakkar@gmail.com> Co-authored-by: Neil Kakkar <neilkakkar@gmail.com>
44 lines
961 B
Python
44 lines
961 B
Python
import json
|
|
from enum import Enum, auto
|
|
from typing import Optional, Union
|
|
|
|
import pytz
|
|
from dateutil.parser import isoparse
|
|
from django.utils import timezone
|
|
|
|
|
|
class PersonPropertiesMode(Enum):
|
|
USING_SUBQUERY = auto()
|
|
USING_PERSON_PROPERTIES_COLUMN = auto()
|
|
# Used when person join handles these filters
|
|
EXCLUDE = auto()
|
|
|
|
|
|
def is_json(val):
|
|
if isinstance(val, int):
|
|
return False
|
|
|
|
try:
|
|
int(val)
|
|
return False
|
|
except:
|
|
pass
|
|
try:
|
|
json.loads(val)
|
|
except (ValueError, TypeError):
|
|
return False
|
|
return True
|
|
|
|
|
|
def cast_timestamp_or_now(timestamp: Optional[Union[timezone.datetime, str]]) -> str:
|
|
if not timestamp:
|
|
timestamp = timezone.now()
|
|
|
|
# clickhouse specific formatting
|
|
if isinstance(timestamp, str):
|
|
timestamp = isoparse(timestamp)
|
|
else:
|
|
timestamp = timestamp.astimezone(pytz.utc)
|
|
|
|
return timestamp.strftime("%Y-%m-%d %H:%M:%S.%f")
|