-
Notifications
You must be signed in to change notification settings - Fork 0
/
rental.view.lkml
142 lines (125 loc) · 3.18 KB
/
rental.view.lkml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
view: rental {
sql_table_name: leon_thesis_data.rental ;;
dimension: rental_id {
primary_key: yes
type: number
sql: ${TABLE}.rental_id ;;
}
dimension: customer_id {
type: number
# hidden: yes
sql: ${TABLE}.customer_id ;;
}
dimension: inventory_id {
type: number
# hidden: yes
sql: CAST( ${TABLE}.inventory_id as INT64);;
}
dimension: test {
sql: case when rand() > 0.5
then "<div><b>hello</b></div>"
else "<img src='https://ctimgibedfordviewcampuslibrary.files.wordpress.com/2015/10/library-books-return.jpg' height=70 width=70>"
end;;
}
dimension_group: last_update {
type: time
timeframes: [
raw,
time,
date,
week,
month,
quarter,
year
]
sql: ${TABLE}.last_update ;;
}
dimension_group: rental {
type: time
timeframes: [
raw,
time,
date,
week,
month,
quarter,
year
]
sql: ${TABLE}.rental_date ;;
}
measure: first_rental {
type: date
sql:min(${TABLE}.rental_date);;
drill_fields: [detail*]
}
dimension_group: return {
type: time
timeframes: [
raw,
time,
date,
week,
month,
quarter,
year
]
sql: ${TABLE}.return_date ;;
}
dimension: actual_rental_duration{
type: number
value_format: "0 \" Days\""
sql: date_diff(${rental.return_date}, ${rental.rental_date},day);;
}
dimension: overdue {
type: string
sql: if(${rental.actual_rental_duration} - ${film.rental_duration} > 0, "overdue", "on time");;
html:{% if value == "overdue" %}
<p style="color: white; background-color: #252cc7; font-size:150%; text-align:center"><img src="https://ctimgibedfordviewcampuslibrary.files.wordpress.com/2015/10/library-books-return.jpg" height=70 width=70><b>{{ rendered_value }}</b></p>
{% else %}
<p <p style="color: black; background-color: #ffad27; font-size:150%; text-align:center"><img src="https://cdn1.vectorstock.com/i/1000x1000/33/60/hands-palm-applause-success-text-bravo-vector-6003360.jpg" height=70 width=70><b>{{ rendered_value }}</b></p>
{% endif %}
;;
}
dimension: staff_id {
type: number
# hidden: yes
sql: ${TABLE}.staff_id ;;
}
dimension: image {
sql: 1 ;;
html: <img src="https://upload.wikimedia.org/wikipedia/commons/thumb/e/ea/Thats_all_folks.svg/1589px-Thats_all_folks.svg.png"/> ;;
}
measure: count {
type: count
#sql: ${rental_id} ;;
drill_fields: [detail*]
}
# measure: times_rented {
# type: number
# # sql: COUNT(${inventory_id}) ;;
# sql:
# COUNT(rental.inventory_id) AS rental_times_rented
# FROM leon_thesis_data.rental AS rental
#
# GROUP BY 1
# ORDER BY 1
# LIMIT 500 ;;
# drill_fields: [detail*]
# }
# ----- Sets of fields for drilling ------
set: detail {
fields: [
rental_id,
inventory.inventory_id,
staff.staff_id,
staff.last_name,
staff.first_name,
staff.username,
customer.last_name,
customer.customer_id,
customer.first_name,
payment.count,
film.rental_rate
]
}
}