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
f752c84d
Unverified
Commit
f752c84d
authored
1 year ago
by
metamben
Committed by
GitHub
1 year ago
Browse files
Options
Downloads
Patches
Plain Diff
Generate correct reference for broken out expressions (#32993)
parent
f4cc36af
Loading
Loading
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/metabase/lib/expression.cljc
+7
-6
7 additions, 6 deletions
src/metabase/lib/expression.cljc
src/metabase/lib/field.cljc
+19
-7
19 additions, 7 deletions
src/metabase/lib/field.cljc
test/metabase/lib/order_by_test.cljc
+17
-1
17 additions, 1 deletion
test/metabase/lib/order_by_test.cljc
with
43 additions
and
14 deletions
src/metabase/lib/expression.cljc
+
7
−
6
View file @
f752c84d
...
...
@@ -55,12 +55,13 @@
(
defmethod
lib.metadata.calculation/metadata-method
:expression
[
query
stage-number
[
_expression
opts
expression-name,
:as
expression-ref-clause
]]
{
:lib/type
:metadata/column
:lib/source-uuid
(
:lib/uuid
opts
)
:name
expression-name
:display-name
(
lib.metadata.calculation/display-name
query
stage-number
expression-ref-clause
)
:base-type
(
lib.metadata.calculation/type-of
query
stage-number
expression-ref-clause
)
:lib/source
:source/expressions
})
{
:lib/type
:metadata/column
:lib/source-uuid
(
:lib/uuid
opts
)
:name
expression-name
:lib/expression-name
expression-name
:display-name
(
lib.metadata.calculation/display-name
query
stage-number
expression-ref-clause
)
:base-type
(
lib.metadata.calculation/type-of
query
stage-number
expression-ref-clause
)
:lib/source
:source/expressions
})
(
defmethod
lib.metadata.calculation/display-name-method
:dispatch-type/integer
[
_query
_stage-number
n
_style
]
...
...
This diff is collapsed.
Click to expand it.
src/metabase/lib/field.cljc
+
19
−
7
View file @
f752c84d
...
...
@@ -419,12 +419,9 @@
[
field-clause
]
field-clause
)
(
defmethod
lib.ref/ref-method
:metadata/column
[{
source
:lib/source,
:as
metadata
}]
(
case
source
:source/aggregations
(
lib.aggregation/column-metadata->aggregation-ref
metadata
)
:source/expressions
(
lib.expression/column-metadata->expression-ref
metadata
)
(
let
[
inherited-column?
(
#
{
:source/card
:source/native
:source/previous-stage
}
(
:lib/source
metadata
))
(
defn-
column-metadata->field-ref
[
metadata
]
(
let
[
inherited-column?
(
#
{
:source/card
:source/native
:source/previous-stage
}
(
:lib/source
metadata
))
options
(
merge
{
:lib/uuid
(
str
(
random-uuid
))
:base-type
(
:base-type
metadata
)
:effective-type
(
column-metadata-effective-type
metadata
)}
...
...
@@ -438,7 +435,22 @@
{
:source-field
source-field-id
}))]
[
:field
options
(
if
inherited-column?
(
or
(
:lib/desired-column-alias
metadata
)
(
:name
metadata
))
(
or
(
:id
metadata
)
(
:name
metadata
)))])))
(
or
(
:id
metadata
)
(
:name
metadata
)))]))
(
defmethod
lib.ref/ref-method
:metadata/column
[{
source
:lib/source,
:as
metadata
}]
(
case
source
:source/aggregations
(
lib.aggregation/column-metadata->aggregation-ref
metadata
)
:source/expressions
(
lib.expression/column-metadata->expression-ref
metadata
)
;; :source/breakouts hides the true origin of the column. Since it's impossible to
;; break out by aggregation references at the current stage, we only have to check
;; if we break out by an expression reference. :expression-name is only set for
;; expression references, so if it's set, we have to generate an expression ref,
;; otherwise we generate a normal field ref.
:source/breakouts
(
if
(
contains?
metadata
:lib/expression-name
)
(
lib.expression/column-metadata->expression-ref
metadata
)
(
column-metadata->field-ref
metadata
))
(
column-metadata->field-ref
metadata
)))
(
defn-
implicit-join-name
[
query
{
:keys
[
fk-field-id
table-id
]
,
:as
_field-metadata
}]
(
when
(
and
fk-field-id
table-id
)
...
...
This diff is collapsed.
Click to expand it.
test/metabase/lib/order_by_test.cljc
+
17
−
1
View file @
f752c84d
(
ns
metabase.lib.order-by-test
(
:require
[
clojure.test
:refer
[
deftest
is
testing
]]
[
clojure.test
:refer
[
are
deftest
is
testing
]]
[
medley.core
:as
m
]
[
metabase.lib.convert
:as
lib.convert
]
[
metabase.lib.core
:as
lib
]
...
...
@@ -163,6 +163,22 @@
:lib/source
:source/breakouts
}]
(
lib/orderable-columns
query
)))))))
(
deftest
^
:parallel
order-by-breakout-expression-test
(
testing
"order-by with a broken out expression has correct reference (#32845)"
(
let
[
query
(
lib/expression
lib.tu/venues-query
"Category ID + 1"
(
lib/+
(
meta/field-metadata
:venues
:category-id
)
1
))
breakout-col
(
m/find-first
#
(
=
(
:lib/source
%
)
:source/expressions
)
(
lib/breakoutable-columns
query
0
))
query
(
lib/breakout
query
breakout-col
)]
(
are
[
query
]
(
=?
[
:desc
{}
[
:expression
{
:base-type
:type/Integer,
:effective-type
:type/Integer
}
"Category ID + 1"
]]
(
get-in
(
lib/order-by
query
0
(
first
(
lib/orderable-columns
query
0
))
:desc
)
[
:stages
0
:order-by
0
]))
query
(
lib/append-stage
query
)))))
(
deftest
^
:parallel
orderable-columns-test
(
let
[
query
lib.tu/venues-query
]
(
testing
(
lib.util/format
"Query =\n%s"
(
u/pprint-to-str
query
))
...
...
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