milvus/docs/design_docs/query_boolean_expr.md
groot 99f7c38513
[skip ci] Add note for design doc (#13235)
Signed-off-by: yhmo <yihua.mo@zilliz.com>
2021-12-13 11:05:28 +08:00

95 lines
1.9 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

```haskell
Expr :=
LogicalExpr | NIL
LogicalExpr :=
LogicalExpr BinaryLogicalOp LogicalExpr
| UnaryLogicalOp LogicalExpr
| "(" LogicalExpr ")"
| SingleExpr
BinaryLogicalOp :=
"&&" | "and"
| "||" | "or"
UnaryLogicalOp :=
"not"
SingleExpr :=
TermExpr
| CompareExpr
TermExpr :=
IDENTIFIER "in" ConstantArray
ConstantArray :=
"[" ConstantExpr { "," ConstantExpr } "]"
ConstantExpr :=
Constant
| ConstantExpr BinaryArithOp ConstantExpr
| UnaryArithOp ConstantExpr
Constant :=
INTERGER
| FLOAT_NUMBER
UnaryArithOp :=
"+"
| "-"
BinaryArithOp :=
"+"
| "-"
| "*"
| "/"
| "%"
| "**"
CompareExpr :=
IDENTIFIER CmpOp IDENTIFIER
| IDENTIFIER CmpOp ConstantExpr
| ConstantExpr CmpOp IDENTIFIER
| ConstantExpr CmpOpRestricted IDENTIFIER CmpOpRestricted ConstantExpr
CmpOpRestricted :=
"<"
| "<="
CmpOp :=
">"
| ">="
| "<"
| "<="
| "=="
| "!="
INTERGER := 整数
FLOAT_NUM := 浮点数
IDENTIFIER := 列名
```
Tips:
1. NIL represents an empty string, which means there is no Predicate for Expr.
2. Gramma is described by EBNF syntaxexpressions that may be omitted or repeated are represented through curly braces `{...}`.
After syntax analysis, the following rules will be applied:
1. non-vector column must exist in Schema.
2. CompareExpr/TermExpr requires operand type matching.
3. CompareExpr between non-vector columns of different types is available.
4. The modulo operation requires all operands to be integers.
5. Integer columns can only match integer operands. While float columns can match both integer and float operands.
6. In BinaryOp, the `and`/`&&` operator has higher priority than the `or`/`||` operator.
Example
```python
A > 3 && A < 4 && (C > 5 || D < 6)
1 < A <= 2.0 + 3 - 4 * 5 / 6 % 7 ** 8
A == B
FloatCol in [1.0, 2, 3.0]
Int64Col in [1, 2, 3] or C != 6
```