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
d79096cc
Unverified
Commit
d79096cc
authored
8 years ago
by
Tom Robinson
Browse files
Options
Downloads
Patches
Plain Diff
Disable metrics and cleanup parser error messages
parent
f0a1c078
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/expressions/parser.js
+23
-10
23 additions, 10 deletions
frontend/src/metabase/lib/expressions/parser.js
frontend/src/metabase/lib/expressions/tokens.js
+5
-0
5 additions, 0 deletions
frontend/src/metabase/lib/expressions/tokens.js
with
28 additions
and
10 deletions
frontend/src/metabase/lib/expressions/parser.js
+
23
−
10
View file @
d79096cc
...
...
@@ -142,14 +142,18 @@ class ExpressionsParser extends Parser {
$
.
RULE
(
"
atomicExpression
"
,
(
outsideAggregation
)
=>
{
return
$
.
OR
([
// aggregations
and metrics
are not allowed inside other aggregations
// aggregations are not allowed inside other aggregations
{
GATE
:
()
=>
outsideAggregation
,
ALT
:
()
=>
$
.
SUBRULE
(
$
.
aggregationExpression
,
[
false
])
},
{
GATE
:
()
=>
outsideAggregation
,
ALT
:
()
=>
$
.
SUBRULE
(
$
.
metricExpression
)
},
// NOTE: DISABLE METRICS
// {GATE: () => outsideAggregation, ALT: () => $.SUBRULE($.metricExpression) },
// fields are not allowed outside aggregations
{
GATE
:
()
=>
!
outsideAggregation
,
ALT
:
()
=>
$
.
SUBRULE
(
$
.
fieldExpression
)
},
{
ALT
:
()
=>
$
.
SUBRULE
(
$
.
parenthesisExpression
,
[
outsideAggregation
])
},
{
ALT
:
()
=>
$
.
SUBRULE
(
$
.
numberLiteral
)
}
]);
]
,
(
outsideAggregation
?
"
aggregation
"
:
"
field name
"
)
+
"
, number, or expression
"
);
});
$
.
RULE
(
"
parenthesisExpression
"
,
(
outsideAggregation
)
=>
{
...
...
@@ -301,6 +305,14 @@ function run(Parser, source, options) {
const
parser
=
new
Parser
(
ExpressionsLexer
.
tokenize
(
source
).
tokens
,
options
);
const
expression
=
parser
[
startRule
]();
if
(
parser
.
errors
.
length
>
0
)
{
for
(
const
error
of
parser
.
errors
)
{
// clean up error messages
error
.
message
=
error
.
message
&&
error
.
message
.
replace
(
/^Expecting:
?\s
+/
,
"
Expected
"
)
.
replace
(
/-->
(
.*
?)
<--/g
,
"
$1
"
)
.
replace
(
/
(\n
|
\s)
*but found:
?
/
,
"
but found
"
)
.
replace
(
/
\s
*but found
\s
+''$/
,
""
);
}
throw
parser
.
errors
;
}
return
expression
;
...
...
@@ -417,13 +429,14 @@ export function suggest(source, {
postfixTrim
:
(
arity
>
0
?
/^
\w
+
(\(\)?
|$
)
/
:
/^
\w
+
\s
*/
)
};
}));
finalSuggestions
.
push
(...
tableMetadata
.
metrics
.
map
(
metric
=>
({
type
:
"
metrics
"
,
name
:
metric
.
name
,
text
:
formatMetricName
(
metric
),
prefixTrim
:
/
\w
+$/
,
postfixTrim
:
/^
\w
+
\s
*/
})))
// NOTE: DISABLE METRICS
// finalSuggestions.push(...tableMetadata.metrics.map(metric => ({
// type: "metrics",
// name: metric.name,
// text: formatMetricName(metric),
// prefixTrim: /\w+$/,
// postfixTrim: /^\w+\s*/
// })))
}
}
else
if
(
nextTokenType
===
NumberLiteral
)
{
// skip number literal
...
...
This diff is collapsed.
Click to expand it.
frontend/src/metabase/lib/expressions/tokens.js
+
5
−
0
View file @
d79096cc
...
...
@@ -49,8 +49,13 @@ export const NumberLiteral = extendToken("NumberLiteral", /-?(0|[1-9]\d*)(\.\d+)
export
const
StringLiteral
=
extendToken
(
"
StringLiteral
"
,
/"
(?:[^\\
"
]
+|
\\(?:[
bfnrtv"
\\/]
|u
[
0-9a-fA-F
]{4}))
*"/
);
export
const
Comma
=
extendToken
(
'
Comma
'
,
/,/
);
Comma
.
LABEL
=
"
comma
"
;
export
const
LParen
=
extendToken
(
'
LParen
'
,
/
\(
/
);
LParen
.
LABEL
=
"
opening parenthesis
"
;
export
const
RParen
=
extendToken
(
'
RParen
'
,
/
\)
/
);
RParen
.
LABEL
=
"
closing parenthesis
"
;
export
const
WhiteSpace
=
extendToken
(
"
WhiteSpace
"
,
/
\s
+/
);
WhiteSpace
.
GROUP
=
Lexer
.
SKIPPED
;
...
...
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