[FEAT MERGE]:Oracle Json Supported

This commit is contained in:
obdev
2023-01-28 15:52:29 +08:00
committed by ob-robot
parent 274e68514d
commit bbb017266b
197 changed files with 30520 additions and 2252 deletions

View File

@ -65,6 +65,11 @@ ob_unittest(test_geo_srs_parser)
ob_unittest(test_geo_func_difference)
ob_unittest(test_geo_func_union)
ob_unittest(test_json_base)
ob_unittest(test_json_bin)
ob_unittest(test_json_path)
ob_unittest(test_json_tree)
add_subdirectory(allocator)
add_subdirectory(auto_increment)
add_subdirectory(cache)

File diff suppressed because it is too large Load Diff

View File

@ -861,77 +861,77 @@ void createTime(ObTime &ob_time)
ASSERT_EQ(OB_SUCCESS, ObTimeConverter::str_to_ob_time_without_date(str, ob_time));
}
void createDate(ObTime &ob_time)
{
ob_time.mode_ = DT_TYPE_DATE;
common::ObString str("20210906");
ASSERT_EQ(OB_SUCCESS, ObTimeConverter::str_to_ob_time_with_date(str, ob_time));
}
void createDateTime(ObTime &ob_time)
{
ob_time.mode_ = DT_TYPE_DATETIME;
common::ObString str("2021-09-06 11:12:13.456789");
ASSERT_EQ(OB_SUCCESS, ObTimeConverter::str_to_ob_time_with_date(str, ob_time));
ASSERT_EQ(OB_SUCCESS, ObTimeConverter::validate_datetime(ob_time));
}
TEST_F(TestJsonBin, dateAndTimeTest)
{
common::ObArenaAllocator allocator(ObModIds::TEST);
ObJsonArray array(&allocator);
ObTime obtime, obdate, obdatetime;
createTime(obtime);
createDate(obdate);
createDateTime(obdatetime);
ObJsonDatetime jt(ObJsonNodeType::J_TIME, obtime);
ObJsonDatetime jd(ObJsonNodeType::J_DATE, obdate);
ObJsonDatetime jtd(ObJsonNodeType::J_DATETIME, obdatetime);
// add to array
ASSERT_EQ(OB_SUCCESS, array.append(&jt));
ASSERT_EQ(OB_SUCCESS, array.append(&jd));
ASSERT_EQ(OB_SUCCESS, array.append(&jtd));
ObIJsonBase *j_tree_array = &array;
ObIJsonBase *j_bin_array = NULL;
ASSERT_EQ(OB_SUCCESS, ObJsonBaseFactory::transform(&allocator, j_tree_array,
ObJsonInType::JSON_BIN, j_bin_array));
ASSERT_EQ(ObJsonNodeType::J_ARRAY, j_bin_array->json_type());
ASSERT_EQ(3, j_bin_array->element_count());
// check time 19:18:17.654321
ObIJsonBase *j_bin1 = NULL;
ASSERT_EQ(OB_SUCCESS, j_bin_array->get_array_element(0, j_bin1));
ASSERT_EQ(ObJsonNodeType::J_TIME, j_bin1->json_type());
ObTime jt1;
j_bin1->get_obtime(jt1);
ASSERT_EQ(19, jt1.parts_[DT_HOUR]);
ASSERT_EQ(18, jt1.parts_[DT_MIN]);
ASSERT_EQ(17, jt1.parts_[DT_SEC]);
ASSERT_EQ(654321, jt1.parts_[DT_USEC]);
// check date 20210906
j_bin1 = NULL;
ASSERT_EQ(OB_SUCCESS, j_bin_array->get_array_element(1, j_bin1));
ASSERT_EQ(ObJsonNodeType::J_DATE, j_bin1->json_type());
j_bin1->get_obtime(jt1);
ASSERT_EQ(2021, jt1.parts_[DT_YEAR]);
ASSERT_EQ(9, jt1.parts_[DT_MON]);
ASSERT_EQ(6, jt1.parts_[DT_MDAY]);
// check datetime 2021-09-06 11:12:13.456789
j_bin1 = NULL;
ASSERT_EQ(OB_SUCCESS, j_bin_array->get_array_element(2, j_bin1));
ASSERT_EQ(ObJsonNodeType::J_DATETIME, j_bin1->json_type());
j_bin1->get_obtime(jt1);
ASSERT_EQ(11, jt1.parts_[DT_HOUR]);
ASSERT_EQ(12, jt1.parts_[DT_MIN]);
ASSERT_EQ(13, jt1.parts_[DT_SEC]);
ASSERT_EQ(456789, jt1.parts_[DT_USEC]);
ASSERT_EQ(2021, jt1.parts_[DT_YEAR]);
ASSERT_EQ(9, jt1.parts_[DT_MON]);
ASSERT_EQ(6, jt1.parts_[DT_MDAY]);
}
// void createDate(ObTime &ob_time)
// {
// ob_time.mode_ = DT_TYPE_DATE;
// common::ObString str("20210906");
// ASSERT_EQ(OB_SUCCESS, ObTimeConverter::str_to_ob_time_with_date(str, ob_time));
// }
//
// void createDateTime(ObTime &ob_time)
// {
// ob_time.mode_ = DT_TYPE_DATETIME;
// common::ObString str("2021-09-06 11:12:13.456789");
// ASSERT_EQ(OB_SUCCESS, ObTimeConverter::str_to_ob_time_with_date(str, ob_time));
// ASSERT_EQ(OB_SUCCESS, ObTimeConverter::validate_datetime(ob_time));
// }
//
// TEST_F(TestJsonBin, dateAndTimeTest)
// {
// common::ObArenaAllocator allocator(ObModIds::TEST);
// ObJsonArray array(&allocator);
// ObTime obtime, obdate, obdatetime;
// createTime(obtime);
// createDate(obdate);
// createDateTime(obdatetime);
// ObJsonDatetime jt(ObJsonNodeType::J_TIME, obtime);
// ObJsonDatetime jd(ObJsonNodeType::J_DATE, obdate);
// ObJsonDatetime jtd(ObJsonNodeType::J_DATETIME, obdatetime);
// // add to array
// ASSERT_EQ(OB_SUCCESS, array.append(&jt));
// ASSERT_EQ(OB_SUCCESS, array.append(&jd));
// ASSERT_EQ(OB_SUCCESS, array.append(&jtd));
//
// ObIJsonBase *j_tree_array = &array;
// ObIJsonBase *j_bin_array = NULL;
// ASSERT_EQ(OB_SUCCESS, ObJsonBaseFactory::transform(&allocator, j_tree_array,
// ObJsonInType::JSON_BIN, j_bin_array));
// ASSERT_EQ(ObJsonNodeType::J_ARRAY, j_bin_array->json_type());
// ASSERT_EQ(3, j_bin_array->element_count());
//
// // check time 19:18:17.654321
// ObIJsonBase *j_bin1 = NULL;
// ASSERT_EQ(OB_SUCCESS, j_bin_array->get_array_element(0, j_bin1));
// ASSERT_EQ(ObJsonNodeType::J_TIME, j_bin1->json_type());
// ObTime jt1;
// j_bin1->get_obtime(jt1);
// ASSERT_EQ(19, jt1.parts_[DT_HOUR]);
// ASSERT_EQ(18, jt1.parts_[DT_MIN]);
// ASSERT_EQ(17, jt1.parts_[DT_SEC]);
// ASSERT_EQ(654321, jt1.parts_[DT_USEC]);
//
// // check date 20210906
// j_bin1 = NULL;
// ASSERT_EQ(OB_SUCCESS, j_bin_array->get_array_element(1, j_bin1));
// ASSERT_EQ(ObJsonNodeType::J_DATE, j_bin1->json_type());
// j_bin1->get_obtime(jt1);
// ASSERT_EQ(2021, jt1.parts_[DT_YEAR]);
// ASSERT_EQ(9, jt1.parts_[DT_MON]);
// ASSERT_EQ(6, jt1.parts_[DT_MDAY]);
//
// // check datetime 2021-09-06 11:12:13.456789
// j_bin1 = NULL;
// ASSERT_EQ(OB_SUCCESS, j_bin_array->get_array_element(2, j_bin1));
// ASSERT_EQ(ObJsonNodeType::J_DATETIME, j_bin1->json_type());
// j_bin1->get_obtime(jt1);
// ASSERT_EQ(11, jt1.parts_[DT_HOUR]);
// ASSERT_EQ(12, jt1.parts_[DT_MIN]);
// ASSERT_EQ(13, jt1.parts_[DT_SEC]);
// ASSERT_EQ(456789, jt1.parts_[DT_USEC]);
// ASSERT_EQ(2021, jt1.parts_[DT_YEAR]);
// ASSERT_EQ(9, jt1.parts_[DT_MON]);
// ASSERT_EQ(6, jt1.parts_[DT_MDAY]);
// }
long getCurrentTime()
{

File diff suppressed because it is too large Load Diff

View File

@ -2074,6 +2074,163 @@ TEST_F(TestJsonTree, test_clone_node_datetime)
}
TEST_F(TestJsonTree, oracle_sub_type)
{
ObArenaAllocator allocator(ObModIds::TEST);
/* contruct type */
// int olong
ObJsonOInt o_int(123);
ObJsonOLong o_long(1234567890);
size_t MAX_BUF_SIZE = 256;
// odecimal
char dec_buf[MAX_BUF_SIZE];
memset(dec_buf, 0, MAX_BUF_SIZE);
number::ObNumber num;
size_t length = sprintf(dec_buf, "%lld", LLONG_MIN);
ASSERT_EQ(OB_SUCCESS, num.from(dec_buf, allocator));
ObJsonDecimal o_dec(num);
// odouble ofloat
ObJsonODouble o_double(0.0);
ObJsonOFloat o_float(23.23);
// interval ds
const char* interval_ds = "interval ds 123";
char* buf1 = (char*)allocator.alloc(MAX_BUF_SIZE);
memset(buf1, 0, MAX_BUF_SIZE);
memcpy(buf1, interval_ds, strlen(interval_ds));
ObJsonOInterval o_intervalds(buf1, strlen(interval_ds), ObIntervalDSType);
// interval ym
const char* interval_ym = "interval ym 123";
char* buf2 = (char*)allocator.alloc(MAX_BUF_SIZE);
memset(buf2, 0, MAX_BUF_SIZE);
memcpy(buf2, interval_ds, strlen(interval_ds));
ObJsonOInterval o_intervalym(buf2, strlen(interval_ds), ObIntervalDSType);
// binary
const char* binary = "binary string";
char* buf3 = (char*)allocator.alloc(MAX_BUF_SIZE);
memset(buf3, 0, MAX_BUF_SIZE);
memcpy(buf3, binary, strlen(binary));
ObJsonORawString o_binary(buf3, strlen(binary), ObJsonNodeType::J_OBINARY);
// odate, oracledate, otimestamp, otimestamptz
ObTime ob_time;
ASSERT_EQ(OB_SUCCESS, ObTimeConverter::datetime_to_ob_time(1429089727 * USECS_PER_SEC, NULL, ob_time));
ObJsonDatetime j_odate(ObJsonNodeType::J_ODATE, ob_time);
ObJsonDatetime j_oracledate(ObJsonNodeType::J_ORACLEDATE, ob_time);
ObJsonDatetime j_otimestamp(ObJsonNodeType::J_OTIMESTAMP, ob_time);
ObJsonDatetime j_otimestamptz(ObJsonNodeType::J_OTIMESTAMPTZ, ob_time);
/* test print */
// print
ObJsonBuffer j_buf(&allocator);
ObIJsonBase *j_base = nullptr;
j_base = (ObIJsonBase*)&o_int;
ASSERT_EQ(OB_SUCCESS, j_base->print(j_buf, false));
cout << "oint = " << j_buf.ptr() << endl;
j_buf.reuse();
j_base = (ObIJsonBase*)&o_long;
ASSERT_EQ(OB_SUCCESS, j_base->print(j_buf, false));
cout << "olong = " << j_buf.ptr() << endl;
j_buf.reuse();
j_base = (ObIJsonBase*)&o_dec;
ASSERT_EQ(OB_SUCCESS, j_base->print(j_buf, false));
cout << "odecimal = " << j_buf.ptr() << endl;
j_buf.reuse();
j_base = (ObIJsonBase*)&o_float;
ASSERT_EQ(OB_SUCCESS, j_base->print(j_buf, false));
cout << "ofloat = " << j_buf.ptr() << endl;
j_buf.reuse();
j_base = (ObIJsonBase*)&o_binary;
ASSERT_EQ(OB_SUCCESS, j_base->print(j_buf, false));
cout << "obinary = " << j_buf.ptr() << endl;
j_buf.reuse();
j_base = (ObIJsonBase*)&o_intervalds;
ASSERT_EQ(OB_SUCCESS, j_base->print(j_buf, false));
cout << "ointervalds = " << j_buf.ptr() << endl;
j_buf.reuse();
j_base = (ObIJsonBase*)&o_intervalym;
ASSERT_EQ(OB_SUCCESS, j_base->print(j_buf, false));
cout << "ointervalmy = " << j_buf.ptr() << endl;
j_buf.reuse();
j_base = (ObIJsonBase*)&j_odate;
ASSERT_EQ(OB_SUCCESS, j_base->print(j_buf, false));
cout << "odate = " << j_buf.ptr() << endl;
j_buf.reuse();
j_base = (ObIJsonBase*)&j_oracledate;
ASSERT_EQ(OB_SUCCESS, j_base->print(j_buf, false));
cout << "oracledate = " << j_buf.ptr() << endl;
j_buf.reuse();
j_base = (ObIJsonBase*)&j_otimestamp;
ASSERT_EQ(OB_SUCCESS, j_base->print(j_buf, false));
cout << "otimestamp = " << j_buf.ptr() << endl;
j_buf.reuse();
j_base = (ObIJsonBase*)&j_otimestamptz;
ASSERT_EQ(OB_SUCCESS, j_base->print(j_buf, false));
cout << "otimestamptz = " << j_buf.ptr() << endl;
/* clone */
ObJsonNode *p_oint = o_int.clone(&allocator);
ASSERT_NE(nullptr, p_oint);
ObJsonNode *p_olong = o_long.clone(&allocator);
ASSERT_NE(nullptr, p_olong);
ObJsonNode *p_ofloat = o_float.clone(&allocator);
ASSERT_NE(nullptr, p_ofloat);
ObJsonNode *p_odoube = o_double.clone(&allocator);
ASSERT_NE(nullptr, p_odoube);
ObJsonNode *p_ointervalds = o_intervalds.clone(&allocator);
ASSERT_NE(nullptr, p_ointervalds);
ObJsonNode *p_ointervalym = o_intervalym.clone(&allocator);
ASSERT_NE(nullptr, p_ointervalym);
ObJsonNode *p_obinary = o_binary.clone(&allocator);
ASSERT_NE(nullptr, p_obinary);
ObJsonNode *p_odate = j_odate.clone(&allocator);
ASSERT_NE(nullptr, p_odate);
ObJsonNode *p_oracledate = j_oracledate.clone(&allocator);
ASSERT_NE(nullptr, p_oracledate);
ObJsonNode *p_otimestamp = j_otimestamp.clone(&allocator);
ASSERT_NE(nullptr, p_otimestamp);
ObJsonNode *p_otimestamptz = j_otimestamptz.clone(&allocator);
ASSERT_NE(nullptr, p_otimestamptz);
double d_value;
float f_value;
uint64_t u_value;
int64_t i_value;
ASSERT_EQ(OB_SUCCESS, o_int.to_double(d_value));
ASSERT_EQ(OB_SUCCESS, o_int.to_uint(u_value));
ASSERT_EQ(OB_SUCCESS, o_float.to_uint(u_value));
ASSERT_EQ(OB_SUCCESS, o_float.to_double(d_value));
ASSERT_EQ(OB_SUCCESS, o_float.to_int(i_value));
}
} // namespace common
} // namespace oceanbase