|
|
@@ -31,7 +31,23 @@ func (c AndCondition) Match(row []byte, table *Table) bool {
|
|
|
return true
|
|
|
}
|
|
|
|
|
|
-type EqCondition struct {
|
|
|
+// CmpOp 比较算子: CmpCondition 的一次单行比较取什么方向。
|
|
|
+// Eq/Gt/Ge/Lt/Le 五个构造函数各填一个值; 索引规划 (classifyLeaf) 与行级过滤
|
|
|
+// (CmpCondition.Match → compareOp) 都按它分派。
|
|
|
+type CmpOp byte
|
|
|
+
|
|
|
+const (
|
|
|
+ OpEq CmpOp = iota // =
|
|
|
+ OpGt // >
|
|
|
+ OpGe // >=
|
|
|
+ OpLt // <
|
|
|
+ OpLe // <=
|
|
|
+)
|
|
|
+
|
|
|
+// CmpCondition 五种单值比较 (=, >, >=, <, <=) 的统一实现。
|
|
|
+// 原 EqCondition/GtCondition/GeCondition/LtCondition/LeCondition 五个导出类型
|
|
|
+// 已合并为本类型; Eq/Gt/Ge/Lt/Le 构造函数签名不变, 仍是构造条件的唯一入口。
|
|
|
+type CmpCondition struct {
|
|
|
Field string
|
|
|
Value interface{}
|
|
|
|
|
|
@@ -39,6 +55,9 @@ type EqCondition struct {
|
|
|
// (见 Table.compareColTypeFor)。它只剩"值怎么从 interface{} 取出"的提示作用,
|
|
|
// 传任何值结果都一样; 保留仅为兼容既有调用方, 新代码传 0 即可。
|
|
|
Type types.FieldType
|
|
|
+
|
|
|
+ // Op 比较方向, 由 Eq/Gt/Ge/Lt/Le 构造函数填入。
|
|
|
+ Op CmpOp
|
|
|
}
|
|
|
|
|
|
// Eq 构造 "field = value" 条件。
|
|
|
@@ -48,98 +67,38 @@ type EqCondition struct {
|
|
|
// 上面刻意不写成 "Deprecated:" 段落 —— Go 只能标记整个标识符废弃, 写了会把本函数
|
|
|
// 一起判为废弃, 而本函数还要继续用。
|
|
|
func Eq(field string, value interface{}, typ types.FieldType) Condition {
|
|
|
- return EqCondition{Field: field, Value: value, Type: typ}
|
|
|
+ return CmpCondition{Field: field, Value: value, Type: typ, Op: OpEq}
|
|
|
}
|
|
|
|
|
|
-func (c EqCondition) Fields() []string {
|
|
|
- return []string{c.Field}
|
|
|
-}
|
|
|
-
|
|
|
-func (c EqCondition) Match(row []byte, table *Table) bool {
|
|
|
- fieldIdx := table.findFieldIndex(c.Field)
|
|
|
- if fieldIdx < 0 {
|
|
|
- return false
|
|
|
- }
|
|
|
- // 比较类型与列级参数一律取列的实际定义 (声明类型已废弃), 与索引路径编键同源。
|
|
|
- ct := table.compareColTypeFor(fieldIdx)
|
|
|
- // 定位列并把行内【实际长度】的字节补齐到档位宽度 (v9 行是变长的, 条件值仍按档位编码)。
|
|
|
- seg, ok := table.rowFieldForCompare(row, fieldIdx, ct)
|
|
|
- if !ok {
|
|
|
- return false
|
|
|
- }
|
|
|
- return table.compareValue(seg, ct, c.Value)
|
|
|
-}
|
|
|
-
|
|
|
-type GeCondition struct {
|
|
|
- Field string
|
|
|
- Value interface{}
|
|
|
-
|
|
|
- // Deprecated: 已不参与比较 —— 行级过滤与索引路径都按【列的实际存储类型】编字节
|
|
|
- // (见 Table.compareColTypeFor)。它只剩"值怎么从 interface{} 取出"的提示作用,
|
|
|
- // 传任何值结果都一样; 保留仅为兼容既有调用方, 新代码传 0 即可。
|
|
|
- Type types.FieldType
|
|
|
+// Gt 构造 "field > value" 条件。第三个参数 typ 的废弃说明见 Eq。
|
|
|
+func Gt(field string, value interface{}, typ types.FieldType) Condition {
|
|
|
+ return CmpCondition{Field: field, Value: value, Type: typ, Op: OpGt}
|
|
|
}
|
|
|
|
|
|
-// Ge 构造 "field >= value" 条件。
|
|
|
-//
|
|
|
-// 第三个参数 typ 已废弃: 比较一律按列的实际存储类型进行 (见 Table.compareColTypeFor),
|
|
|
-// 它取任何值结果都一样, 传 types.FieldType(0) 即可。
|
|
|
-// 上面刻意不写成 "Deprecated:" 段落 —— Go 只能标记整个标识符废弃, 写了会把本函数
|
|
|
-// 一起判为废弃, 而本函数还要继续用。
|
|
|
+// Ge 构造 "field >= value" 条件。第三个参数 typ 的废弃说明见 Eq。
|
|
|
func Ge(field string, value interface{}, typ types.FieldType) Condition {
|
|
|
- return GeCondition{Field: field, Value: value, Type: typ}
|
|
|
-}
|
|
|
-
|
|
|
-func (c GeCondition) Fields() []string {
|
|
|
- return []string{c.Field}
|
|
|
+ return CmpCondition{Field: field, Value: value, Type: typ, Op: OpGe}
|
|
|
}
|
|
|
|
|
|
-func (c GeCondition) Match(row []byte, table *Table) bool {
|
|
|
- fieldIdx := table.findFieldIndex(c.Field)
|
|
|
- if fieldIdx < 0 {
|
|
|
- return false
|
|
|
- }
|
|
|
-
|
|
|
- // 比较类型与列级参数一律取列的实际定义 (声明类型已废弃), 与索引路径编键同源。
|
|
|
- ct := table.compareColTypeFor(fieldIdx)
|
|
|
- // 定位列并把行内【实际长度】的字节补齐到档位宽度 (v9 行是变长的, 条件值仍按档位编码)。
|
|
|
- seg, ok := table.rowFieldForCompare(row, fieldIdx, ct)
|
|
|
- if !ok {
|
|
|
- return false
|
|
|
- }
|
|
|
- return table.compareGreaterOrEqual(seg, ct, c.Value)
|
|
|
-}
|
|
|
-
|
|
|
-type GtCondition struct {
|
|
|
- Field string
|
|
|
- Value interface{}
|
|
|
-
|
|
|
- // Deprecated: 已不参与比较 —— 行级过滤与索引路径都按【列的实际存储类型】编字节
|
|
|
- // (见 Table.compareColTypeFor)。它只剩"值怎么从 interface{} 取出"的提示作用,
|
|
|
- // 传任何值结果都一样; 保留仅为兼容既有调用方, 新代码传 0 即可。
|
|
|
- Type types.FieldType
|
|
|
+// Lt 构造 "field < value" 条件。第三个参数 typ 的废弃说明见 Eq。
|
|
|
+func Lt(field string, value interface{}, typ types.FieldType) Condition {
|
|
|
+ return CmpCondition{Field: field, Value: value, Type: typ, Op: OpLt}
|
|
|
}
|
|
|
|
|
|
-// Gt 构造 "field > value" 条件。
|
|
|
-//
|
|
|
-// 第三个参数 typ 已废弃: 比较一律按列的实际存储类型进行 (见 Table.compareColTypeFor),
|
|
|
-// 它取任何值结果都一样, 传 types.FieldType(0) 即可。
|
|
|
-// 上面刻意不写成 "Deprecated:" 段落 —— Go 只能标记整个标识符废弃, 写了会把本函数
|
|
|
-// 一起判为废弃, 而本函数还要继续用。
|
|
|
-func Gt(field string, value interface{}, typ types.FieldType) Condition {
|
|
|
- return GtCondition{Field: field, Value: value, Type: typ}
|
|
|
+// Le 构造 "field <= value" 条件。第三个参数 typ 的废弃说明见 Eq。
|
|
|
+func Le(field string, value interface{}, typ types.FieldType) Condition {
|
|
|
+ return CmpCondition{Field: field, Value: value, Type: typ, Op: OpLe}
|
|
|
}
|
|
|
|
|
|
-func (c GtCondition) Fields() []string {
|
|
|
+func (c CmpCondition) Fields() []string {
|
|
|
return []string{c.Field}
|
|
|
}
|
|
|
|
|
|
-func (c GtCondition) Match(row []byte, table *Table) bool {
|
|
|
+func (c CmpCondition) Match(row []byte, table *Table) bool {
|
|
|
fieldIdx := table.findFieldIndex(c.Field)
|
|
|
if fieldIdx < 0 {
|
|
|
return false
|
|
|
}
|
|
|
-
|
|
|
// 比较类型与列级参数一律取列的实际定义 (声明类型已废弃), 与索引路径编键同源。
|
|
|
ct := table.compareColTypeFor(fieldIdx)
|
|
|
// 定位列并把行内【实际长度】的字节补齐到档位宽度 (v9 行是变长的, 条件值仍按档位编码)。
|
|
|
@@ -147,7 +106,7 @@ func (c GtCondition) Match(row []byte, table *Table) bool {
|
|
|
if !ok {
|
|
|
return false
|
|
|
}
|
|
|
- return table.compareGreater(seg, ct, c.Value)
|
|
|
+ return table.compareOp(seg, ct, c.Value, c.Op)
|
|
|
}
|
|
|
|
|
|
type InCondition struct {
|
|
|
@@ -188,52 +147,13 @@ func (c InCondition) Match(row []byte, table *Table) bool {
|
|
|
return false
|
|
|
}
|
|
|
for _, value := range c.Values {
|
|
|
- if table.compareValue(seg, ct, value) {
|
|
|
+ if table.compareOp(seg, ct, value, OpEq) {
|
|
|
return true
|
|
|
}
|
|
|
}
|
|
|
return false
|
|
|
}
|
|
|
|
|
|
-type LeCondition struct {
|
|
|
- Field string
|
|
|
- Value interface{}
|
|
|
-
|
|
|
- // Deprecated: 已不参与比较 —— 行级过滤与索引路径都按【列的实际存储类型】编字节
|
|
|
- // (见 Table.compareColTypeFor)。它只剩"值怎么从 interface{} 取出"的提示作用,
|
|
|
- // 传任何值结果都一样; 保留仅为兼容既有调用方, 新代码传 0 即可。
|
|
|
- Type types.FieldType
|
|
|
-}
|
|
|
-
|
|
|
-// Le 构造 "field <= value" 条件。
|
|
|
-//
|
|
|
-// 第三个参数 typ 已废弃: 比较一律按列的实际存储类型进行 (见 Table.compareColTypeFor),
|
|
|
-// 它取任何值结果都一样, 传 types.FieldType(0) 即可。
|
|
|
-// 上面刻意不写成 "Deprecated:" 段落 —— Go 只能标记整个标识符废弃, 写了会把本函数
|
|
|
-// 一起判为废弃, 而本函数还要继续用。
|
|
|
-func Le(field string, value interface{}, typ types.FieldType) Condition {
|
|
|
- return LeCondition{Field: field, Value: value, Type: typ}
|
|
|
-}
|
|
|
-
|
|
|
-func (c LeCondition) Fields() []string {
|
|
|
- return []string{c.Field}
|
|
|
-}
|
|
|
-
|
|
|
-func (c LeCondition) Match(row []byte, table *Table) bool {
|
|
|
- fieldIdx := table.findFieldIndex(c.Field)
|
|
|
- if fieldIdx < 0 {
|
|
|
- return false
|
|
|
- }
|
|
|
- // 比较类型与列级参数一律取列的实际定义 (声明类型已废弃), 与索引路径编键同源。
|
|
|
- ct := table.compareColTypeFor(fieldIdx)
|
|
|
- // 定位列并把行内【实际长度】的字节补齐到档位宽度 (v9 行是变长的, 条件值仍按档位编码)。
|
|
|
- seg, ok := table.rowFieldForCompare(row, fieldIdx, ct)
|
|
|
- if !ok {
|
|
|
- return false
|
|
|
- }
|
|
|
- return table.compareLessOrEqual(seg, ct, c.Value)
|
|
|
-}
|
|
|
-
|
|
|
type LikeCondition struct {
|
|
|
Field string
|
|
|
Pattern string
|
|
|
@@ -325,46 +245,6 @@ func likeMatch(str, pattern string) bool {
|
|
|
return true
|
|
|
}
|
|
|
|
|
|
-type LtCondition struct {
|
|
|
- Field string
|
|
|
- Value interface{}
|
|
|
-
|
|
|
- // Deprecated: 已不参与比较 —— 行级过滤与索引路径都按【列的实际存储类型】编字节
|
|
|
- // (见 Table.compareColTypeFor)。它只剩"值怎么从 interface{} 取出"的提示作用,
|
|
|
- // 传任何值结果都一样; 保留仅为兼容既有调用方, 新代码传 0 即可。
|
|
|
- Type types.FieldType
|
|
|
-}
|
|
|
-
|
|
|
-// Lt 构造 "field < value" 条件。
|
|
|
-//
|
|
|
-// 第三个参数 typ 已废弃: 比较一律按列的实际存储类型进行 (见 Table.compareColTypeFor),
|
|
|
-// 它取任何值结果都一样, 传 types.FieldType(0) 即可。
|
|
|
-// 上面刻意不写成 "Deprecated:" 段落 —— Go 只能标记整个标识符废弃, 写了会把本函数
|
|
|
-// 一起判为废弃, 而本函数还要继续用。
|
|
|
-func Lt(field string, value interface{}, typ types.FieldType) Condition {
|
|
|
- return LtCondition{Field: field, Value: value, Type: typ}
|
|
|
-}
|
|
|
-
|
|
|
-func (c LtCondition) Fields() []string {
|
|
|
- return []string{c.Field}
|
|
|
-}
|
|
|
-
|
|
|
-func (c LtCondition) Match(row []byte, table *Table) bool {
|
|
|
- fieldIdx := table.findFieldIndex(c.Field)
|
|
|
- if fieldIdx < 0 {
|
|
|
- return false
|
|
|
- }
|
|
|
-
|
|
|
- // 比较类型与列级参数一律取列的实际定义 (声明类型已废弃), 与索引路径编键同源。
|
|
|
- ct := table.compareColTypeFor(fieldIdx)
|
|
|
- // 定位列并把行内【实际长度】的字节补齐到档位宽度 (v9 行是变长的, 条件值仍按档位编码)。
|
|
|
- seg, ok := table.rowFieldForCompare(row, fieldIdx, ct)
|
|
|
- if !ok {
|
|
|
- return false
|
|
|
- }
|
|
|
- return table.compareLess(seg, ct, c.Value)
|
|
|
-}
|
|
|
-
|
|
|
type NotCondition struct {
|
|
|
Cond Condition
|
|
|
}
|