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
4a4ad7d4
Unverified
Commit
4a4ad7d4
authored
8 years ago
by
Tom Robinson
Browse files
Options
Downloads
Patches
Plain Diff
misc aggs fixes/cleanup
parent
2e5aae6f
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
frontend/src/metabase/lib/query.js
+15
-16
15 additions, 16 deletions
frontend/src/metabase/lib/query.js
frontend/src/metabase/query_builder/components/AggregationWidget.jsx
+7
-3
7 additions, 3 deletions
...c/metabase/query_builder/components/AggregationWidget.jsx
with
22 additions
and
19 deletions
frontend/src/metabase/lib/query.js
+
15
−
16
View file @
4a4ad7d4
...
...
@@ -10,6 +10,7 @@ import { isFK, TYPE } from "metabase/lib/types";
import
*
as
Q
from
"
./query/query
"
;
import
{
mbql
,
mbqlEq
}
from
"
./query/util
"
;
export
const
NEW_QUERY_TEMPLATES
=
{
query
:
{
...
...
@@ -67,8 +68,6 @@ const METRIC_TYPE_BY_AGGREGATION = {
const
SORTABLE_AGGREGATION_TYPES
=
new
Set
([
"
avg
"
,
"
count
"
,
"
distinct
"
,
"
stddev
"
,
"
sum
"
,
"
min
"
,
"
max
"
]);
const
mbqlCanonicalize
=
(
a
)
=>
typeof
a
===
"
string
"
?
a
.
toLowerCase
().
replace
(
/_/g
,
"
-
"
)
:
a
;
const
mbqlCompare
=
(
a
,
b
)
=>
mbqlCanonicalize
(
a
)
===
mbqlCanonicalize
(
b
)
var
Query
=
{
...
...
@@ -93,7 +92,7 @@ var Query = {
}
}
else
{
for
(
const
[
agg
]
of
aggs
)
{
if
(
!
mbql
Compare
(
agg
,
"
metric
"
)
&&
!
_
.
findWhere
(
tableMetadata
.
aggregation_options
,
{
short
:
agg
}))
{
if
(
!
mbql
Eq
(
agg
,
"
metric
"
)
&&
!
_
.
findWhere
(
tableMetadata
.
aggregation_options
,
{
short
:
agg
}))
{
// return false;
}
}
...
...
@@ -211,7 +210,7 @@ var Query = {
const
aggregations
=
Query
.
getAggregations
(
query
);
return
(
aggregations
[
index
]
&&
aggregations
[
index
][
0
]
&&
SORTABLE_AGGREGATION_TYPES
.
has
(
mbql
Canonicalize
(
aggregations
[
index
][
0
]))
SORTABLE_AGGREGATION_TYPES
.
has
(
mbql
(
aggregations
[
index
][
0
]))
);
},
...
...
@@ -310,23 +309,23 @@ var Query = {
},
isLocalField
(
field
)
{
return
Array
.
isArray
(
field
)
&&
mbql
Compare
(
field
[
0
],
"
field-id
"
);
return
Array
.
isArray
(
field
)
&&
mbql
Eq
(
field
[
0
],
"
field-id
"
);
},
isForeignKeyField
(
field
)
{
return
Array
.
isArray
(
field
)
&&
mbql
Compare
(
field
[
0
],
"
fk->
"
);
return
Array
.
isArray
(
field
)
&&
mbql
Eq
(
field
[
0
],
"
fk->
"
);
},
isDatetimeField
(
field
)
{
return
Array
.
isArray
(
field
)
&&
mbql
Compare
(
field
[
0
],
"
datetime-field
"
);
return
Array
.
isArray
(
field
)
&&
mbql
Eq
(
field
[
0
],
"
datetime-field
"
);
},
isExpressionField
(
field
)
{
return
Array
.
isArray
(
field
)
&&
field
.
length
===
2
&&
mbql
Compare
(
field
[
0
],
"
expression
"
);
return
Array
.
isArray
(
field
)
&&
field
.
length
===
2
&&
mbql
Eq
(
field
[
0
],
"
expression
"
);
},
isAggregateField
(
field
)
{
return
Array
.
isArray
(
field
)
&&
mbql
Compare
(
field
[
0
],
"
aggregation
"
);
return
Array
.
isArray
(
field
)
&&
mbql
Eq
(
field
[
0
],
"
aggregation
"
);
},
isValidField
(
field
)
{
...
...
@@ -634,21 +633,21 @@ export const AggregationClause = {
// predicate function to test if the given aggregation clause represents a Bare Rows aggregation
isBareRows
(
aggregation
)
{
return
AggregationClause
.
isValid
(
aggregation
)
&&
aggregation
[
0
]
===
"
rows
"
;
return
AggregationClause
.
isValid
(
aggregation
)
&&
mbqlEq
(
aggregation
[
0
]
,
"
rows
"
)
;
},
// predicate function to test if a given aggregation clause represents a standard aggregation
isStandard
(
aggregation
)
{
return
AggregationClause
.
isValid
(
aggregation
)
&&
aggregation
[
0
]
!==
"
METRIC
"
;
return
AggregationClause
.
isValid
(
aggregation
)
&&
!
mbqlEq
(
aggregation
[
0
]
,
"
metric
"
)
;
},
getAggregation
(
aggregation
)
{
return
aggregation
&&
mbql
Canonicalize
(
aggregation
[
0
]);
return
aggregation
&&
mbql
(
aggregation
[
0
]);
},
// predicate function to test if a given aggregation clause represents a metric
isMetric
(
aggregation
)
{
return
AggregationClause
.
isValid
(
aggregation
)
&&
aggregation
[
0
]
===
"
METRIC
"
;
return
AggregationClause
.
isValid
(
aggregation
)
&&
mbqlEq
(
aggregation
[
0
]
,
"
metric
"
)
;
},
// get the metricId from a metric aggregation clause
...
...
@@ -662,13 +661,13 @@ export const AggregationClause = {
isCustom
(
aggregation
)
{
return
aggregation
&&
isMath
(
aggregation
)
||
(
!
AggregationClause
.
isStandard
(
aggregation
)
&&
_
.
any
(
aggregation
.
slice
(
1
),
(
arg
)
=>
isMath
(
arg
))
AggregationClause
.
isStandard
(
aggregation
)
&&
_
.
any
(
aggregation
.
slice
(
1
),
(
arg
)
=>
isMath
(
arg
))
);
},
// get the operator from a standard aggregation clause
getOperator
(
aggregation
)
{
if
(
aggregation
&&
aggregation
.
length
>
0
&&
aggregation
[
0
]
!==
"
METRIC
"
)
{
if
(
aggregation
&&
aggregation
.
length
>
0
&&
!
mbqlEq
(
aggregation
[
0
]
,
"
metric
"
)
)
{
return
aggregation
[
0
];
}
else
{
return
null
;
...
...
@@ -677,7 +676,7 @@ export const AggregationClause = {
// get the fieldId from a standard aggregation clause
getField
(
aggregation
)
{
if
(
aggregation
&&
aggregation
.
length
>
1
&&
aggregation
[
0
]
!==
"
METRIC
"
)
{
if
(
aggregation
&&
aggregation
.
length
>
1
&&
!
mbqlEq
(
aggregation
[
0
]
,
"
metric
"
)
)
{
return
aggregation
[
1
];
}
else
{
return
null
;
...
...
This diff is collapsed.
Click to expand it.
frontend/src/metabase/query_builder/components/AggregationWidget.jsx
+
7
−
3
View file @
4a4ad7d4
...
...
@@ -57,11 +57,15 @@ export default class AggregationWidget extends Component {
}
return
(
<
span
className
=
"View-section-aggregation QueryOption py1 mx1 flex align-center"
>
{
selectedAggregation
?
selectedAggregation
.
name
.
replace
(
"
of ...
"
,
""
)
:
"
Choose an aggregation
"
}
{
aggregation
.
length
>
1
&&
{
selectedAggregation
?
selectedAggregation
.
name
.
replace
(
"
of ...
"
,
""
)
:
"
Choose an aggregation
"
}
{
selectedAggregation
&&
fieldId
&&
<
span
style
=
{
{
paddingRight
:
"
4px
"
,
paddingLeft
:
"
4px
"
}
}
className
=
"text-bold"
>
of
</
span
>
}
{
a
ggregation
.
length
>
1
&&
{
selectedA
ggregation
&&
fieldId
&&
<
FieldName
className
=
"View-section-aggregation-target SelectionModule py1"
tableMetadata
=
{
tableMetadata
}
...
...
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