@@ -4,8 +4,8 @@ use crate::{
44 ChatRevenueResponse , ClusterAnalyticsFilter , ClusterTopicsClickhouse ,
55 ComponentAnalyticsFilter , ComponentInteractionTimeResponse , ComponentNamesResponse ,
66 DatasetAnalytics , EventAnalyticsFilter , EventData , EventDataClickhouse , EventNameAndCounts ,
7- EventNamesFilter , FloatTimePoint , FloatTimePointClickhouse , FollowupQueriesResponse ,
8- FollowupQuery , GetEventsResponseBody , Granularity , HeadQueries , IntegerTimePoint ,
7+ FloatTimePoint , FloatTimePointClickhouse , FollowupQueriesResponse , FollowupQuery ,
8+ GetEventsResponseBody , Granularity , HeadQueries , IntegerTimePoint ,
99 IntegerTimePointClickhouse , MessagesPerUserResponse , Pool , PopularChat ,
1010 PopularChatsResponse , PopularFilters , PopularFiltersClickhouse , RAGAnalyticsFilter ,
1111 RAGSortBy , RAGUsageGraphResponse , RAGUsageResponse , RagQueryEvent , RagQueryEventClickhouse ,
@@ -1858,9 +1858,10 @@ pub async fn get_topic_queries_query(
18581858 AVG(rag_queries.top_score) as top_score,
18591859 AVG(rag_queries.hallucination_score) as hallucination_score,
18601860 AVG(JSONExtract(query_rating, 'rating', 'Nullable(Float64)')) as query_rating,
1861- 'View' as status
1861+ groupArray(topic_events.event_name) as event_names
18621862 FROM topics
18631863 JOIN rag_queries ON topics.topic_id = rag_queries.topic_id
1864+ JOIN events as topic_events ON rag_queries.id = toUUID(topic_events.request_id)
18641865 " ,
18651866 ) ;
18661867
@@ -1924,7 +1925,7 @@ pub async fn get_topic_queries_query(
19241925 ( page. unwrap_or( 1 ) - 1 ) * 10
19251926 ) ) ;
19261927
1927- let mut topics = clickhouse_client
1928+ let topics = clickhouse_client
19281929 . query ( query_string. as_str ( ) )
19291930 . bind ( dataset_id)
19301931 . fetch_all :: < TopicAnalyticsSummaryClickhouse > ( )
@@ -1934,37 +1935,6 @@ pub async fn get_topic_queries_query(
19341935 ServiceError :: InternalServerError ( "Error fetching topics" . to_string ( ) )
19351936 } ) ?;
19361937
1937- let topic_ids: Vec < uuid:: Uuid > = topics. iter ( ) . map ( |topic| topic. topic_id ) . collect ( ) ;
1938-
1939- let topic_events: Vec < TopicIdEventTypePair > = clickhouse_client
1940- . query (
1941- "SELECT rag_queries.topic_id as topic_id, events.event_name as event_name
1942- FROM events
1943- JOIN rag_queries ON rag_queries.id = toUUIDOrNull(events.request_id)
1944- WHERE rag_queries.dataset_id = ? AND rag_queries.topic_id in ?" ,
1945- )
1946- . bind ( dataset_id)
1947- . bind ( topic_ids)
1948- . fetch_all :: < TopicIdEventTypePair > ( )
1949- . await
1950- . map_err ( |e| {
1951- log:: error!( "Error fetching query: {:?}" , e) ;
1952- ServiceError :: InternalServerError ( "Error fetching query" . to_string ( ) )
1953- } ) ?;
1954-
1955- for topic_pair in topic_events {
1956- if let Some ( topic) = topics
1957- . iter_mut ( )
1958- . find ( |t| t. topic_id == topic_pair. topic_id )
1959- {
1960- let current_status = EventNamesFilter :: from_string ( & topic. status ) ;
1961- let topic_status = EventNamesFilter :: from_string ( & topic_pair. event_name ) ;
1962-
1963- if topic_status > current_status {
1964- topic. status = topic_pair. event_name . clone ( ) ;
1965- }
1966- }
1967- }
19681938 Ok ( TopicQueriesResponse {
19691939 topics : topics. into_iter ( ) . map ( |t| t. into ( ) ) . collect ( ) ,
19701940 } )
0 commit comments