Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
Metabase
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Engineering Digital Service
Metabase
Commits
424c20ed
Commit
424c20ed
authored
8 years ago
by
Cam Saül
Browse files
Options
Downloads
Patches
Plain Diff
Actually don't make unit->extraction-fn a const
parent
0d58c0b6
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/metabase/driver/druid/query_processor.clj
+36
-34
36 additions, 34 deletions
src/metabase/driver/druid/query_processor.clj
with
36 additions
and
34 deletions
src/metabase/driver/druid/query_processor.clj
+
36
−
34
View file @
424c20ed
...
...
@@ -180,40 +180,42 @@
{
:type
:javascript
:function
(
s/replace
(
apply
str
function-str-parts
)
#
"\s+"
" "
)})
(
def
^
:private
^
:const
unit->extraction-fn
{
:default
(
extract
:timeFormat
"yyyy-MM-dd'T'HH:mm:ssZ"
)
:minute
(
extract
:timeFormat
"yyyy-MM-dd'T'HH:mm:00Z"
)
:minute-of-hour
(
extract
:timeFormat
"mm"
)
:hour
(
extract
:timeFormat
"yyyy-MM-dd'T'HH:00:00Z"
)
:hour-of-day
(
extract
:timeFormat
"HH"
)
:day
(
extract
:timeFormat
"yyyy-MM-ddZ"
)
:day-of-week
(
extract
:js
"function (timestamp) {"
" var date = new Date(timestamp);"
" return date.getDay() + 1;"
"}"
)
:day-of-month
(
extract
:timeFormat
"dd"
)
:day-of-year
(
extract
:timeFormat
"DDD"
)
:week
(
extract
:js
"function (timestamp) {"
" var date = new Date(timestamp);"
" var firstDOW = new Date(date - (date.getDay() * 86400000));"
" var month = firstDOW.getMonth() + 1;"
" var day = firstDOW.getDate();"
" return '' + firstDOW.getFullYear() + '-' + (month < 10 ? '0' : '') + month + '-' + (day < 10 ? '0' : '') + day;"
"}"
)
:week-of-year
(
extract
:timeFormat
"ww"
)
:month
(
extract
:timeFormat
"yyyy-MM-01"
)
:month-of-year
(
extract
:timeFormat
"MM"
)
:quarter
(
extract
:js
"function (timestamp) {"
" var date = new Date(timestamp);"
" var month = date.getMonth() + 1;"
; js months are 0 - 11
" var quarterMonth = month - ((month - 1) % 3);"
" return '' + date.getFullYear() + '-' + (quarterMonth < 10 ? '0' : '') + quarterMonth + '-01';"
"}"
)
:quarter-of-year
(
extract
:js
"function (timestamp) {"
" var date = new Date(timestamp);"
" return Math.floor((date.getMonth() + 3) / 3);"
"}"
)
:year
(
extract
:timeFormat
"yyyy"
)})
;; don't try to make this a ^:const map -- extract:timeFormat looks up timezone info at query time
(
defn-
unit->extraction-fn
[
unit
]
(
case
unit
:default
(
extract
:timeFormat
"yyyy-MM-dd'T'HH:mm:ssZ"
)
:minute
(
extract
:timeFormat
"yyyy-MM-dd'T'HH:mm:00Z"
)
:minute-of-hour
(
extract
:timeFormat
"mm"
)
:hour
(
extract
:timeFormat
"yyyy-MM-dd'T'HH:00:00Z"
)
:hour-of-day
(
extract
:timeFormat
"HH"
)
:day
(
extract
:timeFormat
"yyyy-MM-ddZ"
)
:day-of-week
(
extract
:js
"function (timestamp) {"
" var date = new Date(timestamp);"
" return date.getDay() + 1;"
"}"
)
:day-of-month
(
extract
:timeFormat
"dd"
)
:day-of-year
(
extract
:timeFormat
"DDD"
)
:week
(
extract
:js
"function (timestamp) {"
" var date = new Date(timestamp);"
" var firstDOW = new Date(date - (date.getDay() * 86400000));"
" var month = firstDOW.getMonth() + 1;"
" var day = firstDOW.getDate();"
" return '' + firstDOW.getFullYear() + '-' + (month < 10 ? '0' : '') + month + '-' + (day < 10 ? '0' : '') + day;"
"}"
)
:week-of-year
(
extract
:timeFormat
"ww"
)
:month
(
extract
:timeFormat
"yyyy-MM-01"
)
:month-of-year
(
extract
:timeFormat
"MM"
)
:quarter
(
extract
:js
"function (timestamp) {"
" var date = new Date(timestamp);"
" var month = date.getMonth() + 1;"
; js months are 0 - 11
" var quarterMonth = month - ((month - 1) % 3);"
" return '' + date.getFullYear() + '-' + (quarterMonth < 10 ? '0' : '') + quarterMonth + '-01';"
"}"
)
:quarter-of-year
(
extract
:js
"function (timestamp) {"
" var date = new Date(timestamp);"
" return Math.floor((date.getMonth() + 3) / 3);"
"}"
)
:year
(
extract
:timeFormat
"yyyy"
)))
(
def
^
:private
^
:const
units-that-need-post-processing-int-parsing
"`extract:timeFormat` always returns a string; there are cases where we'd like to return an integer instead, such as `:day-of-month`.
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment