[{"data":1,"prerenderedAt":3152},["ShallowReactive",2],{"article-alternates":3,"article-\u002Fit\u002Fdata\u002Farchitettura-tabella-cohort":13},{"i18nKey":4,"paths":5},"data-007-2026-06",{"de":6,"en":7,"es":8,"fr":9,"it":10,"ru":11,"tr":12},"\u002Fde\u002Fdata\u002Fcohort-table-architecture-production-scaling","\u002Fen\u002Fdata\u002Fcohort-table-architecture-scaling-retention-analysis-production","\u002Fes\u002Fdata\u002Farquitectura-tabla-cohort","\u002Ffr\u002Fdata\u002Fcohort-table-architecture-production-scaling","\u002Fit\u002Fdata\u002Farchitettura-tabella-cohort","\u002Fru\u002Fdata\u002Fcohort-tablitsa-arkhitektura-masshtabirovanie-analiza-uderzhaniia-v-produkcii","\u002Ftr\u002Fdata\u002Fcohort-tablo-mimarisi-retention-analizinin-productionda-olceklenmesi",{"_path":10,"_dir":14,"_draft":15,"_partial":15,"_locale":16,"title":17,"description":18,"publishedAt":19,"modifiedAt":19,"category":14,"i18nKey":4,"tags":20,"readingTime":26,"author":27,"body":28,"_type":3146,"_id":3147,"_source":3148,"_file":3149,"_stem":3150,"_extension":3151},"data",false,"","Architettura della Tabella Cohort: Scalare l'Analisi della Retention in Production","Design architetturale che elabora 100M+ eventi al giorno in tabelle cohort con query in 5 secondi, usando materialized views, partitioning e ottimizzazione dei costi.","2026-06-09",[21,22,23,24,25],"cohort-analysis","bigquery","materialized-views","query-optimization","retention-engineering",8,"Roibase",{"type":29,"children":30,"toc":3137},"root",[31,39,46,82,451,470,477,490,1282,1287,1293,1305,1694,1699,1707,1833,1851,1857,1862,1880,1977,2002,2015,2039,2045,2090,2668,2673,2679,2692,3008,3021,3029,3126,3131],{"type":32,"tag":33,"props":34,"children":35},"element","p",{},[36],{"type":37,"value":38},"text","Quando trasferite le metriche di retention su un dashboard real-time, il primo shock arriva dal costo delle query. Una query cohort di base — \"quanti utenti registrati il 1° gennaio erano ancora attivi il 7° giorno?\" — scritta ingenuamente taragli 200GB di dati, impiega 18 secondi e genera 4 dollari di costi. Un team che visita il dashboard 500 volte al giorno porta il conto a 60.000 dollari al mese. Il problema non è nella vostra capacità analitica, ma nell'architettura della tabella. Per trasferire l'analisi cohort in production, non dovreste memorizzare i dati grezzi degli eventi, ma snapshot pre-aggregati dei cohort.",{"type":32,"tag":40,"props":41,"children":43},"h2",{"id":42},"query-cohort-ingenua-perché-non-scala",[44],{"type":37,"value":45},"Query Cohort Ingenua: Perché Non Scala",{"type":32,"tag":33,"props":47,"children":48},{},[49,51,58,60,66,67,73,75,80],{"type":37,"value":50},"Una query cohort classica unisce tre tabelle: ",{"type":32,"tag":52,"props":53,"children":55},"code",{"className":54},[],[56],{"type":37,"value":57},"users",{"type":37,"value":59},", ",{"type":32,"tag":52,"props":61,"children":63},{"className":62},[],[64],{"type":37,"value":65},"events",{"type":37,"value":59},{"type":32,"tag":52,"props":68,"children":70},{"className":69},[],[71],{"type":37,"value":72},"cohort_definitions",{"type":37,"value":74},". Ogni query scansiona la tabella ",{"type":32,"tag":52,"props":76,"children":78},{"className":77},[],[79],{"type":37,"value":65},{"type":37,"value":81}," senza filtri di partizione. Con 100M di eventi giornalieri, questo approccio non è sostenibile.",{"type":32,"tag":83,"props":84,"children":88},"pre",{"className":85,"code":86,"language":87,"meta":16,"style":16},"language-sql shiki shiki-themes github-dark","-- ❌ Anti-pattern: Scansiona tutti gli events ogni volta\nSELECT \n  DATE_TRUNC(u.created_at, DAY) AS cohort_date,\n  DATE_DIFF(e.event_date, u.created_at, DAY) AS day_n,\n  COUNT(DISTINCT u.user_id) AS retained_users\nFROM users u\nJOIN events e ON u.user_id = e.user_id\nWHERE u.created_at >= '2026-01-01'\n  AND e.event_name = 'session_start'\nGROUP BY 1, 2\nORDER BY 1, 2;\n","sql",[89],{"type":32,"tag":52,"props":90,"children":91},{"__ignoreMap":16},[92,104,120,169,229,275,289,339,370,401,424],{"type":32,"tag":93,"props":94,"children":97},"span",{"class":95,"line":96},"line",1,[98],{"type":32,"tag":93,"props":99,"children":101},{"style":100},"--shiki-default:#6A737D",[102],{"type":37,"value":103},"-- ❌ Anti-pattern: Scansiona tutti gli events ogni volta\n",{"type":32,"tag":93,"props":105,"children":107},{"class":95,"line":106},2,[108,114],{"type":32,"tag":93,"props":109,"children":111},{"style":110},"--shiki-default:#F97583",[112],{"type":37,"value":113},"SELECT",{"type":32,"tag":93,"props":115,"children":117},{"style":116},"--shiki-default:#E1E4E8",[118],{"type":37,"value":119}," \n",{"type":32,"tag":93,"props":121,"children":123},{"class":95,"line":122},3,[124,129,135,140,145,149,154,159,164],{"type":32,"tag":93,"props":125,"children":126},{"style":116},[127],{"type":37,"value":128},"  DATE_TRUNC(",{"type":32,"tag":93,"props":130,"children":132},{"style":131},"--shiki-default:#79B8FF",[133],{"type":37,"value":134},"u",{"type":32,"tag":93,"props":136,"children":137},{"style":116},[138],{"type":37,"value":139},".",{"type":32,"tag":93,"props":141,"children":142},{"style":131},[143],{"type":37,"value":144},"created_at",{"type":32,"tag":93,"props":146,"children":147},{"style":116},[148],{"type":37,"value":59},{"type":32,"tag":93,"props":150,"children":151},{"style":110},[152],{"type":37,"value":153},"DAY",{"type":32,"tag":93,"props":155,"children":156},{"style":116},[157],{"type":37,"value":158},") ",{"type":32,"tag":93,"props":160,"children":161},{"style":110},[162],{"type":37,"value":163},"AS",{"type":32,"tag":93,"props":165,"children":166},{"style":116},[167],{"type":37,"value":168}," cohort_date,\n",{"type":32,"tag":93,"props":170,"children":172},{"class":95,"line":171},4,[173,178,183,187,192,196,200,204,208,212,216,220,224],{"type":32,"tag":93,"props":174,"children":175},{"style":116},[176],{"type":37,"value":177},"  DATE_DIFF(",{"type":32,"tag":93,"props":179,"children":180},{"style":131},[181],{"type":37,"value":182},"e",{"type":32,"tag":93,"props":184,"children":185},{"style":116},[186],{"type":37,"value":139},{"type":32,"tag":93,"props":188,"children":189},{"style":131},[190],{"type":37,"value":191},"event_date",{"type":32,"tag":93,"props":193,"children":194},{"style":116},[195],{"type":37,"value":59},{"type":32,"tag":93,"props":197,"children":198},{"style":131},[199],{"type":37,"value":134},{"type":32,"tag":93,"props":201,"children":202},{"style":116},[203],{"type":37,"value":139},{"type":32,"tag":93,"props":205,"children":206},{"style":131},[207],{"type":37,"value":144},{"type":32,"tag":93,"props":209,"children":210},{"style":116},[211],{"type":37,"value":59},{"type":32,"tag":93,"props":213,"children":214},{"style":110},[215],{"type":37,"value":153},{"type":32,"tag":93,"props":217,"children":218},{"style":116},[219],{"type":37,"value":158},{"type":32,"tag":93,"props":221,"children":222},{"style":110},[223],{"type":37,"value":163},{"type":32,"tag":93,"props":225,"children":226},{"style":116},[227],{"type":37,"value":228}," day_n,\n",{"type":32,"tag":93,"props":230,"children":232},{"class":95,"line":231},5,[233,238,243,248,253,257,262,266,270],{"type":32,"tag":93,"props":234,"children":235},{"style":131},[236],{"type":37,"value":237},"  COUNT",{"type":32,"tag":93,"props":239,"children":240},{"style":116},[241],{"type":37,"value":242},"(",{"type":32,"tag":93,"props":244,"children":245},{"style":110},[246],{"type":37,"value":247},"DISTINCT",{"type":32,"tag":93,"props":249,"children":250},{"style":131},[251],{"type":37,"value":252}," u",{"type":32,"tag":93,"props":254,"children":255},{"style":116},[256],{"type":37,"value":139},{"type":32,"tag":93,"props":258,"children":259},{"style":131},[260],{"type":37,"value":261},"user_id",{"type":32,"tag":93,"props":263,"children":264},{"style":116},[265],{"type":37,"value":158},{"type":32,"tag":93,"props":267,"children":268},{"style":110},[269],{"type":37,"value":163},{"type":32,"tag":93,"props":271,"children":272},{"style":116},[273],{"type":37,"value":274}," retained_users\n",{"type":32,"tag":93,"props":276,"children":278},{"class":95,"line":277},6,[279,284],{"type":32,"tag":93,"props":280,"children":281},{"style":110},[282],{"type":37,"value":283},"FROM",{"type":32,"tag":93,"props":285,"children":286},{"style":116},[287],{"type":37,"value":288}," users u\n",{"type":32,"tag":93,"props":290,"children":292},{"class":95,"line":291},7,[293,298,303,308,312,316,320,325,330,334],{"type":32,"tag":93,"props":294,"children":295},{"style":110},[296],{"type":37,"value":297},"JOIN",{"type":32,"tag":93,"props":299,"children":300},{"style":116},[301],{"type":37,"value":302}," events e ",{"type":32,"tag":93,"props":304,"children":305},{"style":110},[306],{"type":37,"value":307},"ON",{"type":32,"tag":93,"props":309,"children":310},{"style":131},[311],{"type":37,"value":252},{"type":32,"tag":93,"props":313,"children":314},{"style":116},[315],{"type":37,"value":139},{"type":32,"tag":93,"props":317,"children":318},{"style":131},[319],{"type":37,"value":261},{"type":32,"tag":93,"props":321,"children":322},{"style":110},[323],{"type":37,"value":324}," =",{"type":32,"tag":93,"props":326,"children":327},{"style":131},[328],{"type":37,"value":329}," e",{"type":32,"tag":93,"props":331,"children":332},{"style":116},[333],{"type":37,"value":139},{"type":32,"tag":93,"props":335,"children":336},{"style":131},[337],{"type":37,"value":338},"user_id\n",{"type":32,"tag":93,"props":340,"children":341},{"class":95,"line":26},[342,347,351,355,359,364],{"type":32,"tag":93,"props":343,"children":344},{"style":110},[345],{"type":37,"value":346},"WHERE",{"type":32,"tag":93,"props":348,"children":349},{"style":131},[350],{"type":37,"value":252},{"type":32,"tag":93,"props":352,"children":353},{"style":116},[354],{"type":37,"value":139},{"type":32,"tag":93,"props":356,"children":357},{"style":131},[358],{"type":37,"value":144},{"type":32,"tag":93,"props":360,"children":361},{"style":110},[362],{"type":37,"value":363}," >=",{"type":32,"tag":93,"props":365,"children":367},{"style":366},"--shiki-default:#9ECBFF",[368],{"type":37,"value":369}," '2026-01-01'\n",{"type":32,"tag":93,"props":371,"children":373},{"class":95,"line":372},9,[374,379,383,387,392,396],{"type":32,"tag":93,"props":375,"children":376},{"style":110},[377],{"type":37,"value":378},"  AND",{"type":32,"tag":93,"props":380,"children":381},{"style":131},[382],{"type":37,"value":329},{"type":32,"tag":93,"props":384,"children":385},{"style":116},[386],{"type":37,"value":139},{"type":32,"tag":93,"props":388,"children":389},{"style":131},[390],{"type":37,"value":391},"event_name",{"type":32,"tag":93,"props":393,"children":394},{"style":110},[395],{"type":37,"value":324},{"type":32,"tag":93,"props":397,"children":398},{"style":366},[399],{"type":37,"value":400}," 'session_start'\n",{"type":32,"tag":93,"props":402,"children":404},{"class":95,"line":403},10,[405,410,415,419],{"type":32,"tag":93,"props":406,"children":407},{"style":110},[408],{"type":37,"value":409},"GROUP BY",{"type":32,"tag":93,"props":411,"children":412},{"style":131},[413],{"type":37,"value":414}," 1",{"type":32,"tag":93,"props":416,"children":417},{"style":116},[418],{"type":37,"value":59},{"type":32,"tag":93,"props":420,"children":421},{"style":131},[422],{"type":37,"value":423},"2\n",{"type":32,"tag":93,"props":425,"children":427},{"class":95,"line":426},11,[428,433,437,441,446],{"type":32,"tag":93,"props":429,"children":430},{"style":110},[431],{"type":37,"value":432},"ORDER BY",{"type":32,"tag":93,"props":434,"children":435},{"style":131},[436],{"type":37,"value":414},{"type":32,"tag":93,"props":438,"children":439},{"style":116},[440],{"type":37,"value":59},{"type":32,"tag":93,"props":442,"children":443},{"style":131},[444],{"type":37,"value":445},"2",{"type":32,"tag":93,"props":447,"children":448},{"style":116},[449],{"type":37,"value":450},";\n",{"type":32,"tag":33,"props":452,"children":453},{},[454,456,462,464,469],{"type":37,"value":455},"Questa query scannerà 480GB per 6 mesi di dati. In BigQuery, il consumo di slot la rallenterà a 12 secondi, con un costo di 2,40 dollari (pricing on-demand: 5$\u002FTB). Se moltiplicate lo stesso cohort per 20 metriche diverse (revenue, session count, conversion rate), il costo sale a 48 dollari. Se il dashboard viene aggiornato 100 volte al giorno, il costo mensile raggiunge 144.000 dollari. Per rendere il problema adatto a una production scalabile, ci sono due strategie: ",{"type":32,"tag":457,"props":458,"children":459},"strong",{},[460],{"type":37,"value":461},"materializzazione incrementale",{"type":37,"value":463}," e ",{"type":32,"tag":457,"props":465,"children":466},{},[467],{"type":37,"value":468},"snapshot cohort pre-aggregati",{"type":37,"value":139},{"type":32,"tag":471,"props":472,"children":474},"h3",{"id":473},"materializzazione-incrementale-pipeline-event-to-cohort-con-dbt",[475],{"type":37,"value":476},"Materializzazione Incrementale: Pipeline Event-to-Cohort con dbt",{"type":32,"tag":33,"props":478,"children":479},{},[480,482,488],{"type":37,"value":481},"Invece di calcolare i cohort ogni volta, aggiornateli giornalmente tramite batch incrementali. La strategia ",{"type":32,"tag":52,"props":483,"children":485},{"className":484},[],[486],{"type":37,"value":487},"incremental",{"type":37,"value":489}," di dbt consente di aggiungere gli eventi del nuovo giorno alla tabella cohort esistente.",{"type":32,"tag":83,"props":491,"children":493},{"className":85,"code":492,"language":87,"meta":16,"style":16},"-- models\u002Fcohort_retention_daily.sql\n{{\n  config(\n    materialized='incremental',\n    partition_by={'field': 'cohort_date', 'data_type': 'date'},\n    cluster_by=['day_n', 'metric_name'],\n    unique_key='cohort_date || day_n || metric_name'\n  )\n}}\n\nWITH new_events AS (\n  SELECT \n    u.user_id,\n    DATE_TRUNC(u.created_at, DAY) AS cohort_date,\n    DATE_DIFF(e.event_date, u.created_at, DAY) AS day_n,\n    e.event_name,\n    e.revenue_usd\n  FROM {{ ref('events') }} e\n  JOIN {{ ref('users') }} u ON e.user_id = u.user_id\n  {% if is_incremental() %}\n  WHERE e.event_date = CURRENT_DATE() - 1  -- Solo i dati di ieri\n  {% endif %}\n)\nSELECT\n  cohort_date,\n  day_n,\n  'active_users' AS metric_name,\n  COUNT(DISTINCT user_id) AS metric_value\nFROM new_events\nWHERE event_name = 'session_start'\nGROUP BY 1, 2, 3\n\nUNION ALL\n\nSELECT\n  cohort_date,\n  day_n,\n  'revenue_per_cohort' AS metric_name,\n  SUM(revenue_usd) AS metric_value\nFROM new_events\nGROUP BY 1, 2, 3;\n",[494],{"type":32,"tag":52,"props":495,"children":496},{"__ignoreMap":16},[497,505,513,521,544,599,616,633,641,649,658,680,693,714,755,812,833,850,874,929,948,992,1001,1010,1019,1028,1037,1056,1086,1099,1120,1149,1157,1166,1174,1182,1190,1198,1215,1237,1249],{"type":32,"tag":93,"props":498,"children":499},{"class":95,"line":96},[500],{"type":32,"tag":93,"props":501,"children":502},{"style":100},[503],{"type":37,"value":504},"-- models\u002Fcohort_retention_daily.sql\n",{"type":32,"tag":93,"props":506,"children":507},{"class":95,"line":106},[508],{"type":32,"tag":93,"props":509,"children":510},{"style":116},[511],{"type":37,"value":512},"{{\n",{"type":32,"tag":93,"props":514,"children":515},{"class":95,"line":122},[516],{"type":32,"tag":93,"props":517,"children":518},{"style":116},[519],{"type":37,"value":520},"  config(\n",{"type":32,"tag":93,"props":522,"children":523},{"class":95,"line":171},[524,529,534,539],{"type":32,"tag":93,"props":525,"children":526},{"style":116},[527],{"type":37,"value":528},"    materialized",{"type":32,"tag":93,"props":530,"children":531},{"style":110},[532],{"type":37,"value":533},"=",{"type":32,"tag":93,"props":535,"children":536},{"style":366},[537],{"type":37,"value":538},"'incremental'",{"type":32,"tag":93,"props":540,"children":541},{"style":116},[542],{"type":37,"value":543},",\n",{"type":32,"tag":93,"props":545,"children":546},{"class":95,"line":231},[547,552,556,561,566,571,576,580,585,589,594],{"type":32,"tag":93,"props":548,"children":549},{"style":116},[550],{"type":37,"value":551},"    partition_by",{"type":32,"tag":93,"props":553,"children":554},{"style":110},[555],{"type":37,"value":533},{"type":32,"tag":93,"props":557,"children":558},{"style":116},[559],{"type":37,"value":560},"{",{"type":32,"tag":93,"props":562,"children":563},{"style":366},[564],{"type":37,"value":565},"'field'",{"type":32,"tag":93,"props":567,"children":568},{"style":116},[569],{"type":37,"value":570},": ",{"type":32,"tag":93,"props":572,"children":573},{"style":366},[574],{"type":37,"value":575},"'cohort_date'",{"type":32,"tag":93,"props":577,"children":578},{"style":116},[579],{"type":37,"value":59},{"type":32,"tag":93,"props":581,"children":582},{"style":366},[583],{"type":37,"value":584},"'data_type'",{"type":32,"tag":93,"props":586,"children":587},{"style":116},[588],{"type":37,"value":570},{"type":32,"tag":93,"props":590,"children":591},{"style":366},[592],{"type":37,"value":593},"'date'",{"type":32,"tag":93,"props":595,"children":596},{"style":116},[597],{"type":37,"value":598},"},\n",{"type":32,"tag":93,"props":600,"children":601},{"class":95,"line":277},[602,607,611],{"type":32,"tag":93,"props":603,"children":604},{"style":116},[605],{"type":37,"value":606},"    cluster_by",{"type":32,"tag":93,"props":608,"children":609},{"style":110},[610],{"type":37,"value":533},{"type":32,"tag":93,"props":612,"children":613},{"style":116},[614],{"type":37,"value":615},"['day_n', 'metric_name'],\n",{"type":32,"tag":93,"props":617,"children":618},{"class":95,"line":291},[619,624,628],{"type":32,"tag":93,"props":620,"children":621},{"style":116},[622],{"type":37,"value":623},"    unique_key",{"type":32,"tag":93,"props":625,"children":626},{"style":110},[627],{"type":37,"value":533},{"type":32,"tag":93,"props":629,"children":630},{"style":366},[631],{"type":37,"value":632},"'cohort_date || day_n || metric_name'\n",{"type":32,"tag":93,"props":634,"children":635},{"class":95,"line":26},[636],{"type":32,"tag":93,"props":637,"children":638},{"style":116},[639],{"type":37,"value":640},"  )\n",{"type":32,"tag":93,"props":642,"children":643},{"class":95,"line":372},[644],{"type":32,"tag":93,"props":645,"children":646},{"style":116},[647],{"type":37,"value":648},"}}\n",{"type":32,"tag":93,"props":650,"children":651},{"class":95,"line":403},[652],{"type":32,"tag":93,"props":653,"children":655},{"emptyLinePlaceholder":654},true,[656],{"type":37,"value":657},"\n",{"type":32,"tag":93,"props":659,"children":660},{"class":95,"line":426},[661,666,671,675],{"type":32,"tag":93,"props":662,"children":663},{"style":110},[664],{"type":37,"value":665},"WITH",{"type":32,"tag":93,"props":667,"children":668},{"style":116},[669],{"type":37,"value":670}," new_events ",{"type":32,"tag":93,"props":672,"children":673},{"style":110},[674],{"type":37,"value":163},{"type":32,"tag":93,"props":676,"children":677},{"style":116},[678],{"type":37,"value":679}," (\n",{"type":32,"tag":93,"props":681,"children":683},{"class":95,"line":682},12,[684,689],{"type":32,"tag":93,"props":685,"children":686},{"style":110},[687],{"type":37,"value":688},"  SELECT",{"type":32,"tag":93,"props":690,"children":691},{"style":116},[692],{"type":37,"value":119},{"type":32,"tag":93,"props":694,"children":696},{"class":95,"line":695},13,[697,702,706,710],{"type":32,"tag":93,"props":698,"children":699},{"style":131},[700],{"type":37,"value":701},"    u",{"type":32,"tag":93,"props":703,"children":704},{"style":116},[705],{"type":37,"value":139},{"type":32,"tag":93,"props":707,"children":708},{"style":131},[709],{"type":37,"value":261},{"type":32,"tag":93,"props":711,"children":712},{"style":116},[713],{"type":37,"value":543},{"type":32,"tag":93,"props":715,"children":717},{"class":95,"line":716},14,[718,723,727,731,735,739,743,747,751],{"type":32,"tag":93,"props":719,"children":720},{"style":116},[721],{"type":37,"value":722},"    DATE_TRUNC(",{"type":32,"tag":93,"props":724,"children":725},{"style":131},[726],{"type":37,"value":134},{"type":32,"tag":93,"props":728,"children":729},{"style":116},[730],{"type":37,"value":139},{"type":32,"tag":93,"props":732,"children":733},{"style":131},[734],{"type":37,"value":144},{"type":32,"tag":93,"props":736,"children":737},{"style":116},[738],{"type":37,"value":59},{"type":32,"tag":93,"props":740,"children":741},{"style":110},[742],{"type":37,"value":153},{"type":32,"tag":93,"props":744,"children":745},{"style":116},[746],{"type":37,"value":158},{"type":32,"tag":93,"props":748,"children":749},{"style":110},[750],{"type":37,"value":163},{"type":32,"tag":93,"props":752,"children":753},{"style":116},[754],{"type":37,"value":168},{"type":32,"tag":93,"props":756,"children":758},{"class":95,"line":757},15,[759,764,768,772,776,780,784,788,792,796,800,804,808],{"type":32,"tag":93,"props":760,"children":761},{"style":116},[762],{"type":37,"value":763},"    DATE_DIFF(",{"type":32,"tag":93,"props":765,"children":766},{"style":131},[767],{"type":37,"value":182},{"type":32,"tag":93,"props":769,"children":770},{"style":116},[771],{"type":37,"value":139},{"type":32,"tag":93,"props":773,"children":774},{"style":131},[775],{"type":37,"value":191},{"type":32,"tag":93,"props":777,"children":778},{"style":116},[779],{"type":37,"value":59},{"type":32,"tag":93,"props":781,"children":782},{"style":131},[783],{"type":37,"value":134},{"type":32,"tag":93,"props":785,"children":786},{"style":116},[787],{"type":37,"value":139},{"type":32,"tag":93,"props":789,"children":790},{"style":131},[791],{"type":37,"value":144},{"type":32,"tag":93,"props":793,"children":794},{"style":116},[795],{"type":37,"value":59},{"type":32,"tag":93,"props":797,"children":798},{"style":110},[799],{"type":37,"value":153},{"type":32,"tag":93,"props":801,"children":802},{"style":116},[803],{"type":37,"value":158},{"type":32,"tag":93,"props":805,"children":806},{"style":110},[807],{"type":37,"value":163},{"type":32,"tag":93,"props":809,"children":810},{"style":116},[811],{"type":37,"value":228},{"type":32,"tag":93,"props":813,"children":815},{"class":95,"line":814},16,[816,821,825,829],{"type":32,"tag":93,"props":817,"children":818},{"style":131},[819],{"type":37,"value":820},"    e",{"type":32,"tag":93,"props":822,"children":823},{"style":116},[824],{"type":37,"value":139},{"type":32,"tag":93,"props":826,"children":827},{"style":131},[828],{"type":37,"value":391},{"type":32,"tag":93,"props":830,"children":831},{"style":116},[832],{"type":37,"value":543},{"type":32,"tag":93,"props":834,"children":836},{"class":95,"line":835},17,[837,841,845],{"type":32,"tag":93,"props":838,"children":839},{"style":131},[840],{"type":37,"value":820},{"type":32,"tag":93,"props":842,"children":843},{"style":116},[844],{"type":37,"value":139},{"type":32,"tag":93,"props":846,"children":847},{"style":131},[848],{"type":37,"value":849},"revenue_usd\n",{"type":32,"tag":93,"props":851,"children":853},{"class":95,"line":852},18,[854,859,864,869],{"type":32,"tag":93,"props":855,"children":856},{"style":110},[857],{"type":37,"value":858},"  FROM",{"type":32,"tag":93,"props":860,"children":861},{"style":116},[862],{"type":37,"value":863}," {{ ref(",{"type":32,"tag":93,"props":865,"children":866},{"style":366},[867],{"type":37,"value":868},"'events'",{"type":32,"tag":93,"props":870,"children":871},{"style":116},[872],{"type":37,"value":873},") }} e\n",{"type":32,"tag":93,"props":875,"children":877},{"class":95,"line":876},19,[878,883,887,892,897,901,905,909,913,917,921,925],{"type":32,"tag":93,"props":879,"children":880},{"style":110},[881],{"type":37,"value":882},"  JOIN",{"type":32,"tag":93,"props":884,"children":885},{"style":116},[886],{"type":37,"value":863},{"type":32,"tag":93,"props":888,"children":889},{"style":366},[890],{"type":37,"value":891},"'users'",{"type":32,"tag":93,"props":893,"children":894},{"style":116},[895],{"type":37,"value":896},") }} u ",{"type":32,"tag":93,"props":898,"children":899},{"style":110},[900],{"type":37,"value":307},{"type":32,"tag":93,"props":902,"children":903},{"style":131},[904],{"type":37,"value":329},{"type":32,"tag":93,"props":906,"children":907},{"style":116},[908],{"type":37,"value":139},{"type":32,"tag":93,"props":910,"children":911},{"style":131},[912],{"type":37,"value":261},{"type":32,"tag":93,"props":914,"children":915},{"style":110},[916],{"type":37,"value":324},{"type":32,"tag":93,"props":918,"children":919},{"style":131},[920],{"type":37,"value":252},{"type":32,"tag":93,"props":922,"children":923},{"style":116},[924],{"type":37,"value":139},{"type":32,"tag":93,"props":926,"children":927},{"style":131},[928],{"type":37,"value":338},{"type":32,"tag":93,"props":930,"children":932},{"class":95,"line":931},20,[933,938,943],{"type":32,"tag":93,"props":934,"children":935},{"style":116},[936],{"type":37,"value":937},"  {% ",{"type":32,"tag":93,"props":939,"children":940},{"style":110},[941],{"type":37,"value":942},"if",{"type":32,"tag":93,"props":944,"children":945},{"style":116},[946],{"type":37,"value":947}," is_incremental() %}\n",{"type":32,"tag":93,"props":949,"children":951},{"class":95,"line":950},21,[952,957,961,965,969,973,978,983,987],{"type":32,"tag":93,"props":953,"children":954},{"style":110},[955],{"type":37,"value":956},"  WHERE",{"type":32,"tag":93,"props":958,"children":959},{"style":131},[960],{"type":37,"value":329},{"type":32,"tag":93,"props":962,"children":963},{"style":116},[964],{"type":37,"value":139},{"type":32,"tag":93,"props":966,"children":967},{"style":131},[968],{"type":37,"value":191},{"type":32,"tag":93,"props":970,"children":971},{"style":110},[972],{"type":37,"value":324},{"type":32,"tag":93,"props":974,"children":975},{"style":116},[976],{"type":37,"value":977}," CURRENT_DATE() ",{"type":32,"tag":93,"props":979,"children":980},{"style":110},[981],{"type":37,"value":982},"-",{"type":32,"tag":93,"props":984,"children":985},{"style":131},[986],{"type":37,"value":414},{"type":32,"tag":93,"props":988,"children":989},{"style":100},[990],{"type":37,"value":991},"  -- Solo i dati di ieri\n",{"type":32,"tag":93,"props":993,"children":995},{"class":95,"line":994},22,[996],{"type":32,"tag":93,"props":997,"children":998},{"style":116},[999],{"type":37,"value":1000},"  {% endif %}\n",{"type":32,"tag":93,"props":1002,"children":1004},{"class":95,"line":1003},23,[1005],{"type":32,"tag":93,"props":1006,"children":1007},{"style":116},[1008],{"type":37,"value":1009},")\n",{"type":32,"tag":93,"props":1011,"children":1013},{"class":95,"line":1012},24,[1014],{"type":32,"tag":93,"props":1015,"children":1016},{"style":110},[1017],{"type":37,"value":1018},"SELECT\n",{"type":32,"tag":93,"props":1020,"children":1022},{"class":95,"line":1021},25,[1023],{"type":32,"tag":93,"props":1024,"children":1025},{"style":116},[1026],{"type":37,"value":1027},"  cohort_date,\n",{"type":32,"tag":93,"props":1029,"children":1031},{"class":95,"line":1030},26,[1032],{"type":32,"tag":93,"props":1033,"children":1034},{"style":116},[1035],{"type":37,"value":1036},"  day_n,\n",{"type":32,"tag":93,"props":1038,"children":1040},{"class":95,"line":1039},27,[1041,1046,1051],{"type":32,"tag":93,"props":1042,"children":1043},{"style":366},[1044],{"type":37,"value":1045},"  'active_users'",{"type":32,"tag":93,"props":1047,"children":1048},{"style":110},[1049],{"type":37,"value":1050}," AS",{"type":32,"tag":93,"props":1052,"children":1053},{"style":116},[1054],{"type":37,"value":1055}," metric_name,\n",{"type":32,"tag":93,"props":1057,"children":1059},{"class":95,"line":1058},28,[1060,1064,1068,1072,1077,1081],{"type":32,"tag":93,"props":1061,"children":1062},{"style":131},[1063],{"type":37,"value":237},{"type":32,"tag":93,"props":1065,"children":1066},{"style":116},[1067],{"type":37,"value":242},{"type":32,"tag":93,"props":1069,"children":1070},{"style":110},[1071],{"type":37,"value":247},{"type":32,"tag":93,"props":1073,"children":1074},{"style":116},[1075],{"type":37,"value":1076}," user_id) ",{"type":32,"tag":93,"props":1078,"children":1079},{"style":110},[1080],{"type":37,"value":163},{"type":32,"tag":93,"props":1082,"children":1083},{"style":116},[1084],{"type":37,"value":1085}," metric_value\n",{"type":32,"tag":93,"props":1087,"children":1089},{"class":95,"line":1088},29,[1090,1094],{"type":32,"tag":93,"props":1091,"children":1092},{"style":110},[1093],{"type":37,"value":283},{"type":32,"tag":93,"props":1095,"children":1096},{"style":116},[1097],{"type":37,"value":1098}," new_events\n",{"type":32,"tag":93,"props":1100,"children":1102},{"class":95,"line":1101},30,[1103,1107,1112,1116],{"type":32,"tag":93,"props":1104,"children":1105},{"style":110},[1106],{"type":37,"value":346},{"type":32,"tag":93,"props":1108,"children":1109},{"style":116},[1110],{"type":37,"value":1111}," event_name ",{"type":32,"tag":93,"props":1113,"children":1114},{"style":110},[1115],{"type":37,"value":533},{"type":32,"tag":93,"props":1117,"children":1118},{"style":366},[1119],{"type":37,"value":400},{"type":32,"tag":93,"props":1121,"children":1123},{"class":95,"line":1122},31,[1124,1128,1132,1136,1140,1144],{"type":32,"tag":93,"props":1125,"children":1126},{"style":110},[1127],{"type":37,"value":409},{"type":32,"tag":93,"props":1129,"children":1130},{"style":131},[1131],{"type":37,"value":414},{"type":32,"tag":93,"props":1133,"children":1134},{"style":116},[1135],{"type":37,"value":59},{"type":32,"tag":93,"props":1137,"children":1138},{"style":131},[1139],{"type":37,"value":445},{"type":32,"tag":93,"props":1141,"children":1142},{"style":116},[1143],{"type":37,"value":59},{"type":32,"tag":93,"props":1145,"children":1146},{"style":131},[1147],{"type":37,"value":1148},"3\n",{"type":32,"tag":93,"props":1150,"children":1152},{"class":95,"line":1151},32,[1153],{"type":32,"tag":93,"props":1154,"children":1155},{"emptyLinePlaceholder":654},[1156],{"type":37,"value":657},{"type":32,"tag":93,"props":1158,"children":1160},{"class":95,"line":1159},33,[1161],{"type":32,"tag":93,"props":1162,"children":1163},{"style":110},[1164],{"type":37,"value":1165},"UNION ALL\n",{"type":32,"tag":93,"props":1167,"children":1169},{"class":95,"line":1168},34,[1170],{"type":32,"tag":93,"props":1171,"children":1172},{"emptyLinePlaceholder":654},[1173],{"type":37,"value":657},{"type":32,"tag":93,"props":1175,"children":1177},{"class":95,"line":1176},35,[1178],{"type":32,"tag":93,"props":1179,"children":1180},{"style":110},[1181],{"type":37,"value":1018},{"type":32,"tag":93,"props":1183,"children":1185},{"class":95,"line":1184},36,[1186],{"type":32,"tag":93,"props":1187,"children":1188},{"style":116},[1189],{"type":37,"value":1027},{"type":32,"tag":93,"props":1191,"children":1193},{"class":95,"line":1192},37,[1194],{"type":32,"tag":93,"props":1195,"children":1196},{"style":116},[1197],{"type":37,"value":1036},{"type":32,"tag":93,"props":1199,"children":1201},{"class":95,"line":1200},38,[1202,1207,1211],{"type":32,"tag":93,"props":1203,"children":1204},{"style":366},[1205],{"type":37,"value":1206},"  'revenue_per_cohort'",{"type":32,"tag":93,"props":1208,"children":1209},{"style":110},[1210],{"type":37,"value":1050},{"type":32,"tag":93,"props":1212,"children":1213},{"style":116},[1214],{"type":37,"value":1055},{"type":32,"tag":93,"props":1216,"children":1218},{"class":95,"line":1217},39,[1219,1224,1229,1233],{"type":32,"tag":93,"props":1220,"children":1221},{"style":131},[1222],{"type":37,"value":1223},"  SUM",{"type":32,"tag":93,"props":1225,"children":1226},{"style":116},[1227],{"type":37,"value":1228},"(revenue_usd) ",{"type":32,"tag":93,"props":1230,"children":1231},{"style":110},[1232],{"type":37,"value":163},{"type":32,"tag":93,"props":1234,"children":1235},{"style":116},[1236],{"type":37,"value":1085},{"type":32,"tag":93,"props":1238,"children":1240},{"class":95,"line":1239},40,[1241,1245],{"type":32,"tag":93,"props":1242,"children":1243},{"style":110},[1244],{"type":37,"value":283},{"type":32,"tag":93,"props":1246,"children":1247},{"style":116},[1248],{"type":37,"value":1098},{"type":32,"tag":93,"props":1250,"children":1252},{"class":95,"line":1251},41,[1253,1257,1261,1265,1269,1273,1278],{"type":32,"tag":93,"props":1254,"children":1255},{"style":110},[1256],{"type":37,"value":409},{"type":32,"tag":93,"props":1258,"children":1259},{"style":131},[1260],{"type":37,"value":414},{"type":32,"tag":93,"props":1262,"children":1263},{"style":116},[1264],{"type":37,"value":59},{"type":32,"tag":93,"props":1266,"children":1267},{"style":131},[1268],{"type":37,"value":445},{"type":32,"tag":93,"props":1270,"children":1271},{"style":116},[1272],{"type":37,"value":59},{"type":32,"tag":93,"props":1274,"children":1275},{"style":131},[1276],{"type":37,"value":1277},"3",{"type":32,"tag":93,"props":1279,"children":1280},{"style":116},[1281],{"type":37,"value":450},{"type":32,"tag":33,"props":1283,"children":1284},{},[1285],{"type":37,"value":1286},"Alla prima esecuzione (full refresh), vengono elaborati tutti i dati storici. Ogni giorno successivo, vengono aggiunti solo i nuovi event di 1 giorno. Un giorno con 100M di event scannerà 3,2GB di dati (grazie a partitioning + clustering), la query impiegherà 4 secondi, con un costo di 0,016 dollari. Costo incrementale mensile totale: 0,48 dollari — un trecentomillesimo del metodo ingenuo.",{"type":32,"tag":40,"props":1288,"children":1290},{"id":1289},"materialized-views-il-layer-cache-automatico-di-bigquery",[1291],{"type":37,"value":1292},"Materialized Views: Il Layer Cache Automatico di BigQuery",{"type":32,"tag":33,"props":1294,"children":1295},{},[1296,1298,1303],{"type":37,"value":1297},"Il modello incrementale viene aggiornato in batch (una volta al giorno). Se volete aggiungere i dati dell'ultima ora a un dashboard real-time, entra in gioco la feature ",{"type":32,"tag":457,"props":1299,"children":1300},{},[1301],{"type":37,"value":1302},"materialized view",{"type":37,"value":1304}," di BigQuery. Una materialized view memorizza fisicamente il risultato della query base e si aggiorna automaticamente quando la tabella sorgente cambia.",{"type":32,"tag":83,"props":1306,"children":1308},{"className":85,"code":1307,"language":87,"meta":16,"style":16},"CREATE MATERIALIZED VIEW `project.dataset.cohort_retention_mv`\nPARTITION BY cohort_date\nCLUSTER BY day_n, metric_name\nAS\nSELECT\n  DATE_TRUNC(u.created_at, DAY) AS cohort_date,\n  DATE_DIFF(e.event_date, u.created_at, DAY) AS day_n,\n  'active_users' AS metric_name,\n  COUNT(DISTINCT u.user_id) AS metric_value\nFROM `project.dataset.events` e\nJOIN `project.dataset.users` u ON e.user_id = u.user_id\nWHERE e.event_date >= CURRENT_DATE() - 90  -- Solo finestra di 90 giorni\n  AND e.event_name = 'session_start'\nGROUP BY 1, 2, 3;\n",[1309],{"type":32,"tag":52,"props":1310,"children":1311},{"__ignoreMap":16},[1312,1330,1348,1366,1374,1381,1420,1475,1490,1529,1546,1595,1636,1663],{"type":32,"tag":93,"props":1313,"children":1314},{"class":95,"line":96},[1315,1320,1325],{"type":32,"tag":93,"props":1316,"children":1317},{"style":110},[1318],{"type":37,"value":1319},"CREATE",{"type":32,"tag":93,"props":1321,"children":1322},{"style":116},[1323],{"type":37,"value":1324}," MATERIALIZED VIEW ",{"type":32,"tag":93,"props":1326,"children":1327},{"style":366},[1328],{"type":37,"value":1329},"`project.dataset.cohort_retention_mv`\n",{"type":32,"tag":93,"props":1331,"children":1332},{"class":95,"line":106},[1333,1338,1343],{"type":32,"tag":93,"props":1334,"children":1335},{"style":110},[1336],{"type":37,"value":1337},"PARTITION",{"type":32,"tag":93,"props":1339,"children":1340},{"style":110},[1341],{"type":37,"value":1342}," BY",{"type":32,"tag":93,"props":1344,"children":1345},{"style":116},[1346],{"type":37,"value":1347}," cohort_date\n",{"type":32,"tag":93,"props":1349,"children":1350},{"class":95,"line":122},[1351,1356,1361],{"type":32,"tag":93,"props":1352,"children":1353},{"style":116},[1354],{"type":37,"value":1355},"CLUSTER ",{"type":32,"tag":93,"props":1357,"children":1358},{"style":110},[1359],{"type":37,"value":1360},"BY",{"type":32,"tag":93,"props":1362,"children":1363},{"style":116},[1364],{"type":37,"value":1365}," day_n, metric_name\n",{"type":32,"tag":93,"props":1367,"children":1368},{"class":95,"line":171},[1369],{"type":32,"tag":93,"props":1370,"children":1371},{"style":110},[1372],{"type":37,"value":1373},"AS\n",{"type":32,"tag":93,"props":1375,"children":1376},{"class":95,"line":231},[1377],{"type":32,"tag":93,"props":1378,"children":1379},{"style":110},[1380],{"type":37,"value":1018},{"type":32,"tag":93,"props":1382,"children":1383},{"class":95,"line":277},[1384,1388,1392,1396,1400,1404,1408,1412,1416],{"type":32,"tag":93,"props":1385,"children":1386},{"style":116},[1387],{"type":37,"value":128},{"type":32,"tag":93,"props":1389,"children":1390},{"style":131},[1391],{"type":37,"value":134},{"type":32,"tag":93,"props":1393,"children":1394},{"style":116},[1395],{"type":37,"value":139},{"type":32,"tag":93,"props":1397,"children":1398},{"style":131},[1399],{"type":37,"value":144},{"type":32,"tag":93,"props":1401,"children":1402},{"style":116},[1403],{"type":37,"value":59},{"type":32,"tag":93,"props":1405,"children":1406},{"style":110},[1407],{"type":37,"value":153},{"type":32,"tag":93,"props":1409,"children":1410},{"style":116},[1411],{"type":37,"value":158},{"type":32,"tag":93,"props":1413,"children":1414},{"style":110},[1415],{"type":37,"value":163},{"type":32,"tag":93,"props":1417,"children":1418},{"style":116},[1419],{"type":37,"value":168},{"type":32,"tag":93,"props":1421,"children":1422},{"class":95,"line":291},[1423,1427,1431,1435,1439,1443,1447,1451,1455,1459,1463,1467,1471],{"type":32,"tag":93,"props":1424,"children":1425},{"style":116},[1426],{"type":37,"value":177},{"type":32,"tag":93,"props":1428,"children":1429},{"style":131},[1430],{"type":37,"value":182},{"type":32,"tag":93,"props":1432,"children":1433},{"style":116},[1434],{"type":37,"value":139},{"type":32,"tag":93,"props":1436,"children":1437},{"style":131},[1438],{"type":37,"value":191},{"type":32,"tag":93,"props":1440,"children":1441},{"style":116},[1442],{"type":37,"value":59},{"type":32,"tag":93,"props":1444,"children":1445},{"style":131},[1446],{"type":37,"value":134},{"type":32,"tag":93,"props":1448,"children":1449},{"style":116},[1450],{"type":37,"value":139},{"type":32,"tag":93,"props":1452,"children":1453},{"style":131},[1454],{"type":37,"value":144},{"type":32,"tag":93,"props":1456,"children":1457},{"style":116},[1458],{"type":37,"value":59},{"type":32,"tag":93,"props":1460,"children":1461},{"style":110},[1462],{"type":37,"value":153},{"type":32,"tag":93,"props":1464,"children":1465},{"style":116},[1466],{"type":37,"value":158},{"type":32,"tag":93,"props":1468,"children":1469},{"style":110},[1470],{"type":37,"value":163},{"type":32,"tag":93,"props":1472,"children":1473},{"style":116},[1474],{"type":37,"value":228},{"type":32,"tag":93,"props":1476,"children":1477},{"class":95,"line":26},[1478,1482,1486],{"type":32,"tag":93,"props":1479,"children":1480},{"style":366},[1481],{"type":37,"value":1045},{"type":32,"tag":93,"props":1483,"children":1484},{"style":110},[1485],{"type":37,"value":1050},{"type":32,"tag":93,"props":1487,"children":1488},{"style":116},[1489],{"type":37,"value":1055},{"type":32,"tag":93,"props":1491,"children":1492},{"class":95,"line":372},[1493,1497,1501,1505,1509,1513,1517,1521,1525],{"type":32,"tag":93,"props":1494,"children":1495},{"style":131},[1496],{"type":37,"value":237},{"type":32,"tag":93,"props":1498,"children":1499},{"style":116},[1500],{"type":37,"value":242},{"type":32,"tag":93,"props":1502,"children":1503},{"style":110},[1504],{"type":37,"value":247},{"type":32,"tag":93,"props":1506,"children":1507},{"style":131},[1508],{"type":37,"value":252},{"type":32,"tag":93,"props":1510,"children":1511},{"style":116},[1512],{"type":37,"value":139},{"type":32,"tag":93,"props":1514,"children":1515},{"style":131},[1516],{"type":37,"value":261},{"type":32,"tag":93,"props":1518,"children":1519},{"style":116},[1520],{"type":37,"value":158},{"type":32,"tag":93,"props":1522,"children":1523},{"style":110},[1524],{"type":37,"value":163},{"type":32,"tag":93,"props":1526,"children":1527},{"style":116},[1528],{"type":37,"value":1085},{"type":32,"tag":93,"props":1530,"children":1531},{"class":95,"line":403},[1532,1536,1541],{"type":32,"tag":93,"props":1533,"children":1534},{"style":110},[1535],{"type":37,"value":283},{"type":32,"tag":93,"props":1537,"children":1538},{"style":366},[1539],{"type":37,"value":1540}," `project.dataset.events`",{"type":32,"tag":93,"props":1542,"children":1543},{"style":116},[1544],{"type":37,"value":1545}," e\n",{"type":32,"tag":93,"props":1547,"children":1548},{"class":95,"line":426},[1549,1553,1558,1563,1567,1571,1575,1579,1583,1587,1591],{"type":32,"tag":93,"props":1550,"children":1551},{"style":110},[1552],{"type":37,"value":297},{"type":32,"tag":93,"props":1554,"children":1555},{"style":366},[1556],{"type":37,"value":1557}," `project.dataset.users`",{"type":32,"tag":93,"props":1559,"children":1560},{"style":116},[1561],{"type":37,"value":1562}," u ",{"type":32,"tag":93,"props":1564,"children":1565},{"style":110},[1566],{"type":37,"value":307},{"type":32,"tag":93,"props":1568,"children":1569},{"style":131},[1570],{"type":37,"value":329},{"type":32,"tag":93,"props":1572,"children":1573},{"style":116},[1574],{"type":37,"value":139},{"type":32,"tag":93,"props":1576,"children":1577},{"style":131},[1578],{"type":37,"value":261},{"type":32,"tag":93,"props":1580,"children":1581},{"style":110},[1582],{"type":37,"value":324},{"type":32,"tag":93,"props":1584,"children":1585},{"style":131},[1586],{"type":37,"value":252},{"type":32,"tag":93,"props":1588,"children":1589},{"style":116},[1590],{"type":37,"value":139},{"type":32,"tag":93,"props":1592,"children":1593},{"style":131},[1594],{"type":37,"value":338},{"type":32,"tag":93,"props":1596,"children":1597},{"class":95,"line":682},[1598,1602,1606,1610,1614,1618,1622,1626,1631],{"type":32,"tag":93,"props":1599,"children":1600},{"style":110},[1601],{"type":37,"value":346},{"type":32,"tag":93,"props":1603,"children":1604},{"style":131},[1605],{"type":37,"value":329},{"type":32,"tag":93,"props":1607,"children":1608},{"style":116},[1609],{"type":37,"value":139},{"type":32,"tag":93,"props":1611,"children":1612},{"style":131},[1613],{"type":37,"value":191},{"type":32,"tag":93,"props":1615,"children":1616},{"style":110},[1617],{"type":37,"value":363},{"type":32,"tag":93,"props":1619,"children":1620},{"style":116},[1621],{"type":37,"value":977},{"type":32,"tag":93,"props":1623,"children":1624},{"style":110},[1625],{"type":37,"value":982},{"type":32,"tag":93,"props":1627,"children":1628},{"style":131},[1629],{"type":37,"value":1630}," 90",{"type":32,"tag":93,"props":1632,"children":1633},{"style":100},[1634],{"type":37,"value":1635},"  -- Solo finestra di 90 giorni\n",{"type":32,"tag":93,"props":1637,"children":1638},{"class":95,"line":695},[1639,1643,1647,1651,1655,1659],{"type":32,"tag":93,"props":1640,"children":1641},{"style":110},[1642],{"type":37,"value":378},{"type":32,"tag":93,"props":1644,"children":1645},{"style":131},[1646],{"type":37,"value":329},{"type":32,"tag":93,"props":1648,"children":1649},{"style":116},[1650],{"type":37,"value":139},{"type":32,"tag":93,"props":1652,"children":1653},{"style":131},[1654],{"type":37,"value":391},{"type":32,"tag":93,"props":1656,"children":1657},{"style":110},[1658],{"type":37,"value":324},{"type":32,"tag":93,"props":1660,"children":1661},{"style":366},[1662],{"type":37,"value":400},{"type":32,"tag":93,"props":1664,"children":1665},{"class":95,"line":716},[1666,1670,1674,1678,1682,1686,1690],{"type":32,"tag":93,"props":1667,"children":1668},{"style":110},[1669],{"type":37,"value":409},{"type":32,"tag":93,"props":1671,"children":1672},{"style":131},[1673],{"type":37,"value":414},{"type":32,"tag":93,"props":1675,"children":1676},{"style":116},[1677],{"type":37,"value":59},{"type":32,"tag":93,"props":1679,"children":1680},{"style":131},[1681],{"type":37,"value":445},{"type":32,"tag":93,"props":1683,"children":1684},{"style":116},[1685],{"type":37,"value":59},{"type":32,"tag":93,"props":1687,"children":1688},{"style":131},[1689],{"type":37,"value":1277},{"type":32,"tag":93,"props":1691,"children":1692},{"style":116},[1693],{"type":37,"value":450},{"type":32,"tag":33,"props":1695,"children":1696},{},[1697],{"type":37,"value":1698},"Quando interrogate una materialized view, BigQuery restituisce prima il risultato in cache. Se la tabella sorgente cambia (vengono aggiunti nuovi event), il delta viene calcolato in background. La query del dashboard ora impiega 0,2 secondi, con un costo di 0 dollari (cache hit). Tuttavia, attenzione: la materialized view stessa genera costi di storage (BigQuery storage: 0,02$\u002FGB\u002Fmese) e se la tabella cohort di 90 giorni è 12GB, il costo di storage mensile aggiuntivo è di 0,24 dollari.",{"type":32,"tag":33,"props":1700,"children":1701},{},[1702],{"type":32,"tag":457,"props":1703,"children":1704},{},[1705],{"type":37,"value":1706},"Tabella dei tradeoff:",{"type":32,"tag":1708,"props":1709,"children":1710},"table",{},[1711,1745],{"type":32,"tag":1712,"props":1713,"children":1714},"thead",{},[1715],{"type":32,"tag":1716,"props":1717,"children":1718},"tr",{},[1719,1725,1730,1735,1740],{"type":32,"tag":1720,"props":1721,"children":1722},"th",{},[1723],{"type":37,"value":1724},"Metodo",{"type":32,"tag":1720,"props":1726,"children":1727},{},[1728],{"type":37,"value":1729},"Tempo First Query",{"type":32,"tag":1720,"props":1731,"children":1732},{},[1733],{"type":37,"value":1734},"Tempo Query Dashboard",{"type":32,"tag":1720,"props":1736,"children":1737},{},[1738],{"type":37,"value":1739},"Costo Compute Mensile",{"type":32,"tag":1720,"props":1741,"children":1742},{},[1743],{"type":37,"value":1744},"Costo Storage Mensile",{"type":32,"tag":1746,"props":1747,"children":1748},"tbody",{},[1749,1777,1805],{"type":32,"tag":1716,"props":1750,"children":1751},{},[1752,1758,1763,1767,1772],{"type":32,"tag":1753,"props":1754,"children":1755},"td",{},[1756],{"type":37,"value":1757},"Naive JOIN",{"type":32,"tag":1753,"props":1759,"children":1760},{},[1761],{"type":37,"value":1762},"12s",{"type":32,"tag":1753,"props":1764,"children":1765},{},[1766],{"type":37,"value":1762},{"type":32,"tag":1753,"props":1768,"children":1769},{},[1770],{"type":37,"value":1771},"144.000$",{"type":32,"tag":1753,"props":1773,"children":1774},{},[1775],{"type":37,"value":1776},"0$",{"type":32,"tag":1716,"props":1778,"children":1779},{},[1780,1785,1790,1795,1800],{"type":32,"tag":1753,"props":1781,"children":1782},{},[1783],{"type":37,"value":1784},"dbt Incremental",{"type":32,"tag":1753,"props":1786,"children":1787},{},[1788],{"type":37,"value":1789},"4s (primo batch)",{"type":32,"tag":1753,"props":1791,"children":1792},{},[1793],{"type":37,"value":1794},"2s (lettura snapshot)",{"type":32,"tag":1753,"props":1796,"children":1797},{},[1798],{"type":37,"value":1799},"0,48$",{"type":32,"tag":1753,"props":1801,"children":1802},{},[1803],{"type":37,"value":1804},"0,18$ (tabella snapshot)",{"type":32,"tag":1716,"props":1806,"children":1807},{},[1808,1813,1818,1823,1828],{"type":32,"tag":1753,"props":1809,"children":1810},{},[1811],{"type":37,"value":1812},"Materialized View",{"type":32,"tag":1753,"props":1814,"children":1815},{},[1816],{"type":37,"value":1817},"8s (primo build)",{"type":32,"tag":1753,"props":1819,"children":1820},{},[1821],{"type":37,"value":1822},"0,2s (cache hit)",{"type":32,"tag":1753,"props":1824,"children":1825},{},[1826],{"type":37,"value":1827},"0$ (refresh automatico)",{"type":32,"tag":1753,"props":1829,"children":1830},{},[1831],{"type":37,"value":1832},"0,24$",{"type":32,"tag":33,"props":1834,"children":1835},{},[1836,1838,1843,1845,1849],{"type":37,"value":1837},"In production, la combinazione di entrambe è ideale: il ",{"type":32,"tag":457,"props":1839,"children":1840},{},[1841],{"type":37,"value":1842},"modello dbt incremental",{"type":37,"value":1844}," aggiorna quotidianamente i cohort storici tramite batch, mentre la ",{"type":32,"tag":457,"props":1846,"children":1847},{},[1848],{"type":37,"value":1302},{"type":37,"value":1850}," mantiene gli ultimi 7 giorni in tempo reale.",{"type":32,"tag":40,"props":1852,"children":1854},{"id":1853},"partitioning-e-clustering-ridurre-il-costo-delle-query-del-97",[1855],{"type":37,"value":1856},"Partitioning e Clustering: Ridurre il Costo delle Query del 97%",{"type":32,"tag":33,"props":1858,"children":1859},{},[1860],{"type":37,"value":1861},"Se non partizionate e non clusterizzate le tabelle cohort, BigQuery scannerà l'intera tabella a ogni query. Su una tabella cohort di 1TB (dati di 2 anni), una singola query \"mostrami il cohort di gennaio 2026\" scannerà 1TB e sarà addebitata a 5 dollari. Con partitioning + clustering, la stessa query scannerà 8GB, pagherete 0,04 dollari.",{"type":32,"tag":33,"props":1863,"children":1864},{},[1865,1870,1872,1878],{"type":32,"tag":457,"props":1866,"children":1867},{},[1868],{"type":37,"value":1869},"Strategia di partitioning:",{"type":37,"value":1871}," partizionare per ",{"type":32,"tag":52,"props":1873,"children":1875},{"className":1874},[],[1876],{"type":37,"value":1877},"cohort_date",{"type":37,"value":1879}," in base ai giorni. Se BigQuery vede il filtro di partizione nella query, scannerà solo le partizioni rilevanti.",{"type":32,"tag":83,"props":1881,"children":1883},{"className":85,"code":1882,"language":87,"meta":16,"style":16},"CREATE OR REPLACE TABLE `project.dataset.cohort_retention`\nPARTITION BY cohort_date\nCLUSTER BY day_n, metric_name\nAS\nSELECT * FROM `project.dataset.cohort_retention_temp`;\n",[1884],{"type":32,"tag":52,"props":1885,"children":1886},{"__ignoreMap":16},[1887,1914,1929,1944,1951],{"type":32,"tag":93,"props":1888,"children":1889},{"class":95,"line":96},[1890,1894,1899,1904,1909],{"type":32,"tag":93,"props":1891,"children":1892},{"style":110},[1893],{"type":37,"value":1319},{"type":32,"tag":93,"props":1895,"children":1896},{"style":110},[1897],{"type":37,"value":1898}," OR",{"type":32,"tag":93,"props":1900,"children":1901},{"style":110},[1902],{"type":37,"value":1903}," REPLACE",{"type":32,"tag":93,"props":1905,"children":1906},{"style":110},[1907],{"type":37,"value":1908}," TABLE",{"type":32,"tag":93,"props":1910,"children":1911},{"style":366},[1912],{"type":37,"value":1913}," `project.dataset.cohort_retention`\n",{"type":32,"tag":93,"props":1915,"children":1916},{"class":95,"line":106},[1917,1921,1925],{"type":32,"tag":93,"props":1918,"children":1919},{"style":110},[1920],{"type":37,"value":1337},{"type":32,"tag":93,"props":1922,"children":1923},{"style":110},[1924],{"type":37,"value":1342},{"type":32,"tag":93,"props":1926,"children":1927},{"style":116},[1928],{"type":37,"value":1347},{"type":32,"tag":93,"props":1930,"children":1931},{"class":95,"line":122},[1932,1936,1940],{"type":32,"tag":93,"props":1933,"children":1934},{"style":116},[1935],{"type":37,"value":1355},{"type":32,"tag":93,"props":1937,"children":1938},{"style":110},[1939],{"type":37,"value":1360},{"type":32,"tag":93,"props":1941,"children":1942},{"style":116},[1943],{"type":37,"value":1365},{"type":32,"tag":93,"props":1945,"children":1946},{"class":95,"line":171},[1947],{"type":32,"tag":93,"props":1948,"children":1949},{"style":110},[1950],{"type":37,"value":1373},{"type":32,"tag":93,"props":1952,"children":1953},{"class":95,"line":231},[1954,1958,1963,1968,1973],{"type":32,"tag":93,"props":1955,"children":1956},{"style":110},[1957],{"type":37,"value":113},{"type":32,"tag":93,"props":1959,"children":1960},{"style":110},[1961],{"type":37,"value":1962}," *",{"type":32,"tag":93,"props":1964,"children":1965},{"style":110},[1966],{"type":37,"value":1967}," FROM",{"type":32,"tag":93,"props":1969,"children":1970},{"style":366},[1971],{"type":37,"value":1972}," `project.dataset.cohort_retention_temp`",{"type":32,"tag":93,"props":1974,"children":1975},{"style":116},[1976],{"type":37,"value":450},{"type":32,"tag":33,"props":1978,"children":1979},{},[1980,1985,1987,1993,1994,2000],{"type":32,"tag":457,"props":1981,"children":1982},{},[1983],{"type":37,"value":1984},"Clustering:",{"type":37,"value":1986}," all'interno di ogni partizione, se specificate campi frequentemente filtrati (ad es. ",{"type":32,"tag":52,"props":1988,"children":1990},{"className":1989},[],[1991],{"type":37,"value":1992},"day_n",{"type":37,"value":59},{"type":32,"tag":52,"props":1995,"children":1997},{"className":1996},[],[1998],{"type":37,"value":1999},"metric_name",{"type":37,"value":2001},") come cluster, BigQuery esegue block-level pruning. Una query come \"mostrami retention day_7 + metrica active_users\" scannerà solo i block rilevanti.",{"type":32,"tag":33,"props":2003,"children":2004},{},[2005,2007,2013],{"type":37,"value":2006},"Esempio concreto: 365 partizioni (giornaliere), ogni partizione 3GB. Senza clustering, un filtro \"day_7\" scannerà 365 partizioni × 3GB = 1TB. Con clustering, scannerà solo i block dove ",{"type":32,"tag":52,"props":2008,"children":2010},{"className":2009},[],[2011],{"type":37,"value":2012},"day_n=7",{"type":37,"value":2014},", totale 12GB. Differenza di costo: 5$ → 0,06$.",{"type":32,"tag":33,"props":2016,"children":2017},{},[2018,2023,2025,2030,2032,2037],{"type":32,"tag":457,"props":2019,"children":2020},{},[2021],{"type":37,"value":2022},"Anti-pattern:",{"type":37,"value":2024}," non clusterizzate per ",{"type":32,"tag":52,"props":2026,"children":2028},{"className":2027},[],[2029],{"type":37,"value":261},{"type":37,"value":2031},". L'analisi cohort non è a livello di utente, ma di aggregazione a livello cohort. Clusterizzare per ",{"type":32,"tag":52,"props":2033,"children":2035},{"className":2034},[],[2036],{"type":37,"value":261},{"type":37,"value":2038}," non aiuta il query planner, anzi riduce l'efficienza della cache.",{"type":32,"tag":40,"props":2040,"children":2042},{"id":2041},"identity-resolution-per-la-precisione-dei-cohort",[2043],{"type":37,"value":2044},"Identity Resolution per la Precisione dei Cohort",{"type":32,"tag":33,"props":2046,"children":2047},{},[2048,2050,2055,2057,2062,2064,2073,2075,2081,2083,2088],{"type":37,"value":2049},"L'accuratezza dell'analisi cohort dipende dalla precisione dell'",{"type":32,"tag":52,"props":2051,"children":2053},{"className":2052},[],[2054],{"type":37,"value":261},{"type":37,"value":2056},". Quando una sessione anonima seguita da login viene attribuita a due ",{"type":32,"tag":52,"props":2058,"children":2060},{"className":2059},[],[2061],{"type":37,"value":261},{"type":37,"value":2063}," diversi, un JOIN ingenuo crea due record cohort separati. Risolvete questo problema con ",{"type":32,"tag":2065,"props":2066,"children":2070},"a",{"href":2067,"rel":2068},"https:\u002F\u002Fwww.roibase.com.tr\u002Fit\u002Ffirstparty",[2069],"nofollow",[2071],{"type":37,"value":2072},"First-Party Data & Architettura di Misurazione",{"type":37,"value":2074},": costruite un identity graph tra ",{"type":32,"tag":52,"props":2076,"children":2078},{"className":2077},[],[2079],{"type":37,"value":2080},"client_id",{"type":37,"value":2082}," anonimo e ",{"type":32,"tag":52,"props":2084,"children":2086},{"className":2085},[],[2087],{"type":37,"value":261},{"type":37,"value":2089}," autenticato.",{"type":32,"tag":83,"props":2091,"children":2093},{"className":85,"code":2092,"language":87,"meta":16,"style":16},"-- Tabella di identity resolution\nCREATE TABLE `project.dataset.identity_graph` (\n  canonical_user_id STRING,\n  client_id STRING,\n  user_id STRING,\n  merged_at TIMESTAMP\n)\nPARTITION BY DATE(merged_at)\nCLUSTER BY canonical_user_id;\n\n-- Combinate con la query cohort\nWITH resolved_users AS (\n  SELECT \n    COALESCE(ig.canonical_user_id, e.user_id) AS user_id,\n    e.event_date,\n    e.event_name\n  FROM events e\n  LEFT JOIN identity_graph ig \n    ON e.client_id = ig.client_id OR e.user_id = ig.user_id\n)\nSELECT \n  DATE_TRUNC(u.created_at, DAY) AS cohort_date,\n  DATE_DIFF(r.event_date, u.created_at, DAY) AS day_n,\n  COUNT(DISTINCT r.user_id) AS retained_users\nFROM resolved_users r\nJOIN users u ON r.user_id = u.user_id\nGROUP BY 1, 2;\n",[2094],{"type":32,"tag":52,"props":2095,"children":2096},{"__ignoreMap":16},[2097,2105,2125,2133,2141,2149,2162,2169,2190,2206,2213,2221,2241,2252,2307,2326,2342,2354,2367,2436,2443,2454,2493,2549,2589,2601,2645],{"type":32,"tag":93,"props":2098,"children":2099},{"class":95,"line":96},[2100],{"type":32,"tag":93,"props":2101,"children":2102},{"style":100},[2103],{"type":37,"value":2104},"-- Tabella di identity resolution\n",{"type":32,"tag":93,"props":2106,"children":2107},{"class":95,"line":106},[2108,2112,2116,2121],{"type":32,"tag":93,"props":2109,"children":2110},{"style":110},[2111],{"type":37,"value":1319},{"type":32,"tag":93,"props":2113,"children":2114},{"style":110},[2115],{"type":37,"value":1908},{"type":32,"tag":93,"props":2117,"children":2118},{"style":366},[2119],{"type":37,"value":2120}," `project.dataset.identity_graph`",{"type":32,"tag":93,"props":2122,"children":2123},{"style":116},[2124],{"type":37,"value":679},{"type":32,"tag":93,"props":2126,"children":2127},{"class":95,"line":122},[2128],{"type":32,"tag":93,"props":2129,"children":2130},{"style":116},[2131],{"type":37,"value":2132},"  canonical_user_id STRING,\n",{"type":32,"tag":93,"props":2134,"children":2135},{"class":95,"line":171},[2136],{"type":32,"tag":93,"props":2137,"children":2138},{"style":116},[2139],{"type":37,"value":2140},"  client_id STRING,\n",{"type":32,"tag":93,"props":2142,"children":2143},{"class":95,"line":231},[2144],{"type":32,"tag":93,"props":2145,"children":2146},{"style":116},[2147],{"type":37,"value":2148},"  user_id STRING,\n",{"type":32,"tag":93,"props":2150,"children":2151},{"class":95,"line":277},[2152,2157],{"type":32,"tag":93,"props":2153,"children":2154},{"style":116},[2155],{"type":37,"value":2156},"  merged_at ",{"type":32,"tag":93,"props":2158,"children":2159},{"style":110},[2160],{"type":37,"value":2161},"TIMESTAMP\n",{"type":32,"tag":93,"props":2163,"children":2164},{"class":95,"line":291},[2165],{"type":32,"tag":93,"props":2166,"children":2167},{"style":116},[2168],{"type":37,"value":1009},{"type":32,"tag":93,"props":2170,"children":2171},{"class":95,"line":26},[2172,2176,2180,2185],{"type":32,"tag":93,"props":2173,"children":2174},{"style":110},[2175],{"type":37,"value":1337},{"type":32,"tag":93,"props":2177,"children":2178},{"style":110},[2179],{"type":37,"value":1342},{"type":32,"tag":93,"props":2181,"children":2182},{"style":110},[2183],{"type":37,"value":2184}," DATE",{"type":32,"tag":93,"props":2186,"children":2187},{"style":116},[2188],{"type":37,"value":2189},"(merged_at)\n",{"type":32,"tag":93,"props":2191,"children":2192},{"class":95,"line":372},[2193,2197,2201],{"type":32,"tag":93,"props":2194,"children":2195},{"style":116},[2196],{"type":37,"value":1355},{"type":32,"tag":93,"props":2198,"children":2199},{"style":110},[2200],{"type":37,"value":1360},{"type":32,"tag":93,"props":2202,"children":2203},{"style":116},[2204],{"type":37,"value":2205}," canonical_user_id;\n",{"type":32,"tag":93,"props":2207,"children":2208},{"class":95,"line":403},[2209],{"type":32,"tag":93,"props":2210,"children":2211},{"emptyLinePlaceholder":654},[2212],{"type":37,"value":657},{"type":32,"tag":93,"props":2214,"children":2215},{"class":95,"line":426},[2216],{"type":32,"tag":93,"props":2217,"children":2218},{"style":100},[2219],{"type":37,"value":2220},"-- Combinate con la query cohort\n",{"type":32,"tag":93,"props":2222,"children":2223},{"class":95,"line":682},[2224,2228,2233,2237],{"type":32,"tag":93,"props":2225,"children":2226},{"style":110},[2227],{"type":37,"value":665},{"type":32,"tag":93,"props":2229,"children":2230},{"style":116},[2231],{"type":37,"value":2232}," resolved_users ",{"type":32,"tag":93,"props":2234,"children":2235},{"style":110},[2236],{"type":37,"value":163},{"type":32,"tag":93,"props":2238,"children":2239},{"style":116},[2240],{"type":37,"value":679},{"type":32,"tag":93,"props":2242,"children":2243},{"class":95,"line":695},[2244,2248],{"type":32,"tag":93,"props":2245,"children":2246},{"style":110},[2247],{"type":37,"value":688},{"type":32,"tag":93,"props":2249,"children":2250},{"style":116},[2251],{"type":37,"value":119},{"type":32,"tag":93,"props":2253,"children":2254},{"class":95,"line":716},[2255,2260,2264,2269,2273,2278,2282,2286,2290,2294,2298,2302],{"type":32,"tag":93,"props":2256,"children":2257},{"style":131},[2258],{"type":37,"value":2259},"    COALESCE",{"type":32,"tag":93,"props":2261,"children":2262},{"style":116},[2263],{"type":37,"value":242},{"type":32,"tag":93,"props":2265,"children":2266},{"style":131},[2267],{"type":37,"value":2268},"ig",{"type":32,"tag":93,"props":2270,"children":2271},{"style":116},[2272],{"type":37,"value":139},{"type":32,"tag":93,"props":2274,"children":2275},{"style":131},[2276],{"type":37,"value":2277},"canonical_user_id",{"type":32,"tag":93,"props":2279,"children":2280},{"style":116},[2281],{"type":37,"value":59},{"type":32,"tag":93,"props":2283,"children":2284},{"style":131},[2285],{"type":37,"value":182},{"type":32,"tag":93,"props":2287,"children":2288},{"style":116},[2289],{"type":37,"value":139},{"type":32,"tag":93,"props":2291,"children":2292},{"style":131},[2293],{"type":37,"value":261},{"type":32,"tag":93,"props":2295,"children":2296},{"style":116},[2297],{"type":37,"value":158},{"type":32,"tag":93,"props":2299,"children":2300},{"style":110},[2301],{"type":37,"value":163},{"type":32,"tag":93,"props":2303,"children":2304},{"style":116},[2305],{"type":37,"value":2306}," user_id,\n",{"type":32,"tag":93,"props":2308,"children":2309},{"class":95,"line":757},[2310,2314,2318,2322],{"type":32,"tag":93,"props":2311,"children":2312},{"style":131},[2313],{"type":37,"value":820},{"type":32,"tag":93,"props":2315,"children":2316},{"style":116},[2317],{"type":37,"value":139},{"type":32,"tag":93,"props":2319,"children":2320},{"style":131},[2321],{"type":37,"value":191},{"type":32,"tag":93,"props":2323,"children":2324},{"style":116},[2325],{"type":37,"value":543},{"type":32,"tag":93,"props":2327,"children":2328},{"class":95,"line":814},[2329,2333,2337],{"type":32,"tag":93,"props":2330,"children":2331},{"style":131},[2332],{"type":37,"value":820},{"type":32,"tag":93,"props":2334,"children":2335},{"style":116},[2336],{"type":37,"value":139},{"type":32,"tag":93,"props":2338,"children":2339},{"style":131},[2340],{"type":37,"value":2341},"event_name\n",{"type":32,"tag":93,"props":2343,"children":2344},{"class":95,"line":835},[2345,2349],{"type":32,"tag":93,"props":2346,"children":2347},{"style":110},[2348],{"type":37,"value":858},{"type":32,"tag":93,"props":2350,"children":2351},{"style":116},[2352],{"type":37,"value":2353}," events e\n",{"type":32,"tag":93,"props":2355,"children":2356},{"class":95,"line":852},[2357,2362],{"type":32,"tag":93,"props":2358,"children":2359},{"style":110},[2360],{"type":37,"value":2361},"  LEFT JOIN",{"type":32,"tag":93,"props":2363,"children":2364},{"style":116},[2365],{"type":37,"value":2366}," identity_graph ig \n",{"type":32,"tag":93,"props":2368,"children":2369},{"class":95,"line":876},[2370,2375,2379,2383,2387,2391,2396,2400,2404,2408,2412,2416,2420,2424,2428,2432],{"type":32,"tag":93,"props":2371,"children":2372},{"style":110},[2373],{"type":37,"value":2374},"    ON",{"type":32,"tag":93,"props":2376,"children":2377},{"style":131},[2378],{"type":37,"value":329},{"type":32,"tag":93,"props":2380,"children":2381},{"style":116},[2382],{"type":37,"value":139},{"type":32,"tag":93,"props":2384,"children":2385},{"style":131},[2386],{"type":37,"value":2080},{"type":32,"tag":93,"props":2388,"children":2389},{"style":110},[2390],{"type":37,"value":324},{"type":32,"tag":93,"props":2392,"children":2393},{"style":131},[2394],{"type":37,"value":2395}," ig",{"type":32,"tag":93,"props":2397,"children":2398},{"style":116},[2399],{"type":37,"value":139},{"type":32,"tag":93,"props":2401,"children":2402},{"style":131},[2403],{"type":37,"value":2080},{"type":32,"tag":93,"props":2405,"children":2406},{"style":110},[2407],{"type":37,"value":1898},{"type":32,"tag":93,"props":2409,"children":2410},{"style":131},[2411],{"type":37,"value":329},{"type":32,"tag":93,"props":2413,"children":2414},{"style":116},[2415],{"type":37,"value":139},{"type":32,"tag":93,"props":2417,"children":2418},{"style":131},[2419],{"type":37,"value":261},{"type":32,"tag":93,"props":2421,"children":2422},{"style":110},[2423],{"type":37,"value":324},{"type":32,"tag":93,"props":2425,"children":2426},{"style":131},[2427],{"type":37,"value":2395},{"type":32,"tag":93,"props":2429,"children":2430},{"style":116},[2431],{"type":37,"value":139},{"type":32,"tag":93,"props":2433,"children":2434},{"style":131},[2435],{"type":37,"value":338},{"type":32,"tag":93,"props":2437,"children":2438},{"class":95,"line":931},[2439],{"type":32,"tag":93,"props":2440,"children":2441},{"style":116},[2442],{"type":37,"value":1009},{"type":32,"tag":93,"props":2444,"children":2445},{"class":95,"line":950},[2446,2450],{"type":32,"tag":93,"props":2447,"children":2448},{"style":110},[2449],{"type":37,"value":113},{"type":32,"tag":93,"props":2451,"children":2452},{"style":116},[2453],{"type":37,"value":119},{"type":32,"tag":93,"props":2455,"children":2456},{"class":95,"line":994},[2457,2461,2465,2469,2473,2477,2481,2485,2489],{"type":32,"tag":93,"props":2458,"children":2459},{"style":116},[2460],{"type":37,"value":128},{"type":32,"tag":93,"props":2462,"children":2463},{"style":131},[2464],{"type":37,"value":134},{"type":32,"tag":93,"props":2466,"children":2467},{"style":116},[2468],{"type":37,"value":139},{"type":32,"tag":93,"props":2470,"children":2471},{"style":131},[2472],{"type":37,"value":144},{"type":32,"tag":93,"props":2474,"children":2475},{"style":116},[2476],{"type":37,"value":59},{"type":32,"tag":93,"props":2478,"children":2479},{"style":110},[2480],{"type":37,"value":153},{"type":32,"tag":93,"props":2482,"children":2483},{"style":116},[2484],{"type":37,"value":158},{"type":32,"tag":93,"props":2486,"children":2487},{"style":110},[2488],{"type":37,"value":163},{"type":32,"tag":93,"props":2490,"children":2491},{"style":116},[2492],{"type":37,"value":168},{"type":32,"tag":93,"props":2494,"children":2495},{"class":95,"line":1003},[2496,2500,2505,2509,2513,2517,2521,2525,2529,2533,2537,2541,2545],{"type":32,"tag":93,"props":2497,"children":2498},{"style":116},[2499],{"type":37,"value":177},{"type":32,"tag":93,"props":2501,"children":2502},{"style":131},[2503],{"type":37,"value":2504},"r",{"type":32,"tag":93,"props":2506,"children":2507},{"style":116},[2508],{"type":37,"value":139},{"type":32,"tag":93,"props":2510,"children":2511},{"style":131},[2512],{"type":37,"value":191},{"type":32,"tag":93,"props":2514,"children":2515},{"style":116},[2516],{"type":37,"value":59},{"type":32,"tag":93,"props":2518,"children":2519},{"style":131},[2520],{"type":37,"value":134},{"type":32,"tag":93,"props":2522,"children":2523},{"style":116},[2524],{"type":37,"value":139},{"type":32,"tag":93,"props":2526,"children":2527},{"style":131},[2528],{"type":37,"value":144},{"type":32,"tag":93,"props":2530,"children":2531},{"style":116},[2532],{"type":37,"value":59},{"type":32,"tag":93,"props":2534,"children":2535},{"style":110},[2536],{"type":37,"value":153},{"type":32,"tag":93,"props":2538,"children":2539},{"style":116},[2540],{"type":37,"value":158},{"type":32,"tag":93,"props":2542,"children":2543},{"style":110},[2544],{"type":37,"value":163},{"type":32,"tag":93,"props":2546,"children":2547},{"style":116},[2548],{"type":37,"value":228},{"type":32,"tag":93,"props":2550,"children":2551},{"class":95,"line":1012},[2552,2556,2560,2564,2569,2573,2577,2581,2585],{"type":32,"tag":93,"props":2553,"children":2554},{"style":131},[2555],{"type":37,"value":237},{"type":32,"tag":93,"props":2557,"children":2558},{"style":116},[2559],{"type":37,"value":242},{"type":32,"tag":93,"props":2561,"children":2562},{"style":110},[2563],{"type":37,"value":247},{"type":32,"tag":93,"props":2565,"children":2566},{"style":131},[2567],{"type":37,"value":2568}," r",{"type":32,"tag":93,"props":2570,"children":2571},{"style":116},[2572],{"type":37,"value":139},{"type":32,"tag":93,"props":2574,"children":2575},{"style":131},[2576],{"type":37,"value":261},{"type":32,"tag":93,"props":2578,"children":2579},{"style":116},[2580],{"type":37,"value":158},{"type":32,"tag":93,"props":2582,"children":2583},{"style":110},[2584],{"type":37,"value":163},{"type":32,"tag":93,"props":2586,"children":2587},{"style":116},[2588],{"type":37,"value":274},{"type":32,"tag":93,"props":2590,"children":2591},{"class":95,"line":1021},[2592,2596],{"type":32,"tag":93,"props":2593,"children":2594},{"style":110},[2595],{"type":37,"value":283},{"type":32,"tag":93,"props":2597,"children":2598},{"style":116},[2599],{"type":37,"value":2600}," resolved_users r\n",{"type":32,"tag":93,"props":2602,"children":2603},{"class":95,"line":1030},[2604,2608,2613,2617,2621,2625,2629,2633,2637,2641],{"type":32,"tag":93,"props":2605,"children":2606},{"style":110},[2607],{"type":37,"value":297},{"type":32,"tag":93,"props":2609,"children":2610},{"style":116},[2611],{"type":37,"value":2612}," users u ",{"type":32,"tag":93,"props":2614,"children":2615},{"style":110},[2616],{"type":37,"value":307},{"type":32,"tag":93,"props":2618,"children":2619},{"style":131},[2620],{"type":37,"value":2568},{"type":32,"tag":93,"props":2622,"children":2623},{"style":116},[2624],{"type":37,"value":139},{"type":32,"tag":93,"props":2626,"children":2627},{"style":131},[2628],{"type":37,"value":261},{"type":32,"tag":93,"props":2630,"children":2631},{"style":110},[2632],{"type":37,"value":324},{"type":32,"tag":93,"props":2634,"children":2635},{"style":131},[2636],{"type":37,"value":252},{"type":32,"tag":93,"props":2638,"children":2639},{"style":116},[2640],{"type":37,"value":139},{"type":32,"tag":93,"props":2642,"children":2643},{"style":131},[2644],{"type":37,"value":338},{"type":32,"tag":93,"props":2646,"children":2647},{"class":95,"line":1039},[2648,2652,2656,2660,2664],{"type":32,"tag":93,"props":2649,"children":2650},{"style":110},[2651],{"type":37,"value":409},{"type":32,"tag":93,"props":2653,"children":2654},{"style":131},[2655],{"type":37,"value":414},{"type":32,"tag":93,"props":2657,"children":2658},{"style":116},[2659],{"type":37,"value":59},{"type":32,"tag":93,"props":2661,"children":2662},{"style":131},[2663],{"type":37,"value":445},{"type":32,"tag":93,"props":2665,"children":2666},{"style":116},[2667],{"type":37,"value":450},{"type":32,"tag":33,"props":2669,"children":2670},{},[2671],{"type":37,"value":2672},"Senza identity resolution, i cohort si gonfiano del 12-18% (un utente viene registrato con due ID diversi). Questo errore mostra le metriche di retention basse, perché il numeratore del cohort cresce ma l'attività a day_n rimane la stessa.",{"type":32,"tag":40,"props":2674,"children":2676},{"id":2675},"monitoraggio-del-costo-delle-query-production-monitoring-con-information_schema",[2677],{"type":37,"value":2678},"Monitoraggio del Costo delle Query: Production Monitoring con INFORMATION_SCHEMA",{"type":32,"tag":33,"props":2680,"children":2681},{},[2682,2684,2690],{"type":37,"value":2683},"Dopo aver costruito l'architettura cohort, dovete continuare a ottimizzare il costo delle query. La tabella ",{"type":32,"tag":52,"props":2685,"children":2687},{"className":2686},[],[2688],{"type":37,"value":2689},"INFORMATION_SCHEMA.JOBS",{"type":37,"value":2691}," di BigQuery vi mostra quanti byte scannerà ogni query, l'utilizzo degli slot e il costo totale.",{"type":32,"tag":83,"props":2693,"children":2695},{"className":85,"code":2694,"language":87,"meta":16,"style":16},"SELECT\n  user_email,\n  query,\n  total_bytes_processed \u002F POW(10, 12) AS tb_processed,\n  (total_bytes_processed \u002F POW(10, 12)) * 5 AS cost_usd,\n  total_slot_ms \u002F 1000 \u002F 60 AS slot_minutes\nFROM `region-us`.INFORMATION_SCHEMA.JOBS_BY_PROJECT\nWHERE creation_time >= TIMESTAMP_SUB(CURRENT_TIMESTAMP(), INTERVAL 7 DAY)\n  AND statement_type = 'SELECT'\n  AND query LIKE '%cohort_retention%'\nORDER BY total_bytes_processed DESC\nLIMIT 20;\n",[2696],{"type":32,"tag":52,"props":2697,"children":2698},{"__ignoreMap":16},[2699,2706,2714,2722,2767,2819,2855,2885,2931,2952,2974,2991],{"type":32,"tag":93,"props":2700,"children":2701},{"class":95,"line":96},[2702],{"type":32,"tag":93,"props":2703,"children":2704},{"style":110},[2705],{"type":37,"value":1018},{"type":32,"tag":93,"props":2707,"children":2708},{"class":95,"line":106},[2709],{"type":32,"tag":93,"props":2710,"children":2711},{"style":116},[2712],{"type":37,"value":2713},"  user_email,\n",{"type":32,"tag":93,"props":2715,"children":2716},{"class":95,"line":122},[2717],{"type":32,"tag":93,"props":2718,"children":2719},{"style":116},[2720],{"type":37,"value":2721},"  query,\n",{"type":32,"tag":93,"props":2723,"children":2724},{"class":95,"line":171},[2725,2730,2735,2740,2745,2749,2754,2758,2762],{"type":32,"tag":93,"props":2726,"children":2727},{"style":116},[2728],{"type":37,"value":2729},"  total_bytes_processed ",{"type":32,"tag":93,"props":2731,"children":2732},{"style":110},[2733],{"type":37,"value":2734},"\u002F",{"type":32,"tag":93,"props":2736,"children":2737},{"style":116},[2738],{"type":37,"value":2739}," POW(",{"type":32,"tag":93,"props":2741,"children":2742},{"style":131},[2743],{"type":37,"value":2744},"10",{"type":32,"tag":93,"props":2746,"children":2747},{"style":116},[2748],{"type":37,"value":59},{"type":32,"tag":93,"props":2750,"children":2751},{"style":131},[2752],{"type":37,"value":2753},"12",{"type":32,"tag":93,"props":2755,"children":2756},{"style":116},[2757],{"type":37,"value":158},{"type":32,"tag":93,"props":2759,"children":2760},{"style":110},[2761],{"type":37,"value":163},{"type":32,"tag":93,"props":2763,"children":2764},{"style":116},[2765],{"type":37,"value":2766}," tb_processed,\n",{"type":32,"tag":93,"props":2768,"children":2769},{"class":95,"line":231},[2770,2775,2779,2783,2787,2791,2795,2800,2805,2810,2814],{"type":32,"tag":93,"props":2771,"children":2772},{"style":116},[2773],{"type":37,"value":2774},"  (total_bytes_processed ",{"type":32,"tag":93,"props":2776,"children":2777},{"style":110},[2778],{"type":37,"value":2734},{"type":32,"tag":93,"props":2780,"children":2781},{"style":116},[2782],{"type":37,"value":2739},{"type":32,"tag":93,"props":2784,"children":2785},{"style":131},[2786],{"type":37,"value":2744},{"type":32,"tag":93,"props":2788,"children":2789},{"style":116},[2790],{"type":37,"value":59},{"type":32,"tag":93,"props":2792,"children":2793},{"style":131},[2794],{"type":37,"value":2753},{"type":32,"tag":93,"props":2796,"children":2797},{"style":116},[2798],{"type":37,"value":2799},")) ",{"type":32,"tag":93,"props":2801,"children":2802},{"style":110},[2803],{"type":37,"value":2804},"*",{"type":32,"tag":93,"props":2806,"children":2807},{"style":131},[2808],{"type":37,"value":2809}," 5",{"type":32,"tag":93,"props":2811,"children":2812},{"style":110},[2813],{"type":37,"value":1050},{"type":32,"tag":93,"props":2815,"children":2816},{"style":116},[2817],{"type":37,"value":2818}," cost_usd,\n",{"type":32,"tag":93,"props":2820,"children":2821},{"class":95,"line":277},[2822,2827,2831,2836,2841,2846,2850],{"type":32,"tag":93,"props":2823,"children":2824},{"style":116},[2825],{"type":37,"value":2826},"  total_slot_ms ",{"type":32,"tag":93,"props":2828,"children":2829},{"style":110},[2830],{"type":37,"value":2734},{"type":32,"tag":93,"props":2832,"children":2833},{"style":131},[2834],{"type":37,"value":2835}," 1000",{"type":32,"tag":93,"props":2837,"children":2838},{"style":110},[2839],{"type":37,"value":2840}," \u002F",{"type":32,"tag":93,"props":2842,"children":2843},{"style":131},[2844],{"type":37,"value":2845}," 60",{"type":32,"tag":93,"props":2847,"children":2848},{"style":110},[2849],{"type":37,"value":1050},{"type":32,"tag":93,"props":2851,"children":2852},{"style":116},[2853],{"type":37,"value":2854}," slot_minutes\n",{"type":32,"tag":93,"props":2856,"children":2857},{"class":95,"line":291},[2858,2862,2867,2871,2876,2880],{"type":32,"tag":93,"props":2859,"children":2860},{"style":110},[2861],{"type":37,"value":283},{"type":32,"tag":93,"props":2863,"children":2864},{"style":366},[2865],{"type":37,"value":2866}," `region-us`",{"type":32,"tag":93,"props":2868,"children":2869},{"style":116},[2870],{"type":37,"value":139},{"type":32,"tag":93,"props":2872,"children":2873},{"style":131},[2874],{"type":37,"value":2875},"INFORMATION_SCHEMA",{"type":32,"tag":93,"props":2877,"children":2878},{"style":116},[2879],{"type":37,"value":139},{"type":32,"tag":93,"props":2881,"children":2882},{"style":131},[2883],{"type":37,"value":2884},"JOBS_BY_PROJECT\n",{"type":32,"tag":93,"props":2886,"children":2887},{"class":95,"line":26},[2888,2892,2897,2902,2907,2912,2917,2922,2927],{"type":32,"tag":93,"props":2889,"children":2890},{"style":110},[2891],{"type":37,"value":346},{"type":32,"tag":93,"props":2893,"children":2894},{"style":116},[2895],{"type":37,"value":2896}," creation_time ",{"type":32,"tag":93,"props":2898,"children":2899},{"style":110},[2900],{"type":37,"value":2901},">=",{"type":32,"tag":93,"props":2903,"children":2904},{"style":116},[2905],{"type":37,"value":2906}," TIMESTAMP_SUB(",{"type":32,"tag":93,"props":2908,"children":2909},{"style":131},[2910],{"type":37,"value":2911},"CURRENT_TIMESTAMP",{"type":32,"tag":93,"props":2913,"children":2914},{"style":116},[2915],{"type":37,"value":2916},"(), INTERVAL ",{"type":32,"tag":93,"props":2918,"children":2919},{"style":131},[2920],{"type":37,"value":2921},"7",{"type":32,"tag":93,"props":2923,"children":2924},{"style":110},[2925],{"type":37,"value":2926}," DAY",{"type":32,"tag":93,"props":2928,"children":2929},{"style":116},[2930],{"type":37,"value":1009},{"type":32,"tag":93,"props":2932,"children":2933},{"class":95,"line":372},[2934,2938,2943,2947],{"type":32,"tag":93,"props":2935,"children":2936},{"style":110},[2937],{"type":37,"value":378},{"type":32,"tag":93,"props":2939,"children":2940},{"style":116},[2941],{"type":37,"value":2942}," statement_type ",{"type":32,"tag":93,"props":2944,"children":2945},{"style":110},[2946],{"type":37,"value":533},{"type":32,"tag":93,"props":2948,"children":2949},{"style":366},[2950],{"type":37,"value":2951}," 'SELECT'\n",{"type":32,"tag":93,"props":2953,"children":2954},{"class":95,"line":403},[2955,2959,2964,2969],{"type":32,"tag":93,"props":2956,"children":2957},{"style":110},[2958],{"type":37,"value":378},{"type":32,"tag":93,"props":2960,"children":2961},{"style":116},[2962],{"type":37,"value":2963}," query ",{"type":32,"tag":93,"props":2965,"children":2966},{"style":110},[2967],{"type":37,"value":2968},"LIKE",{"type":32,"tag":93,"props":2970,"children":2971},{"style":366},[2972],{"type":37,"value":2973}," '%cohort_retention%'\n",{"type":32,"tag":93,"props":2975,"children":2976},{"class":95,"line":426},[2977,2981,2986],{"type":32,"tag":93,"props":2978,"children":2979},{"style":110},[2980],{"type":37,"value":432},{"type":32,"tag":93,"props":2982,"children":2983},{"style":116},[2984],{"type":37,"value":2985}," total_bytes_processed ",{"type":32,"tag":93,"props":2987,"children":2988},{"style":110},[2989],{"type":37,"value":2990},"DESC\n",{"type":32,"tag":93,"props":2992,"children":2993},{"class":95,"line":682},[2994,2999,3004],{"type":32,"tag":93,"props":2995,"children":2996},{"style":110},[2997],{"type":37,"value":2998},"LIMIT",{"type":32,"tag":93,"props":3000,"children":3001},{"style":131},[3002],{"type":37,"value":3003}," 20",{"type":32,"tag":93,"props":3005,"children":3006},{"style":116},[3007],{"type":37,"value":450},{"type":32,"tag":33,"props":3009,"children":3010},{},[3011,3013,3019],{"type":37,"value":3012},"Questa query elenca le query sulle tabelle cohort degli ultimi 7 giorni ordinate per costo. Se un pannello dashboard viene attivato 500 volte al giorno e scannerà 80GB ogni volta (segno di filtro di partizione mancante), il costo è 500 × 80GB × 5$\u002FTB = 200$ al giorno. In questo caso, aggiungere un filtro ",{"type":32,"tag":52,"props":3014,"children":3016},{"className":3015},[],[3017],{"type":37,"value":3018},"WHERE cohort_date >= CURRENT_DATE() - 30",{"type":37,"value":3020}," alla query del pannello ridurrà il costo a 6$ al giorno.",{"type":32,"tag":33,"props":3022,"children":3023},{},[3024],{"type":32,"tag":457,"props":3025,"children":3026},{},[3027],{"type":37,"value":3028},"Checklist Production:",{"type":32,"tag":3030,"props":3031,"children":3034},"ul",{"className":3032},[3033],"contains-task-list",[3035,3055,3077,3086,3095,3111],{"type":32,"tag":3036,"props":3037,"children":3040},"li",{"className":3038},[3039],"task-list-item",[3041,3046,3048,3053],{"type":32,"tag":3042,"props":3043,"children":3045},"input",{"disabled":654,"type":3044},"checkbox",[],{"type":37,"value":3047}," Tutte le tabelle cohort sono partizionate per ",{"type":32,"tag":52,"props":3049,"children":3051},{"className":3050},[],[3052],{"type":37,"value":1877},{"type":37,"value":3054},"?",{"type":32,"tag":3036,"props":3056,"children":3058},{"className":3057},[3039],[3059,3062,3064,3069,3070,3075],{"type":32,"tag":3042,"props":3060,"children":3061},{"disabled":654,"type":3044},[],{"type":37,"value":3063}," ",{"type":32,"tag":52,"props":3065,"children":3067},{"className":3066},[],[3068],{"type":37,"value":1992},{"type":37,"value":463},{"type":32,"tag":52,"props":3071,"children":3073},{"className":3072},[],[3074],{"type":37,"value":1999},{"type":37,"value":3076}," sono clusterizzati?",{"type":32,"tag":3036,"props":3078,"children":3080},{"className":3079},[3039],[3081,3084],{"type":32,"tag":3042,"props":3082,"children":3083},{"disabled":654,"type":3044},[],{"type":37,"value":3085}," Il job dbt incremental viene eseguito quotidianamente?",{"type":32,"tag":3036,"props":3087,"children":3089},{"className":3088},[3039],[3090,3093],{"type":32,"tag":3042,"props":3091,"children":3092},{"disabled":654,"type":3044},[],{"type":37,"value":3094}," La materialized view è limitata a una finestra di 90 giorni?",{"type":32,"tag":3036,"props":3096,"children":3098},{"className":3097},[3039],[3099,3102,3104,3110],{"type":32,"tag":3042,"props":3100,"children":3101},{"disabled":654,"type":3044},[],{"type":37,"value":3103}," Le query del dashboard hanno il filtro ",{"type":32,"tag":52,"props":3105,"children":3107},{"className":3106},[],[3108],{"type":37,"value":3109},"WHERE cohort_date >= ...",{"type":37,"value":3054},{"type":32,"tag":3036,"props":3112,"children":3114},{"className":3113},[3039],[3115,3118,3120,3125],{"type":32,"tag":3042,"props":3116,"children":3117},{"disabled":654,"type":3044},[],{"type":37,"value":3119}," Raccogliete un report settimanale dei costi con ",{"type":32,"tag":52,"props":3121,"children":3123},{"className":3122},[],[3124],{"type":37,"value":2875},{"type":37,"value":3054},{"type":32,"tag":33,"props":3127,"children":3128},{},[3129],{"type":37,"value":3130},"Quando l'architettura cohort è costruita correttamente, l'analisi della retention diventa production-ready: 100M di eventi al giorno, tempo di query di 5 secondi, costo di compute mensile di 10 dollari. Tuttavia, questa architettura richiede identity resolution first-party, standardizzazione dello schema degli event e disciplina nella pipeline dbt — per questo motivo, l'ingegneria della retention è una piattaforma, non un SQL una tantum.",{"type":32,"tag":3132,"props":3133,"children":3134},"style",{},[3135],{"type":37,"value":3136},"html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}",{"title":16,"searchDepth":122,"depth":122,"links":3138},[3139,3142,3143,3144,3145],{"id":42,"depth":106,"text":45,"children":3140},[3141],{"id":473,"depth":122,"text":476},{"id":1289,"depth":106,"text":1292},{"id":1853,"depth":106,"text":1856},{"id":2041,"depth":106,"text":2044},{"id":2675,"depth":106,"text":2678},"markdown","content:it:data:architettura-tabella-cohort.md","content","it\u002Fdata\u002Farchitettura-tabella-cohort.md","it\u002Fdata\u002Farchitettura-tabella-cohort","md",1782050755405]