Closed Little-Villain closed 1 month ago
data_type.cpp make_unique
(),
请问这一行 make_unique<FloatType>(),
的顺序与 src/observer/common/type/attr_type.h 中DATES 的声明顺序一致吗,这个可能会影响到你所说的 “出现的报错是调用了FloatType的比较函数”
data_type.cpp make_unique(),
请问这一行
make_unique<FloatType>(),
的顺序与 src/observer/common/type/attr_type.h 中DATES 的声明顺序一致吗,这个可能会影响到你所说的 “出现的报错是调用了FloatType的比较函数”
感谢!就是这里出错了,修改完以后可以正确运行了
以下是实现改动
case AttrType::DATES: { value_.int_value_ = *(int *)data; length_ = length; } break;
void Value::set_date(int val) { reset(); attr_type_ = AttrType::DATES; value_.int_value_ = val; length_ = sizeof(val); }
const char *ATTR_TYPE_NAME[] = {"undefined", "chars", "ints", "floats", "dates", "booleans"};
RC CharType::cast_to(const Value &val, AttrType type, Value &result) const { switch (type) { case AttrType::DATES : { result.attr_type_=AttrType::DATES; int y,m,d; if(sscanf(val.value_.pointer_value_,"%d-%d-%d",&y,&m,&d)!=3){ LOG_WARN("invalid date1 format:%s",val.value_.pointer_value_); return RC::INVALID_ARGUMENT; } bool check_ret=check_date(y,m,d); if(!check_ret){ LOG_WARN("invalid date2 format:%s",val.value_.pointer_value_); return RC::INVALID_ARGUMENT; } result.set_date(10000*y+100*m+d); LOG_WARN("Insert :%s %d-%d-%d",val.value_.pointer_value_,y,m,d); }break; default: return RC::UNIMPLEMENTED; } return RC::SUCCESS; }
int CharType::cast_cost(AttrType type) { if (type == AttrType::CHARS) { return 0; } if (type == AttrType::DATES) { return 1; } return INT32_MAX; }
make_unique<DateType>(),
include
include "common/lang/comparator.h"
include "common/lang/sstream.h"
include "common/log/log.h"
include "common/type/date_type.h"
include "common/value.h"
int DateType::compare(const Value &left, const Value &right) const { return common::compareint((void*)&left.value.intvalue,(void*)&right.value_.intvalue); }
RC DateType::tostring(const Value &val, string &result) const { stringstream ss; ss << std::setw(4) << std::setfill('0') << val.value.intvalue / 10000 <<"-" << std::setw(2) << std::setfill('0') << (val.value_.intvalue%10000) / 100 <<"-" << std::setw(2) << std::setfill('0') << val.value_.intvalue % 100;
result=ss.str(); return RC::SUCCESS; }
`