static int double_mtime(const ObObjCastParams ¶ms, const ObExprObj &in, ObExprObj &out) { UNUSED(params); OB_ASSERT(in.get_type() == ObDoubleType); out.set_mtime(static_cast<ObModifyTime> (in.get_double())); return OB_SUCCESS; }
static int ctime_float(const ObObjCastParams ¶ms, const ObExprObj &in, ObExprObj &out) { UNUSED(params); OB_ASSERT(in.get_type() == ObCreateTimeType); out.set_float(static_cast<float> (in.get_ctime())); return OB_SUCCESS; }
static int double_int(const ObObjCastParams ¶ms, const ObExprObj &in, ObExprObj &out) { UNUSED(params); OB_ASSERT(in.get_type() == ObDoubleType); out.set_int(static_cast<int64_t> (in.get_double())); return OB_SUCCESS; }
static int ctime_datetime(const ObObjCastParams ¶ms, const ObExprObj &in, ObExprObj &out) { UNUSED(params); OB_ASSERT(in.get_type() == ObCreateTimeType); out.set_datetime(static_cast<ObDateTime> (in.get_ctime() / 1000000L)); return OB_SUCCESS; }
static int mtime_pdatetime(const ObObjCastParams ¶ms, const ObExprObj &in, ObExprObj &out) { UNUSED(params); OB_ASSERT(in.get_type() == ObModifyTimeType); out.set_precise_datetime(static_cast<ObPreciseDateTime> (in.get_mtime())); return OB_SUCCESS; }
static int float_double(const ObObjCastParams ¶ms, const ObExprObj &in, ObExprObj &out) { UNUSED(params); OB_ASSERT(in.get_type() == ObFloatType); out.set_double(static_cast<double> (in.get_float())); return OB_SUCCESS; }
static int decimal_bool(const ObObjCastParams ¶ms, const ObExprObj &in, ObExprObj &out) { UNUSED(params); OB_ASSERT(in.get_type() == ObDecimalType); out.set_bool(!in.get_decimal().is_zero()); return OB_SUCCESS; }
static int mtime_bool(const ObObjCastParams ¶ms, const ObExprObj &in, ObExprObj &out) { UNUSED(params); OB_ASSERT(in.get_type() == ObModifyTimeType); out.set_bool(static_cast<bool> (in.get_mtime())); return OB_SUCCESS; }
static int bool_float(const ObObjCastParams ¶ms, const ObExprObj &in, ObExprObj &out) { UNUSED(params); OB_ASSERT(in.get_type() == ObBoolType); out.set_float(static_cast<float> (in.get_bool())); return OB_SUCCESS; }
static int int_datetime(const ObObjCastParams ¶ms, const ObExprObj &in, ObExprObj &out) { UNUSED(params); OB_ASSERT(in.get_type() == ObIntType); out.set_datetime(static_cast<ObDateTime> (in.get_int())); return OB_SUCCESS; }
static int bool_ctime(const ObObjCastParams ¶ms, const ObExprObj &in, ObExprObj &out) { UNUSED(params); OB_ASSERT(in.get_type() == ObBoolType); out.set_ctime(static_cast<ObCreateTime> (in.get_bool())); return OB_SUCCESS; }
static int int_varchar(const ObObjCastParams ¶ms, const ObExprObj &in, ObExprObj &out) { int ret = OB_SUCCESS; UNUSED(params); OB_ASSERT(in.get_type() == ObIntType); ret = varchar_printf(out, "%ld", in.get_int()); return ret; }
static int int_decimal(const ObObjCastParams ¶ms, const ObExprObj &in, ObExprObj &out) { UNUSED(params); OB_ASSERT(in.get_type() == ObIntType); ObNumber num; num.from(in.get_int()); out.set_decimal(num); // @todo optimize return OB_SUCCESS; }
static int mtime_decimal(const ObObjCastParams ¶ms, const ObExprObj &in, ObExprObj &out) { UNUSED(params); OB_ASSERT(in.get_type() == ObModifyTimeType); ObNumber num; num.from(static_cast<int64_t> (in.get_mtime())); out.set_decimal(num); return OB_SUCCESS; }
static int datetime_varchar(const ObObjCastParams ¶ms, const ObExprObj &in, ObExprObj &out) { int ret = OB_SUCCESS; UNUSED(params); OB_ASSERT(in.get_type() == ObDateTimeType); time_t t = static_cast<time_t> (in.get_datetime()); struct tm gtm; localtime_r(&t, >m); ret = varchar_printf(out, "%04d-%02d-%02d %02d:%02d:%02d", gtm.tm_year + 1900, gtm.tm_mon + 1, gtm.tm_mday, gtm.tm_hour, gtm.tm_min, gtm.tm_sec); return ret; }
static int varchar_datetime(const ObObjCastParams ¶ms, const ObExprObj &in, ObExprObj &out) { int ret = OB_SUCCESS; UNUSED(params); OB_ASSERT(in.get_type() == ObVarcharType); int year = 0; int month = 0; int day = 0; int hour = 0; int minute = 0; int second = 0; ret = varchar_scanf(in, 6, "%4d-%2d-%2d %2d:%2d:%2d", &year, &month, &day, &hour, &minute, &second); if (OB_SUCCESS != ret) { year = month = day = hour = minute = second = 0; ret = varchar_scanf(in, 3, "%4d-%2d-%2d", &year, &month, &day); } if (OB_SUCCESS != ret) { year = month = day = hour = minute = second = 0; ret = varchar_scanf(in, 3, "%2d:%2d:%2d", &hour, &minute, &second); } if (OB_SUCCESS == ret) { struct tm gtm; memset(>m, 0, sizeof (gtm)); gtm.tm_year = year - 1900; gtm.tm_mon = month - 1; gtm.tm_mday = day; gtm.tm_hour = hour; gtm.tm_min = minute; gtm.tm_sec = second; time_t t = mktime(>m); out.set_datetime(static_cast<ObDateTime> (t)); } else { const string& varchar = in.get_varchar(); jlog(WARNING, "failed to convert string `%.*s' to datetime type", varchar.length(), varchar.data()); out.set_datetime(static_cast<ObDateTime> (0)); ret = OB_SUCCESS; } return ret; }
static int bool_varchar(const ObObjCastParams ¶ms, const ObExprObj &in, ObExprObj &out) { UNUSED(params); OB_ASSERT(in.get_type() == ObBoolType); string varchar; if (in.get_bool()) { varchar.assign("true"); } else { varchar.assign("false"); } out.set_varchar(varchar); return OB_SUCCESS; }
static int decimal_mtime(const ObObjCastParams ¶ms, const ObExprObj &in, ObExprObj &out) { int ret = OB_SUCCESS; UNUSED(params); OB_ASSERT(in.get_type() == ObDecimalType); int64_t i64 = 0; if (OB_SUCCESS != (ret = in.get_decimal().cast_to_int64(i64))) { jlog(WARNING, "failed to cast to int64, err=%d", ret); } else { out.set_mtime(static_cast<ObModifyTime> (i64)); } return ret; }
static int varchar_decimal(const ObObjCastParams ¶ms, const ObExprObj &in, ObExprObj &out) { int ret = OB_SUCCESS; UNUSED(params); OB_ASSERT(in.get_type() == ObVarcharType); const string &varchar = in.get_varchar(); ObNumber num; if (OB_SUCCESS != (ret = num.from(varchar.data(), varchar.length()))) { jlog(WARNING, "failed to convert varchar to decimal, err=%d varchar=%.*s", ret, varchar.length(), varchar.data()); } else { out.set_decimal(num); // @todo optimize } return OB_SUCCESS; }
static int varchar_double(const ObObjCastParams ¶ms, const ObExprObj &in, ObExprObj &out) { int ret = OB_SUCCESS; UNUSED(params); OB_ASSERT(in.get_type() == ObVarcharType); double value = 0.0; ret = varchar_scanf(in, 1, "%lf", &value); if (OB_SUCCESS == ret) { out.set_double(value); } else { out.set_double(0.0); ret = OB_SUCCESS; } return ret; }
static int decimal_varchar(const ObObjCastParams ¶ms, const ObExprObj &in, ObExprObj &out) { int ret = OB_SUCCESS; UNUSED(params); OB_ASSERT(in.get_type() == ObDecimalType); string varchar = out.get_varchar(); if (varchar.length() < ObNumber::MAX_PRINTABLE_SIZE) { jlog(WARNING, "output buffer for varchar not enough, buf_len=%d", varchar.length()); ret = OB_INVALID_ARGUMENT; } else { int64_t length = in.get_decimal().to_string((char*) varchar.data(), varchar.length()); string varchar2(varchar); out.set_varchar(varchar2); } return ret; }
static int double_decimal(const ObObjCastParams ¶ms, const ObExprObj &in, ObExprObj &out) { int ret = OB_SUCCESS; UNUSED(params); OB_ASSERT(in.get_type() == ObDoubleType); static const int64_t MAX_DOUBLE_PRINT_SIZE = 64; char buf[MAX_DOUBLE_PRINT_SIZE]; snprintf(buf, MAX_DOUBLE_PRINT_SIZE, "%f", in.get_double()); ObNumber num; if (OB_SUCCESS != (ret = num.from(buf))) { jlog(WARNING, "failed to convert float to decimal, err=%d", ret); } else { out.set_decimal(num); } return ret; }
static int decimal_double(const ObObjCastParams ¶ms, const ObExprObj &in, ObExprObj &out) { UNUSED(params); OB_ASSERT(in.get_type() == ObDecimalType); // decimal -> string -> float char buf[ObNumber::MAX_PRINTABLE_SIZE]; memset(buf, 0, ObNumber::MAX_PRINTABLE_SIZE); in.get_decimal().to_string(buf, ObNumber::MAX_PRINTABLE_SIZE); double v = 0.0; if (1 == sscanf(buf, "%lf", &v)) { out.set_double(v); } else { out.set_double(0.0); } return OB_SUCCESS; }
static int varchar_mtime(const ObObjCastParams ¶ms, const ObExprObj &in, ObExprObj &out) { int ret = OB_SUCCESS; UNUSED(params); OB_ASSERT(in.get_type() == ObVarcharType); int64_t timestamp = 0; ret = varchar_timestamp(in, timestamp); if (OB_SUCCESS == ret) { out.set_mtime(static_cast<ObModifyTime> (timestamp)); } else { const string& varchar = in.get_varchar(); jlog(WARNING, "failed to convert string `%.*s' to modifytime type", varchar.length(), varchar.data()); out.set_mtime(static_cast<ObModifyTime> (0)); ret = OB_SUCCESS; } return ret; }
static int varchar_bool(const ObObjCastParams ¶ms, const ObExprObj &in, ObExprObj &out) { UNUSED(params); OB_ASSERT(in.get_type() == ObVarcharType); const string &varchar = in.get_varchar(); bool value = false; if (varchar.data() != NULL && varchar.length() > 0) { static const int64_t len_true = strlen("true"); static const int64_t len_t = strlen("T"); static const int64_t len_yes = strlen("yes"); static const int64_t len_y = strlen("y"); if (varchar.length() == len_true && 0 == strncasecmp(varchar.data(), "true", len_true)) { value = true; } else if (varchar.length() == len_t && 0 == strncasecmp(varchar.data(), "T", len_t)) { value = true; } else if (varchar.length() == len_yes && 0 == strncasecmp(varchar.data(), "yes", len_yes)) { value = true; } else if (varchar.length() == len_y && 0 == strncasecmp(varchar.data(), "y", len_y)) { value = true; } } out.set_bool(value); return OB_SUCCESS; }
static int mtime_varchar(const ObObjCastParams ¶ms, const ObExprObj &in, ObExprObj &out) { UNUSED(params); OB_ASSERT(in.get_type() == ObModifyTimeType); return timestamp_varchar(in.get_mtime(), out); }
static int double_varchar(const ObObjCastParams ¶ms, const ObExprObj &in, ObExprObj &out) { UNUSED(params); OB_ASSERT(in.get_type() == ObDoubleType); return varchar_printf(out, "%f", in.get_double()); }
static int pdatetime_varchar(const ObObjCastParams ¶ms, const ObExprObj &in, ObExprObj &out) { UNUSED(params); OB_ASSERT(in.get_type() == ObPreciseDateTimeType); return timestamp_varchar(in.get_precise_datetime(), out); }