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
71ebbb7a
Commit
71ebbb7a
authored
8 years ago
by
Cam Saül
Committed by
GitHub
8 years ago
Browse files
Options
Downloads
Plain Diff
Merge pull request #4101 from metabase/fix-past-relative-date-ranges
Fix past relative date ranges
parents
9bbbca65
31302057
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/metabase/query_processor/expand.clj
+8
-9
8 additions, 9 deletions
src/metabase/query_processor/expand.clj
test/metabase/query_processor_test/date_bucketing_test.clj
+12
-2
12 additions, 2 deletions
test/metabase/query_processor_test/date_bucketing_test.clj
with
20 additions
and
11 deletions
src/metabase/query_processor/expand.clj
+
8
−
9
View file @
71ebbb7a
...
...
@@ -301,20 +301,19 @@
(filter {} (time-interval (field-id 100) :current :day)) "
[
f
n
unit
]
(
if-not
(
integer?
n
)
(
let
[
n
(
normalize-token
n
)]
(
case
n
:current
(
recur
f
0
unit
)
:last
(
recur
f
-1
unit
)
:next
(
recur
f
1
unit
)))
(
case
(
normalize-token
n
)
:current
(
recur
f
0
unit
)
:last
(
recur
f
-1
unit
)
:next
(
recur
f
1
unit
))
(
let
[
f
(
datetime-field
f
unit
)]
(
cond
(
core/=
n
0
)
(
=
f
(
value
f
(
relative-datetime
:current
)))
(
core/=
n
-1
)
(
=
f
(
value
f
(
relative-datetime
-1
unit
)))
(
core/=
n
1
)
(
=
f
(
value
f
(
relative-datetime
1
unit
)))
(
core/<
n
-1
)
(
between
f
(
value
f
(
relative-datetime
(
dec
n
)
unit
))
(
value
f
(
relative-datetime
-1
unit
)))
(
core/>
n
1
)
(
between
f
(
value
f
(
relative-datetime
1
unit
))
(
value
f
(
relative-datetime
(
inc
n
)
unit
)))))))
(
core/<
n
-1
)
(
between
f
(
value
f
(
relative-datetime
n
unit
))
(
value
f
(
relative-datetime
-1
unit
)))
(
core/>
n
1
)
(
between
f
(
value
f
(
relative-datetime
1
unit
))
(
value
f
(
relative-datetime
n
unit
)))))))
(
s/defn
^
:ql
^
:always-validate
filter
"Filter the results returned by the query.
...
...
This diff is collapsed.
Click to expand it.
test/metabase/query_processor_test/date_bucketing_test.clj
+
12
−
2
View file @
71ebbb7a
...
...
@@ -337,12 +337,13 @@
;; that actually reflects the units the results are in.
;; eg when we breakout by one unit and filter by another, make sure the results and the col info
;; use the unit used by breakout
(
defn-
date-bucketing-unit-when-you
[
&
{
:keys
[
breakout-by
filter-by
]}]
(
defn-
date-bucketing-unit-when-you
[
&
{
:keys
[
breakout-by
filter-by
with-interval
]
:or
{
with-interval
:current
}}]
(
let
[
results
(
data/with-temp-db
[
_
(
checkins
:1-per-day
)]
(
data/run-query
checkins
(
ql/aggregation
(
ql/count
))
(
ql/breakout
(
ql/datetime-field
$timestamp
breakout-by
))
(
ql/filter
(
ql/time-interval
$timestamp
:current
filter-by
))))]
(
ql/filter
(
ql/time-interval
$timestamp
with-interval
filter-by
))))]
{
:rows
(
or
(
->
results
:row_count
)
(
throw
(
ex-info
"Query failed!"
results
)))
:unit
(
->
results
:data
:cols
first
:unit
)}))
...
...
@@ -366,3 +367,12 @@
(
expect-with-non-timeseries-dbs-except
#
{
:bigquery
}
{
:rows
1
,
:unit
:hour
}
(
date-bucketing-unit-when-you
:breakout-by
"hour"
,
:filter-by
"day"
))
;; make sure if you use a relative date bucket in the past (e.g. "past 2 months") you get the correct amount of rows (#3910)
(
expect-with-non-timeseries-dbs-except
#
{
:bigquery
}
{
:rows
2
,
:unit
:day
}
(
date-bucketing-unit-when-you
:breakout-by
"day"
,
:filter-by
"day"
,
:with-interval
-2
))
(
expect-with-non-timeseries-dbs-except
#
{
:bigquery
}
{
:rows
2
,
:unit
:day
}
(
date-bucketing-unit-when-you
:breakout-by
"day"
,
:filter-by
"day"
,
:with-interval
2
))
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