InCondition.go 695 B

1234567891011121314151617181920212223242526272829303132333435
  1. package core
  2. import "TsDB2/DB/core/types"
  3. type InCondition struct {
  4. Field string
  5. Values []interface{}
  6. Type types.FieldType
  7. }
  8. func In(field string, values []interface{}, typ types.FieldType) Condition {
  9. return InCondition{Field: field, Values: values, Type: typ}
  10. }
  11. func (c InCondition) Fields() []string {
  12. return []string{c.Field}
  13. }
  14. func (c InCondition) Match(row []byte, table *Table) bool {
  15. fieldIdx := table.findFieldIndex(c.Field)
  16. if fieldIdx < 0 {
  17. return false
  18. }
  19. offset, ok := table.getVersionedOffset(row, fieldIdx)
  20. if !ok {
  21. return false
  22. }
  23. for _, value := range c.Values {
  24. if table.compareValue(row, offset, c.Type, value) {
  25. return true
  26. }
  27. }
  28. return false
  29. }