Advertisement
Guest User

Untitled

a guest
May 19th, 2019
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.37 KB | None | 0 0
  1. view: messages_user_last {
  2. # Or, you could make this view a derived table, like this:
  3. derived_table: {
  4. sql: WITH messages AS (
  5. SELECT
  6. m_id,
  7. date,
  8. botSlug,
  9. author,
  10. reader,
  11. status
  12. FROM
  13. `analytics.incoming_2019_05_*`
  14. WHERE
  15. m_type != 'watermark' ),
  16. conv AS (
  17. SELECT
  18. *,
  19. RANK() OVER (PARTITION BY botSlug, IF(author.role = 'user', author.id, reader)
  20. ORDER BY
  21. date DESC) AS rank,
  22. LOWER(currentState) IN ('humanloop', 'human-loop', 'human-mode') is_in_humanloop
  23. FROM
  24. messages i
  25. LEFT JOIN
  26. `analytics.bot_states_2019_05_*` bs
  27. ON
  28. (i.m_id = bs.messageId) )
  29. SELECT
  30. *
  31. FROM
  32. conv
  33. WHERE
  34. status = 'RECEIVED'
  35. AND rank = 1
  36. AND DATETIME_DIFF('2019-05-04 00:00:00',
  37. DATETIME(date),
  38. MINUTE) >= 60
  39. AND date BETWEEN '2019-05-03 00:00:00'
  40. AND '2019-05-04 00:00:00'
  41. ;;
  42. }
  43.  
  44. dimension: m_id {
  45. primary_key: yes
  46. description: "Unique ID for each message"
  47. label: "Id"
  48. type: string
  49. sql: ${TABLE}.m_id ;;
  50. }
  51.  
  52. dimension_group: date {
  53. type: time
  54. timeframes: [
  55. raw,
  56. time,
  57. date,
  58. week,
  59. month,
  60. quarter,
  61. year,
  62. hour
  63. ]
  64. sql: ${TABLE}.date ;;
  65. label: "Date"
  66. }
  67.  
  68. dimension: bot_slug {
  69. type: string
  70. sql: ${TABLE}.botSlug ;;
  71. label: "Bot Slug"
  72. }
  73.  
  74. dimension: author {
  75. hidden: yes
  76. sql: ${TABLE}.author ;;
  77. label: "Author"
  78. }
  79.  
  80. dimension: reader {
  81. type: string
  82. sql: ${TABLE}.reader ;;
  83. label: "Reader"
  84. }
  85.  
  86. dimension: status {
  87. type: string
  88. sql: ${TABLE}.status ;;
  89. label: "Status"
  90. }
  91.  
  92. dimension: rank {
  93. type: number
  94. sql: ${TABLE}.rank ;;
  95. label: "Rank"
  96. }
  97.  
  98. dimension: is_in_humanloop {
  99. type: yesno
  100. sql: ${TABLE}.is_in_humanloop ;;
  101. label: "Is in humanloop"
  102. }
  103.  
  104. measure: count_all {
  105. description: "Use this for counting lifetime orders across many users"
  106. type: count
  107. # sql: ${lifetime_orders} ;;
  108. label: "Count"
  109. }
  110. }
  111.  
  112. view: messages_user_last__author {
  113. dimension: id {
  114. primary_key: yes
  115. type: string
  116. sql: ${TABLE}.id ;;
  117. label: "Author Id"
  118. }
  119.  
  120. dimension: role {
  121. type: string
  122. sql: ${TABLE}.role ;;
  123. label: "Author Role"
  124. }
  125. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement