| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- package core
- import "TsDB2/DB/core/types"
- type InCondition struct {
- Field string
- Values []interface{}
- // Deprecated: 已不参与比较 —— 行级过滤与索引路径都按【列的实际存储类型】编字节
- // (见 Table.compareColTypeFor)。它只剩"值怎么从 interface{} 取出"的提示作用,
- // 传任何值结果都一样; 保留仅为兼容既有调用方, 新代码传 0 即可。
- Type types.FieldType
- }
- // In 构造 "field IN (values...)" 条件。
- //
- // 第三个参数 typ 已废弃: 比较一律按列的实际存储类型进行 (见 Table.compareColTypeFor),
- // 它取任何值结果都一样, 传 types.FieldType(0) 即可。
- // 上面刻意不写成 "Deprecated:" 段落 —— Go 只能标记整个标识符废弃, 写了会把本函数
- // 一起判为废弃, 而本函数还要继续用。
- func In(field string, values []interface{}, typ types.FieldType) Condition {
- return InCondition{Field: field, Values: values, Type: typ}
- }
- func (c InCondition) Fields() []string {
- return []string{c.Field}
- }
- func (c InCondition) Match(row []byte, table *Table) bool {
- fieldIdx := table.findFieldIndex(c.Field)
- if fieldIdx < 0 {
- return false
- }
- offset, ok := table.getVersionedOffset(row, fieldIdx)
- if !ok {
- return false
- }
- // 比较类型与列级参数一律取列的实际定义 (声明类型已废弃), 与索引路径编键同源。
- ct := table.compareColTypeFor(fieldIdx)
- for _, value := range c.Values {
- if table.compareValue(row, offset, ct, value) {
- return true
- }
- }
- return false
- }
|