Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

qtag to map function breaks results cache for enriched query history #461

Open
rymurr opened this issue Oct 12, 2023 · 3 comments
Open

qtag to map function breaks results cache for enriched query history #461

rymurr opened this issue Oct 12, 2023 · 3 comments

Comments

@rymurr
Copy link
Contributor

rymurr commented Oct 12, 2023

qtag_to_map is a udf written in javascript and it appears that snowflake won't use results cache with a javascript UDF even if its not projected. This results on all the enriched_query_history queries taking longer than they should.

@rymurr
Copy link
Contributor Author

rymurr commented Oct 16, 2023

Removing it appears to mean one of several options:

  1. push into MV and add a migration step
  2. use something like the below to calculate w/o javascript. Same result, all done in sql so cache is respected. However this takes a long time
with fl as (
select qh.*, coalesce(value:SOURCE,'unknown') as k, value:KEY::varchar as kk, value:VALUE as v from internal_reporting_mv.query_history_complete_and_daily qh, lateral flatten(qtag) where RECORD_TYPE in ('COMPLETE_FIXED', 'DAILY') 
), grp_pre as (
select kk, any_value(v) as v, k, query_id from fl group by all
), grp as (
select object_agg(kk, v) as vv, k, query_id from grp_pre group by all
), grp2 as (
select object_agg(k, vv) as qtag_filter_2, query_id from grp group by all
)
select * from grp2

@joshelser
Copy link
Contributor

I assume it's a non-starter to push the qtag unwrapping into a downstream view, e.g. REPORTING.QTAGGED_QUERY_HISTORY? Assuming it's a non-starter, pushing into the MV seems much better but I am wary given our recent problems in doing those migrations correctly.

@rymurr
Copy link
Contributor Author

rymurr commented Oct 17, 2023

that won't get rid of the udf unless we materalize it. Like you said I am not keen on materializing it atm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: No status
Development

No branches or pull requests

2 participants