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
f47eafd3
Unverified
Commit
f47eafd3
authored
5 months ago
by
metamben
Committed by
GitHub
5 months ago
Browse files
Options
Downloads
Patches
Plain Diff
Support resolving names in source-metadata by ID (#48765)
Fixes #48639
parent
004848ae
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/metabase/query_processor/util/add_alias_info.clj
+7
-3
7 additions, 3 deletions
src/metabase/query_processor/util/add_alias_info.clj
test/metabase/query_processor_test/model_test.clj
+67
-0
67 additions, 0 deletions
test/metabase/query_processor_test/model_test.clj
with
74 additions
and
3 deletions
src/metabase/query_processor/util/add_alias_info.clj
+
7
−
3
View file @
f47eafd3
...
...
@@ -230,9 +230,13 @@
;; if still no match try looking based for a matching Field based on ID.
(
let
[[
_field
id-or-name
_opts
]
field-clause
]
(
when
(
integer?
id-or-name
)
(
m/find-first
(
fn
[[
_field
an-id-or-name
_opts
]]
(
=
an-id-or-name
id-or-name
))
field-exports
)))
(
or
(
m/find-first
(
fn
[[
_field
an-id-or-name
_opts
]]
(
=
an-id-or-name
id-or-name
))
field-exports
)
;; look for a field referenced by the ID in source-metadata
(
when-let
[
column
(
m/find-first
#
(
=
(
:id
%
)
id-or-name
)
source-metadata
)]
(
let
[
signature
(
field-signature
(
:field_ref
column
))]
(
m/find-first
#
(
=
(
field-signature
%
)
signature
)
field-exports
))))))
;; otherwise if this is a nominal field literal ref then look for matches based on the string name used
(
when-let
[
field-name
(
let
[[
_
id-or-name
]
field-clause
]
(
when
(
string?
id-or-name
)
...
...
This diff is collapsed.
Click to expand it.
test/metabase/query_processor_test/model_test.clj
0 → 100644
+
67
−
0
View file @
f47eafd3
(
ns
metabase.query-processor-test.model-test
(
:require
[
clojure.test
:refer
[
deftest
is
testing
]]
[
medley.core
:as
m
]
[
metabase.lib.convert
:as
lib.convert
]
[
metabase.lib.core
:as
lib
]
[
metabase.lib.metadata
:as
lib.metadata
]
[
metabase.lib.metadata.jvm
:as
lib.metadata.jvm
]
[
metabase.query-processor
:as
qp
]
[
metabase.test
:as
mt
]))
(
deftest
^
:parallel
model-self-join-test
(
testing
"Field references from model joined a second time can be resolved (#48639)"
(
let
[
mp
(
lib.metadata.jvm/application-database-metadata-provider
(
mt/id
))]
(
mt/with-temp
[
:model/Card
base-model
{
:dataset_query
(
->
(
lib/query
mp
(
lib.metadata/table
mp
(
mt/id
:products
)))
(
lib/join
(
->
(
lib/join-clause
(
lib.metadata/table
mp
(
mt/id
:reviews
))
[(
lib/=
(
lib.metadata/field
mp
(
mt/id
:products
:id
))
(
lib.metadata/field
mp
(
mt/id
:reviews
:product_id
)))])
(
lib/with-join-fields
:all
)))
lib.convert/->legacy-MBQL
)
:database_id
(
mt/id
)
:name
"Products+Reviews"
:type
:model
}
:model/Card
consumer-model
{
:dataset_query
(
as->
(
lib/query
mp
(
lib.metadata/card
mp
(
:id
base-model
)))
$q
(
lib/aggregate
$q
(
lib/sum
(
->>
$q
lib/available-aggregation-operators
(
m/find-first
(
comp
#
{
:sum
}
:short
))
:columns
(
m/find-first
(
comp
#
{
"Price"
}
:display-name
)))))
(
lib/breakout
$q
(
->
(
m/find-first
(
comp
#
{
"Reviews → Created At"
}
:display-name
)
(
lib/breakoutable-columns
$q
))
(
lib/with-temporal-bucket
:month
))))
:database_id
(
mt/id
)
:name
"Products+Reviews Summary"
:type
:model
}]
(
let
[
question
(
as->
(
lib/query
mp
(
lib.metadata/card
mp
(
:id
base-model
)))
$q
(
lib/breakout
$q
(
->
(
m/find-first
(
comp
#
{
"Reviews → Created At"
}
:display-name
)
(
lib/breakoutable-columns
$q
))
(
lib/with-temporal-bucket
:month
)))
(
lib/aggregate
$q
(
lib/avg
(
->>
$q
lib/available-aggregation-operators
(
m/find-first
(
comp
#
{
:avg
}
:short
))
:columns
(
m/find-first
(
comp
#
{
"Rating"
}
:display-name
)))))
(
lib/append-stage
$q
)
(
lib/join
$q
(
->
(
lib/join-clause
(
lib.metadata/card
mp
(
:id
consumer-model
))
[(
lib/=
(
->
(
m/find-first
(
comp
#
{
"Reviews → Created At: Month"
}
:display-name
)
(
lib/breakoutable-columns
$q
))
(
lib/with-temporal-bucket
:month
))
(
->
(
m/find-first
(
comp
#
{
"Reviews → Created At"
}
:display-name
)
(
lib/breakoutable-columns
(
lib/query
mp
(
lib.metadata/card
mp
(
:id
consumer-model
)))))
(
lib/with-temporal-bucket
:month
)))])
(
lib/with-join-fields
:all
))))]
(
is
(
=
[
"Reviews → Created At"
"Average of Rating"
"Products+Reviews Summary - Reviews → Created At: Month → Created At"
"Products+Reviews Summary - Reviews → Created At: Month → Sum"
]
(
->>
(
qp/process-query
question
)
mt/cols
(
mapv
:display_name
)))))))))
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