Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Build Funnels with Google BigQuery

Build Funnels with Google BigQuery

Suyeol Jeon

March 03, 2018
Tweet

More Decks by Suyeol Jeon

Other Decks in Programming

Transcript

  1. time view click buy 100 100 200 100 200 300

    300 200 400 300 400 500 300 500 600 300 500 600
  2. time view click buy 100 100 200 100 200 300

    300 200 400 300 400 500 300 500 600 300 500 600
  3. time view click buy 100 100 200 100 200 300

    300 200 400 300 400 500 300 500 600 300 500 600 origin next next
  4. time view click buy 100 100 200 100 200 300

    300 200 400 300 400 500 300 500 600 300 500 600 < origin next next
  5. time view click buy 100 100 200 100 200 300

    300 400 300 400 500 300 500 600 300 500 600 origin next next
  6. time view click buy 100 100 200 100 200 300

    300 400 300 400 500 300 500 600 300 500 600 origin next next
  7. time view click buy 100 100 200 100 100 300

    300 400 300 300 500 300 300 600 300 300 300 origin next next
  8. time view click buy 100 100 200 100 100 300

    300 400 300 300 500 300 300 600 300 300 300
  9. time view click buy 100 100 200 100 100 300

    300 400 300 300 500 300 300 600 300 300 300 100 300 100 300 300
  10. time view click buy 100 100 200 200 300 300

    400 400 500 500 600 600 After (1)
  11. Query (1) #standardSQL SELECT time, (CASE event WHEN "view" THEN

    time END) AS view, (CASE event WHEN "click" THEN time END) AS click, (CASE event WHEN "buy" THEN time END)AS buy FROM events
  12. time view click buy 100 100 200 200 300 300

    400 400 500 500 600 600 Before (2)
  13. time view click buy 100 100 200 100 200 300

    300 200 400 300 400 500 300 500 600 300 500 600 After (2)
  14. #standardSQL SELECT LAST_VALUE(view) OVER (ORDER BY time) AS view, LAST_VALUE(click)

    OVER (ORDER BY time) AS click, LAST_VALUE(buy) OVER (ORDER BY time) AS buy FROM query_1_result ⚠ Query (2)
  15. time view click buy 100 100 200 200 300 300

    400 400 500 500 600 600 ⚠ Query (2)
  16. time view click buy 100 100 NULL NULL 200 200

    300 300 400 400 500 500 600 600 ⚠ Query (2)
  17. time view click buy 100 100 NULL NULL 200 NULL

    200 NULL 300 300 400 400 500 500 600 600 ⚠ Query (2)
  18. time view click buy 100 100 NULL NULL 200 NULL

    200 NULL 300 300 NULL NULL 400 400 500 500 600 600 ⚠ Query (2)
  19. time view click buy 100 100 NULL NULL 200 NULL

    200 NULL 300 300 NULL NULL 400 NULL 400 NULL 500 500 600 600 ⚠ Query (2)
  20. time view click buy 100 100 NULL NULL 200 NULL

    200 NULL 300 300 NULL NULL 400 NULL 400 NULL 500 NULL 500 NULL 600 600 ⚠ Query (2)
  21. time view click buy 100 100 NULL NULL 200 NULL

    200 NULL 300 300 NULL NULL 400 NULL 400 NULL 500 NULL 500 NULL 600 NULL NULL 600 ⚠ Query (2)
  22. time view click buy 100 100 NULL NULL 200 NULL

    200 NULL 300 300 NULL NULL 400 NULL 400 NULL 500 NULL 500 NULL 600 NULL NULL 600 ⚠ Query (2)
  23. #standardSQL SELECT LAST_VALUE(view IGNORE NULLS) OVER (ORDER BY time) AS

    view, LAST_VALUE(click IGNORE NULLS) OVER (ORDER BY time) AS click, LAST_VALUE(buy IGNORE NULLS) OVER (ORDER BY time) AS buy FROM query_1_result ✅ Query (2)
  24. time view click buy 100 100 200 200 300 300

    400 400 500 500 600 600 ✅ Query (2)
  25. time view click buy 100 100 NULL NULL 200 200

    300 300 400 400 500 500 600 600 ✅ Query (2)
  26. time view click buy 100 100 NULL NULL 200 100

    200 NULL 300 300 400 400 500 500 600 600 ✅ Query (2)
  27. time view click buy 100 100 NULL NULL 200 100

    200 NULL 300 300 200 NULL 400 400 500 500 600 600 ✅ Query (2)
  28. time view click buy 100 100 NULL NULL 200 100

    200 NULL 300 300 200 NULL 400 300 400 NULL 500 500 600 600 ✅ Query (2)
  29. time view click buy 100 100 NULL NULL 200 100

    200 NULL 300 300 200 NULL 400 300 400 NULL 500 300 500 NULL 600 600 ✅ Query (2)
  30. time view click buy 100 100 NULL NULL 200 100

    200 NULL 300 300 200 NULL 400 300 400 NULL 500 300 500 NULL 600 300 500 600 ✅ Query (2)
  31. time view click buy 100 100 NULL NULL 200 100

    200 NULL 300 300 200 NULL 400 300 400 NULL 500 300 500 NULL 600 300 500 600 ✅ Query (2)
  32. time view click buy 100 100 200 100 200 300

    300 200 400 300 400 500 300 500 600 300 500 600 Before (3)
  33. time view click buy 100 100 200 100 200 300

    300 200 400 300 400 500 300 500 600 300 500 600 < After (3)
  34. #standardSQL SELECT view, (CASE WHEN view < click THEN click

    END) AS click, (CASE WHEN click < buy THEN buy END) AS buy FROM query_2_result Query (3)
  35. time view click buy 100 100 200 100 200 300

    300 400 300 400 500 300 500 600 300 500 600 Before (4)
  36. time view click buy 100 100 200 100 100 300

    300 400 300 300 500 300 300 600 300 300 300 After (4)
  37. #standardSQL SELECT (CASE WHEN view IS NOT NULL THEN view

    END) AS view, (CASE WHEN click IS NOT NULL THEN view END) AS click, (CASE WHEN buy IS NOT NULL THEN view END) AS buy FROM query_3_result Query (4)
  38. time view click buy 100 100 200 100 100 300

    300 400 300 300 500 300 300 600 300 300 300 Before (5)
  39. #standardSQL SELECT "view" AS step, COUNT(DISTINCT view) AS count FROM

    query_4_result UNION ALL SELECT "click", COUNT(DISTINCT click) FROM query_4_result UNION ALL SELECT "buy", COUNT(DISTINCT buy) FROM query_4_result Query (4)
  40. user time view click buy A 100 100 B 200

    200 B 300 300 A 400 400 A 500 500 A 600 600
  41. user time view click buy A 100 100 B 200

    200 B 300 300 A 400 400 A 500 500 A 600 600
  42. user time view click buy A 100 100 B 200

    200 B 300 300 A 400 400 A 500 500 A 600 600
  43. #standardSQL SELECT LAST_VALUE(view IGNORE NULLS) OVER (ORDER BY time) AS

    view, LAST_VALUE(click IGNORE NULLS) OVER (ORDER BY time) AS click, LAST_VALUE(buy IGNORE NULLS) OVER (ORDER BY time) AS buy FROM query_1_result Back to Query (2)
  44. user time view click buy A 100 100 B 200

    200 B 300 300 A 400 400 A 500 500 A 600 600 Before (2)
  45. user time view click buy A 100 100 B 200

    100 200 B 300 300 200 A 400 300 400 A 500 300 500 A 600 300 500 600 ⚠ After (2)
  46. user time view click buy A 100 100 B 200

    200 B 300 300 200 A 400 100 400 A 500 100 500 A 600 100 500 600 ✅ After (2)
  47. #standardSQL SELECT LAST_VALUE(view IGNORE NULLS) OVER (PARTITION BY user ORDER

    BY time) AS view, LAST_VALUE(click IGNORE NULLS) OVER (PARTITION BY user ORDER BY time) AS click, LAST_VALUE(buy IGNORE NULLS) OVER (PARTITION BY user ORDER BY time) AS buy FROM query_1_result ✅ Query (2)
  48. user time view click buy A 100 100 A 400

    400 A 500 500 A 600 600 PARTITION BY user user time view click buy A 100 100 B 200 200 B 300 300 A 400 400 A 500 500 A 600 600 user time view click buy B 200 200 B 300 300
  49. user time view click buy A 100 100 A 400

    100 400 A 500 100 500 A 600 100 500 600 LAST_VALUE & PARTITION BY user time view click buy A 100 100 B 200 200 B 300 300 A 400 400 A 500 500 A 600 600 user time view click buy B 200 200 B 300 300 200
  50. user time view click buy A 100 100 A 400

    100 400 A 500 100 500 A 600 100 500 600 user time view click buy B 200 200 B 300 300 200 user time view click buy A 100 100 B 200 200 B 300 300 200 A 400 100 400 A 500 100 500 A 600 100 500 600 LAST_VALUE & PARTITION BY
  51. user time view click buy A 100 100 B 200

    200 B 300 300 200 A 400 100 400 A 500 100 500 A 600 100 500 600
  52. user time view click buy A 100 100 B 200

    200 B 300 300 200 A 400 100 400 A 500 100 500 A 600 100 500 600 < <
  53. user time view click buy A 100 100 B 200

    B 300 300 A 400 100 400 A 500 100 500 A 600 100 500 600
  54. user time view click buy A 100 100 B 200

    B 300 300 A 400 100 100 A 500 100 100 A 600 100 100 100
  55. user time view click buy A 100 100 B 200

    B 300 300 A 400 100 100 A 500 100 100 A 600 100 100 100
  56. user time view click buy A 100 100 B 200

    B 300 300 A 400 100 100 A 500 100 100 A 600 100 100 100
  57. user time view click buy A 100 100 B 200

    B 300 300 A 400 100 100 A 500 100 100 A 600 100 100 100 100 300 100 100