GtCondition.go 1.6 KB

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