LeCondition.go 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. package core
  2. import "TsDB2/DB/core/types"
  3. type LeCondition struct {
  4. Field string
  5. Value interface{}
  6. // Deprecated: 已不参与比较 —— 行级过滤与索引路径都按【列的实际存储类型】编字节
  7. // (见 Table.compareColTypeFor)。它只剩"值怎么从 interface{} 取出"的提示作用,
  8. // 传任何值结果都一样; 保留仅为兼容既有调用方, 新代码传 0 即可。
  9. Type types.FieldType
  10. }
  11. // Le 构造 "field <= value" 条件。
  12. //
  13. // 第三个参数 typ 已废弃: 比较一律按列的实际存储类型进行 (见 Table.compareColTypeFor),
  14. // 它取任何值结果都一样, 传 types.FieldType(0) 即可。
  15. // 上面刻意不写成 "Deprecated:" 段落 —— Go 只能标记整个标识符废弃, 写了会把本函数
  16. // 一起判为废弃, 而本函数还要继续用。
  17. func Le(field string, value interface{}, typ types.FieldType) Condition {
  18. return LeCondition{Field: field, Value: value, Type: typ}
  19. }
  20. func (c LeCondition) Fields() []string {
  21. return []string{c.Field}
  22. }
  23. func (c LeCondition) Match(row []byte, table *Table) bool {
  24. fieldIdx := table.findFieldIndex(c.Field)
  25. if fieldIdx < 0 {
  26. return false
  27. }
  28. offset, ok := table.getVersionedOffset(row, fieldIdx)
  29. if !ok {
  30. return false
  31. }
  32. // 比较类型与列级参数一律取列的实际定义 (声明类型已废弃), 与索引路径编键同源。
  33. ct := table.compareColTypeFor(fieldIdx)
  34. return table.compareLessOrEqual(row, offset, ct, c.Value)
  35. }