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
031fc025
Unverified
Commit
031fc025
authored
1 year ago
by
metamben
Committed by
GitHub
1 year ago
Browse files
Options
Downloads
Patches
Plain Diff
Add filter-positions to filterable-columns (#34769)
parent
71641927
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/metabase/lib/filter.cljc
+31
-6
31 additions, 6 deletions
src/metabase/lib/filter.cljc
src/metabase/lib/metadata/calculation.cljc
+1
-1
1 addition, 1 deletion
src/metabase/lib/metadata/calculation.cljc
test/metabase/lib/filter_test.cljc
+40
-1
40 additions, 1 deletion
test/metabase/lib/filter_test.cljc
with
72 additions
and
8 deletions
src/metabase/lib/filter.cljc
+
31
−
6
View file @
031fc025
...
...
@@ -331,6 +331,14 @@
(
let
[
operators
(
lib.filter.operator/filter-operators
column
)]
(
m/assoc-some
column
:operators
(
clojure.core/not-empty
operators
))))
(
defn-
leading-ref
"Returns the first argument of `a-filter` if it is a reference clause, nil otherwise."
[
a-filter
]
(
when-let
[
leading-arg
(
clojure.core/and
(
lib.util/clause?
a-filter
)
(
get
a-filter
2
))]
(
when
(
lib.util/ref-clause?
leading-arg
)
leading-arg
)))
(
mu/defn
filterable-columns
:-
[
:sequential
ColumnWithOperators
]
"Get column metadata for all the columns that can be filtered in
the stage number `stage-number` of the query `query`
...
...
@@ -351,12 +359,29 @@
([
query
:-
::lib.schema/query
stage-number
:-
:int
]
(
let
[
stage
(
lib.util/query-stage
query
stage-number
)]
(
clojure.core/not-empty
(
into
[]
(
comp
(
map
add-column-operators
)
(
clojure.core/filter
:operators
))
(
lib.metadata.calculation/visible-columns
query
stage-number
stage
))))))
(
let
[
stage
(
lib.util/query-stage
query
stage-number
)
columns
(
sequence
(
comp
(
map
add-column-operators
)
(
clojure.core/filter
:operators
))
(
lib.metadata.calculation/visible-columns
query
stage-number
stage
))
existing-filters
(
filters
query
stage-number
)]
(
cond
(
empty?
columns
)
nil
(
empty?
existing-filters
)
(
vec
columns
)
:else
(
let
[
matching
(
group-by
(
fn
[
filter-pos
]
(
when-let
[
a-ref
(
leading-ref
(
get
existing-filters
filter-pos
))]
(
lib.equality/find-matching-column
query
stage-number
a-ref
columns
)))
(
range
(
count
existing-filters
)))]
(
mapv
#
(
let
[
positions
(
matching
%
)]
(
cond->
%
positions
(
assoc
:filter-positions
positions
)))
columns
))))))
(
mu/defn
filter-clause
:-
::lib.schema.expression/boolean
"Returns a standalone filter clause for a `filter-operator`,
...
...
This diff is collapsed.
Click to expand it.
src/metabase/lib/metadata/calculation.cljc
+
1
−
1
View file @
031fc025
...
...
@@ -359,7 +359,7 @@
:is-implicitly-joinable
(
=
source
:source/implicitly-joinable
)})
(
when-some
[
selected
(
:selected?
x-metadata
)]
{
:selected
selected
})
(
select-keys
x-metadata
[
:breakout-position
:order-by-position
]))))
(
select-keys
x-metadata
[
:breakout-position
:order-by-position
:filter-positions
]))))
(
defmethod
display-info-method
:default
[
query
stage-number
x
]
...
...
This diff is collapsed.
Click to expand it.
test/metabase/lib/filter_test.cljc
+
40
−
1
View file @
031fc025
...
...
@@ -215,7 +215,7 @@
[
:field
{
:lib/uuid
"be28f393-538a-406b-90da-bac5f8ef565e"
}
(
meta/id
:venues
:name
)]
"t"
])))
))
(
deftest
^
:parallel
filterable-columns
(
deftest
^
:parallel
filterable-columns
-test
(
let
[
query
(
->
(
lib/query
meta/metadata-provider
(
meta/table-metadata
:users
))
(
lib/join
(
->
(
lib/join-clause
(
meta/table-metadata
:checkins
)
[(
lib/=
...
...
@@ -670,3 +670,42 @@
:name
"Created At is Sep 1, 2022 – Oct 3, 2023"
}
{
:clause
[
:between
created-at
"2022-09-01T13:00:00"
"2023-10-03T01:00:00"
]
,
:name
"Created At is Sep 1, 2022, 1:00 PM – Oct 3, 2023, 1:00 AM"
}])))
(
deftest
^
:parallel
filter-positions-test
(
let
[
base
(
->
(
lib/query
meta/metadata-provider
(
meta/table-metadata
:orders
))
(
lib/expression
"expr"
(
lib/absolute-datetime
"2020"
:month
)))
base-cols
(
lib/breakoutable-columns
base
)
base-col
(
fn
[
col-name
]
(
m/find-first
#
(
=
(
:name
%
)
col-name
)
base-cols
))
query
(
->
base
(
lib/breakout
(
base-col
"ID"
))
(
lib/breakout
(
base-col
"expr"
))
(
lib/aggregate
(
lib/count
))
(
lib/aggregate
(
lib/max
(
base-col
"USER_ID"
)))
lib/append-stage
)
query-cols
(
lib/filterable-columns
query
)
query-col
(
fn
[
col-name
]
(
m/find-first
#
(
=
(
:name
%
)
col-name
)
query-cols
))
filtered-query
(
->
query
(
lib/filter
(
lib/not-null
(
query-col
"expr"
)))
(
lib/filter
(
lib/>=
(
query-col
"max"
)
7
))
(
lib/filter
(
lib/!=
(
query-col
"ID"
)
42
))
(
lib/filter
(
lib/<
(
query-col
"max"
)
17
)))
filtered-query-cols
(
lib/filterable-columns
filtered-query
)
signature-fn
(
juxt
:display-name
:filter-positions
)]
(
testing
"no filters"
(
is
(
=
[[
"ID"
nil
]
[
"expr"
nil
]
[
"Count"
nil
]
[
"Max of User ID"
nil
]]
(
map
signature-fn
query-cols
))))
(
testing
"with existing filter"
(
let
[
expected-signatures
[[
"ID"
[
2
]]
[
"expr"
[
0
]]
[
"Count"
nil
]
[
"Max of User ID"
[
1
3
]]]]
(
is
(
=
expected-signatures
(
map
signature-fn
filtered-query-cols
)))
(
testing
"display-info"
(
is
(
=
expected-signatures
(
map
(
comp
signature-fn
#
(
lib/display-info
filtered-query
%
))
filtered-query-cols
))))))))
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