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
d96ff955
Commit
d96ff955
authored
6 years ago
by
Simon Belak
Browse files
Options
Downloads
Patches
Plain Diff
Correctly handle empty table lists in `enhance-table-stats`
parent
4b15f5d7
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/metabase/automagic_dashboards/core.clj
+32
-29
32 additions, 29 deletions
src/metabase/automagic_dashboards/core.clj
with
32 additions
and
29 deletions
src/metabase/automagic_dashboards/core.clj
+
32
−
29
View file @
d96ff955
...
...
@@ -861,35 +861,38 @@
(
defn-
enhance-table-stats
[
tables
]
(
let
[
field-count
(
->>
(
db/query
{
:select
[
:table_id
[
:%count.*
"count"
]]
:from
[
:metabase_field
]
:where
[
:in
:table_id
(
map
u/get-id
tables
)]
:group-by
[
:table_id
]})
(
into
{}
(
map
(
fn
[{
:keys
[
count
table_id
]}]
[
table_id
count
]))))
list-like?
(
->>
(
db/query
{
:select
[
:table_id
[
:%count.*
"count"
]]
:from
[
:metabase_field
]
:where
[
:and
[
:in
:table_id
(
->>
field-count
(
filter
(
comp
#
{
2
}
val
))
(
map
key
))]
[
:or
[
:not=
:special_type
"type/PK"
]
[
:=
:special_type
nil
]]]
:group-by
[
:table_id
]
:having
[
:=
:count
1
]})
(
into
#
{}
(
map
:table_id
)))
link-table?
(
->>
(
db/query
{
:select
[
:table_id
[
:%count.*
"count"
]]
:from
[
:metabase_field
]
:where
[
:and
[
:in
:table_id
(
keys
field-count
)]
[
:in
:special_type
[
"type/PK"
"type/FK"
]]]
:group-by
[
:table_id
]})
(
filter
(
fn
[{
:keys
[
table_id
count
]}]
(
=
count
(
field-count
table_id
))))
(
into
#
{}
(
map
:table_id
)))]
(
for
[
table
tables
]
(
let
[
table-id
(
u/get-id
table
)]
(
assoc
table
:stats
{
:num-fields
(
field-count
table-id
0
)
:list-like?
(
boolean
(
list-like?
table-id
))
:link-table?
(
boolean
(
link-table?
table-id
))})))))
(
when
(
not-empty
tables
)
(
let
[
field-count
(
->>
(
db/query
{
:select
[
:table_id
[
:%count.*
"count"
]]
:from
[
:metabase_field
]
:where
[
:in
:table_id
(
map
u/get-id
tables
)]
:group-by
[
:table_id
]})
(
into
{}
(
map
(
fn
[{
:keys
[
count
table_id
]}]
[
table_id
count
]))))
list-like?
(
->>
(
when-let
[
candidates
(
->>
field-count
(
filter
(
comp
(
partial
>=
2
)
val
))
(
map
key
)
not-empty
)]
(
db/query
{
:select
[
:table_id
[
:%count.*
"count"
]]
:from
[
:metabase_field
]
:where
[
:and
[
:in
:table_id
]
[
:or
[
:not=
:special_type
"type/PK"
]
[
:=
:special_type
nil
]]]
:group-by
[
:table_id
]
:having
[
:=
:count
1
]}))
(
into
#
{}
(
map
:table_id
)))
link-table?
(
->>
(
db/query
{
:select
[
:table_id
[
:%count.*
"count"
]]
:from
[
:metabase_field
]
:where
[
:and
[
:in
:table_id
(
keys
field-count
)]
[
:in
:special_type
[
"type/PK"
"type/FK"
]]]
:group-by
[
:table_id
]})
(
filter
(
fn
[{
:keys
[
table_id
count
]}]
(
=
count
(
field-count
table_id
))))
(
into
#
{}
(
map
:table_id
)))]
(
for
[
table
tables
]
(
let
[
table-id
(
u/get-id
table
)]
(
assoc
table
:stats
{
:num-fields
(
field-count
table-id
0
)
:list-like?
(
boolean
(
list-like?
table-id
))
:link-table?
(
boolean
(
link-table?
table-id
))}))))))
(
def
^
:private
^
:const
^
Long
max-candidate-tables
"Maximal number of tables per schema shown in `candidate-tables`."
...
...
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