Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
doodoocoder
prometheus
提交
51e8badc
P
prometheus
项目概览
doodoocoder
/
prometheus
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
prometheus
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
51e8badc
编写于
10月 16, 2015
作者:
F
Fabian Reinartz
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #1159 from prometheus/scalar-bool
promql: Remove scalar/scalar comparisons.
上级
e4229ea6
c3696113
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
33 addition
and
23 deletion
+33
-23
promql/lex.go
promql/lex.go
+11
-0
promql/parse.go
promql/parse.go
+8
-4
promql/parse_test.go
promql/parse_test.go
+14
-13
promql/testdata/comparison.test
promql/testdata/comparison.test
+0
-6
未找到文件。
promql/lex.go
浏览文件 @
51e8badc
...
...
@@ -60,6 +60,17 @@ func (i itemType) isAggregator() bool { return i > aggregatorsStart && i < aggre
// Returns false otherwise.
func
(
i
itemType
)
isKeyword
()
bool
{
return
i
>
keywordsStart
&&
i
<
keywordsEnd
}
// isCompairsonOperator returns true if the item corresponds to a comparison operator.
// Returns false otherwise.
func
(
i
itemType
)
isComparisonOperator
()
bool
{
switch
i
{
case
itemEQL
,
itemNEQ
,
itemLTE
,
itemLSS
,
itemGTE
,
itemGTR
:
return
true
default
:
return
false
}
}
// Constants for operator precedence in expressions.
//
const
LowestPrec
=
0
// Non-operators.
...
...
promql/parse.go
浏览文件 @
51e8badc
...
...
@@ -488,10 +488,7 @@ func (p *parser) expr() Expr {
returnBool
:=
false
// Parse bool modifier.
if
p
.
peek
()
.
typ
==
itemBool
{
switch
op
{
case
itemEQL
,
itemNEQ
,
itemLTE
,
itemLSS
,
itemGTE
,
itemGTR
:
break
default
:
if
!
op
.
isComparisonOperator
()
{
p
.
errorf
(
"bool modifier can only be used on comparison operators"
)
}
p
.
next
()
...
...
@@ -540,6 +537,9 @@ func (p *parser) expr() Expr {
},
VectorMatching
:
lhs
.
VectorMatching
,
}
if
op
.
isComparisonOperator
()
&&
!
returnBool
&&
rhs
.
Type
()
==
model
.
ValScalar
&&
lhs
.
RHS
.
Type
()
==
model
.
ValScalar
{
p
.
errorf
(
"comparisons between scalars must use BOOL modifier"
)
}
}
else
{
expr
=
&
BinaryExpr
{
Op
:
op
,
...
...
@@ -548,7 +548,11 @@ func (p *parser) expr() Expr {
VectorMatching
:
vecMatching
,
ReturnBool
:
returnBool
,
}
if
op
.
isComparisonOperator
()
&&
!
returnBool
&&
rhs
.
Type
()
==
model
.
ValScalar
&&
expr
.
Type
()
==
model
.
ValScalar
{
p
.
errorf
(
"comparisons between scalars must use BOOL modifier"
)
}
}
}
}
...
...
promql/parse_test.go
浏览文件 @
51e8badc
...
...
@@ -85,23 +85,20 @@ var testExpr = []struct {
input
:
"1 / 1"
,
expected
:
&
BinaryExpr
{
itemDIV
,
&
NumberLiteral
{
1
},
&
NumberLiteral
{
1
},
nil
,
false
},
},
{
input
:
"1 == 1"
,
expected
:
&
BinaryExpr
{
itemEQL
,
&
NumberLiteral
{
1
},
&
NumberLiteral
{
1
},
nil
,
fals
e
},
input
:
"1 ==
bool
1"
,
expected
:
&
BinaryExpr
{
itemEQL
,
&
NumberLiteral
{
1
},
&
NumberLiteral
{
1
},
nil
,
tru
e
},
},
{
input
:
"1 != 1"
,
expected
:
&
BinaryExpr
{
itemNEQ
,
&
NumberLiteral
{
1
},
&
NumberLiteral
{
1
},
nil
,
fals
e
},
input
:
"1 !=
bool
1"
,
expected
:
&
BinaryExpr
{
itemNEQ
,
&
NumberLiteral
{
1
},
&
NumberLiteral
{
1
},
nil
,
tru
e
},
},
{
input
:
"1 > 1"
,
expected
:
&
BinaryExpr
{
itemGTR
,
&
NumberLiteral
{
1
},
&
NumberLiteral
{
1
},
nil
,
fals
e
},
input
:
"1 >
bool
1"
,
expected
:
&
BinaryExpr
{
itemGTR
,
&
NumberLiteral
{
1
},
&
NumberLiteral
{
1
},
nil
,
tru
e
},
},
{
input
:
"1 >= 1"
,
expected
:
&
BinaryExpr
{
itemGTE
,
&
NumberLiteral
{
1
},
&
NumberLiteral
{
1
},
nil
,
fals
e
},
input
:
"1 >=
bool
1"
,
expected
:
&
BinaryExpr
{
itemGTE
,
&
NumberLiteral
{
1
},
&
NumberLiteral
{
1
},
nil
,
tru
e
},
},
{
input
:
"1 < 1"
,
expected
:
&
BinaryExpr
{
itemLSS
,
&
NumberLiteral
{
1
},
&
NumberLiteral
{
1
},
nil
,
false
},
},
{
input
:
"1 <= 1"
,
expected
:
&
BinaryExpr
{
itemLTE
,
&
NumberLiteral
{
1
},
&
NumberLiteral
{
1
},
nil
,
false
},
input
:
"1 < bool 1"
,
expected
:
&
BinaryExpr
{
itemLSS
,
&
NumberLiteral
{
1
},
&
NumberLiteral
{
1
},
nil
,
true
},
},
{
input
:
"1 <= bool 1"
,
expected
:
&
BinaryExpr
{
itemLTE
,
&
NumberLiteral
{
1
},
&
NumberLiteral
{
1
},
nil
,
true
},
...
...
@@ -203,6 +200,10 @@ var testExpr = []struct {
input
:
"1 and 1"
,
fail
:
true
,
errMsg
:
"AND and OR not allowed in binary scalar expression"
,
},
{
input
:
"1 == 1"
,
fail
:
true
,
errMsg
:
"parse error at char 7: comparisons between scalars must use BOOL modifier"
,
},
{
input
:
"1 or 1"
,
fail
:
true
,
...
...
promql/testdata/comparison.test
浏览文件 @
51e8badc
...
...
@@ -40,12 +40,6 @@ eval instant at 50m SUM(http_requests) BY (job) != bool SUM(http_requests) BY (j
{
job
=
"app-server"
}
0
eval
instant
at
50
m
0
==
1
0
eval
instant
at
50
m
1
==
1
1
eval
instant
at
50
m
0
==
bool
1
0
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录