Question: Query: - - Component View Data DROP TABLE IF EXISTS SCRATCHDB.search _ rag; CREATE TABLE SCRATCHDB.search _ rag as ( select chegg _ uuid as

Query:
--Component View Data
DROP TABLE IF EXISTS SCRATCHDB.search_rag;
CREATE TABLE SCRATCHDB.search_rag
as (
select
chegg_uuid as user_uuid,
content_content_id as question_uuid,
content_metadata_multi_turn_chat_conversation_id as conversation_id,
content_metadata_search_strack_id as strackid,
content_metadata_multi_turn_chat_message_id as message_id,
content_metadata_cs_qa_solution_ids as answer_id,--control group
content_metadata_cs_qa_solution_uuids as original_answer_uuid, --treatment group
content_metadata_cs_qa_is_rag_solution as rag_flag,
content_metadata_search_result_match_badge as match_badge
from edw.riodb_enriched_prod.clickstream_component_view
where year ='2024'
and mon in ('08')
and event_time between '2023-08-05' and (CURRENT_DATE)
and view_view_version like 'mtc%'
and geo_country_code ='US'
and component_view_component_name = 'answer'
)
--Interaction Data
DROP TABLE IF EXISTS SCRATCHDB.interaction_rag;
CREATE TABLE SCRATCHDB.interaction_rag
as (
select
ci.content_metadata_search_strack_id as strack_id,
ci.chegg_uuid,
ci.event_time,
ci.interaction_element_value
from
edw.riodb_structured_prod.clickstream_interaction ci
where
ci.year in ('2024')
and ci.mon='08'
and ci.day >='05'
and ci.view_view_version ='mtc 1.0'
and ci.interaction_element_name in ('rating','ratings','submit rating')
and ci.base_event_type='web'
and ci.chegg_uuid in (select distinct user_uuid from scratchdb.search_rag where rag_flag = true)
and ci.content_metadata_search_strack_id is not null
)
Allocation Data
DROP TABLE IF EXISTS SCRATCHDB.eligible_users;
CREATE TABLE SCRATCHDB.eligible_users
as (
Select
oa.chegg_uuid as uuid,
case when oa.variant_id ='29945290389' then 'Control'
when oa.variant_id ='29931980460' then 'Test' end as Exp_Group
From
edw.riodb_enriched_prod.optimizely_allocation oa
Where
oa.year >='2024'
and oa.experiment_id ='29914610561'
and oa.variant_id in ('29945290389','29931980460')
and oa.chegg_uuid is not null
)
--Control:
Select
bq.id as question_id,
Count(Distinct rev.id) as total_ratings,
Count(Distinct case when rev.review_value =0 then rev.id end) as Positive_ratings,
((Count(Distinct case when rev.review_value =0 then rev.id end)*1.0)/(Count(Distinct rev.id)*1.0))*100 as CF_Score
From
Odsdb.review_user_entity_review rev
Join SCRATCHDB.eligible_users eu on rev.user_uuid = eu.uuid
join odsdb.board_question bq on bq.id = rev.question_id
join SCRATCHDB.search_rag s on s.user_uuid = eu.uuid and s.question_uuid = rev.question_uuid
Where
rev.entity_type =3
and rev.review_type =1
and rev.created_time >='2024-08-05'
and eu.Exp_Group = 'Control'
and s.match_badge in ('exact','EXACT_MATCH')
Group by 1;
--Treatment:
with max_event as(
select strack_id, chegg_uuid, max(event_time) as eventTime
from scratchdb.interaction_data_rag
group by 1,2
)
Select
bq.id as question_id,
Count(Distinct i.interaction_element_value) as total_ratings,
Count(Distinct case when i.interaction_element_value in ('1','positive','Positive') then i.interaction_element_value end) as Positive_ratings,
((Count(Distinct case when i.interaction_element_value in ('1','positive','Positive') then i.chegg_uuid end)*1.0)/(Count(Distinct i.interaction_element_value)*1.0))*100 as CF_Score
From
SCRATCHDB.interaction_rag i
join SCRATCHDB.search_rag s on s.user_uuid = i.chegg_uuid
join odsdb.board_answer ba on ba.uuid = s.original_answer_uuid[0]
join odsdb.board_question bq on bq.id = ba.question_id
join SCRATCHDB.eligible_users e on e.uuid = i.chegg_uuid
join max_event m on m.strack_id = i.strack_id and m.chegg_uuid = i.chegg_uuid and m.eventTime = i.event_time
Where
i.event_time >='2024-08-05'
and s.rag_flag = true
and e.exp_group = 'Test'
Group by 1;

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!