#include "sql/expr/tuple_cell.h" #include "storage/common/field.h" #include "common/log/log.h" #include "util/comparator.h" void TupleCell::to_string(std::ostream &os) const { switch (attr_type_) { case INTS: { os << *(int *)data_; } break; case FLOATS: { os << *(float *)data_; } break; case CHARS: { for (int i = 0; i < 4; i++) { // the max length of CHARS is 4 if (data_[i] == '\0') { break; } os << data_[i]; } } break; default: { LOG_WARN("unsupported attr type: %d", attr_type_); } break; } } int TupleCell::compare(const TupleCell &other) const { if (this->attr_type_ == other.attr_type_) { switch (this->attr_type_) { case INTS: return compare_int(this->data_, other.data_); case FLOATS: return compare_float(this->data_, other.data_); case CHARS: return compare_string(this->data_, other.data_, 4); default: { LOG_WARN("unsupported type: %d", this->attr_type_); } } } else if (this->attr_type_ == INTS && other.attr_type_ == FLOATS) { float this_data = *(int *)data_; return compare_float(&this_data, other.data_); } else if (this->attr_type_ == FLOATS && other.attr_type_ == INTS) { float other_data = *(int *)other.data_; return compare_float(data_, &other_data); } LOG_WARN("not supported"); return -1; // TODO return rc? }