From 76c7a839ae6f5989ec05ce16fa9e7bb750b3ca7b Mon Sep 17 00:00:00 2001 From: Shekar Siri Date: Fri, 17 Jan 2025 15:17:18 +0100 Subject: [PATCH] change(api): ch query updaets - monitors - sessions with 4xx .. --- api/chalicelib/core/sessions/sessions_ch.py | 14 ++++++++------ api/chalicelib/utils/sql_helper.py | 7 ++++++- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/api/chalicelib/core/sessions/sessions_ch.py b/api/chalicelib/core/sessions/sessions_ch.py index 454af1e41..c6dd00bb8 100644 --- a/api/chalicelib/core/sessions/sessions_ch.py +++ b/api/chalicelib/core/sessions/sessions_ch.py @@ -159,12 +159,14 @@ def search2_table(data: schemas.SessionsSearchPayloadSchema, project_id: int, de extra_conditions[e.operator].value.append(v) extra_conditions = list(extra_conditions.values()) elif metric_of == schemas.MetricOfTable.FETCH: - extra_event = f"""SELECT DISTINCT ev.session_id, ev.url_path - FROM {exp_ch_helper.get_main_events_table(data.startTimestamp)} AS ev - WHERE ev.`_timestamp` >= toDateTime(%(startDate)s / 1000) - AND ev.`_timestamp` <= toDateTime(%(endDate)s / 1000) - AND ev.project_id = %(project_id)s - AND ev.`$event_name` = 'REQUEST'""" + extra_event = f"""SELECT DISTINCT ev.session_id, + JSONExtractString(toString(ev.`$properties`), 'url_path') AS url_path + FROM {exp_ch_helper.get_main_events_table(data.startTimestamp)} AS ev + WHERE ev.`_timestamp` >= toDateTime(%(startDate)s / 1000) + AND ev.`_timestamp` <= toDateTime(%(endDate)s / 1000) + AND ev.project_id = %(project_id)s + AND ev.`$event_name` = 'REQUEST'""" + extra_deduplication.append("url_path") extra_conditions = {} for e in data.events: diff --git a/api/chalicelib/utils/sql_helper.py b/api/chalicelib/utils/sql_helper.py index 723755863..23c0078c4 100644 --- a/api/chalicelib/utils/sql_helper.py +++ b/api/chalicelib/utils/sql_helper.py @@ -3,7 +3,7 @@ from enum import Enum import schemas -def get_sql_operator(op: Union[schemas.SearchEventOperator, schemas.ClickEventExtraOperator]): +def get_sql_operator(op: Union[schemas.SearchEventOperator, schemas.ClickEventExtraOperator, schemas.MathOperator]): return { schemas.SearchEventOperator.IS: "=", schemas.SearchEventOperator.ON: "=", @@ -21,6 +21,11 @@ def get_sql_operator(op: Union[schemas.SearchEventOperator, schemas.ClickEventEx schemas.ClickEventExtraOperator.NOT_CONTAINS: "NOT ILIKE", schemas.ClickEventExtraOperator.STARTS_WITH: "ILIKE", schemas.ClickEventExtraOperator.ENDS_WITH: "ILIKE", + + schemas.MathOperator.GREATER: ">", + schemas.MathOperator.GREATER_EQ: ">=", + schemas.MathOperator.LESS: "<", + schemas.MathOperator.LESS_EQ: "<=", }.get(op, "=")