[refactor](remove non vec code) remove json functions string functions match functions and some code (#16141)
remove json functions code remove string functions code remove math functions code move MatchPredicate to olap since it is only used in storage predicate process remove some code in tuple, Tuple structure should be removed in the future. remove many code in collection value structure, they are useless
This commit is contained in:
@ -38,217 +38,6 @@ public:
|
||||
JsonFunctionTest() {}
|
||||
};
|
||||
|
||||
TEST_F(JsonFunctionTest, string) {
|
||||
std::string json_string("{\"id\":\"name\",\"age\":11,\"money\":123000.789}");
|
||||
std::string path_string("$.id");
|
||||
rapidjson::Document document1;
|
||||
rapidjson::Value* res1 = JsonFunctions::get_json_object(nullptr, json_string, path_string,
|
||||
JSON_FUN_STRING, &document1);
|
||||
EXPECT_EQ(std::string(res1->GetString()), "name");
|
||||
|
||||
std::string json_string2("{\"price a\": [0,1,2],\"couponFee\":0}");
|
||||
std::string path_string2("$.price a");
|
||||
rapidjson::Document document2;
|
||||
rapidjson::Value* res2 = JsonFunctions::get_json_object(nullptr, json_string2, path_string2,
|
||||
JSON_FUN_STRING, &document2);
|
||||
rapidjson::StringBuffer buf2;
|
||||
rapidjson::Writer<rapidjson::StringBuffer> writer2(buf2);
|
||||
res2->Accept(writer2);
|
||||
EXPECT_EQ(std::string(buf2.GetString()), "[0,1,2]");
|
||||
|
||||
std::string json_string3("{\"price a\": [],\"couponFee\":0}");
|
||||
std::string path_string3("$.price a");
|
||||
rapidjson::Document document3;
|
||||
rapidjson::Value* res3 = JsonFunctions::get_json_object(nullptr, json_string3, path_string3,
|
||||
JSON_FUN_STRING, &document3);
|
||||
rapidjson::StringBuffer buf3;
|
||||
rapidjson::Writer<rapidjson::StringBuffer> writer3(buf3);
|
||||
res3->Accept(writer3);
|
||||
EXPECT_EQ(std::string(buf3.GetString()), "[]");
|
||||
|
||||
std::string json_string4("{\"price a\": [],\"couponFee\":null}");
|
||||
std::string path_string4("$.couponFee");
|
||||
rapidjson::Document document4;
|
||||
rapidjson::Value* res4 = JsonFunctions::get_json_object(nullptr, json_string4, path_string4,
|
||||
JSON_FUN_STRING, &document4);
|
||||
EXPECT_TRUE(res4->IsNull());
|
||||
|
||||
std::string json_string5(
|
||||
"{\"blockNames\": {},"
|
||||
"\"seatCategories\": [{\"areas\": [{\"areaId\": 205705999,\"blockIds\": []},"
|
||||
"{\"areaId\": 205705998,\"blockIds\": []}],\"seatCategoryId\": 338937290}]}");
|
||||
std::string path_string5_1("$.blockNames");
|
||||
rapidjson::Document document5_1;
|
||||
rapidjson::Value* res5_1 = JsonFunctions::get_json_object(nullptr, json_string5, path_string5_1,
|
||||
JSON_FUN_STRING, &document5_1);
|
||||
rapidjson::StringBuffer buf5_1;
|
||||
rapidjson::Writer<rapidjson::StringBuffer> writer5_1(buf5_1);
|
||||
res5_1->Accept(writer5_1);
|
||||
EXPECT_EQ(std::string(buf5_1.GetString()), "{}");
|
||||
|
||||
std::string path_string5_2("$.seatCategories.areas.blockIds");
|
||||
rapidjson::Document document5_2;
|
||||
rapidjson::Value* res5_2 = JsonFunctions::get_json_object(nullptr, json_string5, path_string5_2,
|
||||
JSON_FUN_STRING, &document5_2);
|
||||
rapidjson::StringBuffer buf5_2;
|
||||
rapidjson::Writer<rapidjson::StringBuffer> writer5_2(buf5_2);
|
||||
res5_2->Accept(writer5_2);
|
||||
EXPECT_EQ(std::string(buf5_2.GetString()), "[]");
|
||||
|
||||
std::string path_string5_3("$.seatCategories.areas[0].areaId");
|
||||
rapidjson::Document document5_3;
|
||||
rapidjson::Value* res5_3 = JsonFunctions::get_json_object(nullptr, json_string5, path_string5_3,
|
||||
JSON_FUN_STRING, &document5_2);
|
||||
rapidjson::StringBuffer buf5_3;
|
||||
rapidjson::Writer<rapidjson::StringBuffer> writer5_3(buf5_3);
|
||||
res5_3->Accept(writer5_3);
|
||||
EXPECT_EQ(std::string(buf5_3.GetString()), "205705999");
|
||||
}
|
||||
|
||||
TEST_F(JsonFunctionTest, json_quote) {
|
||||
doris_udf::FunctionContext* context = new doris_udf::FunctionContext();
|
||||
|
||||
EXPECT_EQ(StringVal::null(), JsonFunctions::json_quote(context, StringVal::null()));
|
||||
|
||||
doris_udf::StringVal res1 = JsonFunctions::json_quote(context, StringVal("null"));
|
||||
EXPECT_EQ(std::string("\"null\""), std::string((char*)res1.ptr, res1.len));
|
||||
|
||||
doris_udf::StringVal res2 = JsonFunctions::json_quote(context, StringVal("[1, 2, 3]"));
|
||||
EXPECT_EQ(std::string("\"[1, 2, 3]\""), std::string((char*)res2.ptr, res2.len));
|
||||
|
||||
doris_udf::StringVal res3 = JsonFunctions::json_quote(context, StringVal("\n\b\r\t"));
|
||||
EXPECT_EQ(std::string("\"\\n\\b\\r\\t\""), std::string((char*)res3.ptr, res3.len));
|
||||
|
||||
doris_udf::StringVal res4 = JsonFunctions::json_quote(context, StringVal("\""));
|
||||
EXPECT_EQ(std::string("\"\\\"\""), std::string((char*)res4.ptr, res4.len));
|
||||
|
||||
doris_udf::StringVal json_str = {""};
|
||||
doris_udf::StringVal res5 = JsonFunctions::json_quote(context, json_str);
|
||||
EXPECT_EQ(std::string("\"\""), std::string((char*)res5.ptr, res5.len));
|
||||
delete context;
|
||||
}
|
||||
|
||||
TEST_F(JsonFunctionTest, json_array) {
|
||||
doris_udf::FunctionContext* context = new doris_udf::FunctionContext();
|
||||
|
||||
doris_udf::StringVal json_str1[2] = {"[1,2,3]", "5"};
|
||||
doris_udf::StringVal res1 = JsonFunctions::json_array(context, 2, json_str1);
|
||||
EXPECT_EQ(std::string("[\"[1,2,3]\"]"), std::string((char*)res1.ptr, res1.len));
|
||||
|
||||
doris_udf::StringVal json_str2[4] = {"1", "abc", "null", "250"};
|
||||
doris_udf::StringVal res2 = JsonFunctions::json_array(context, 4, json_str2);
|
||||
EXPECT_EQ(std::string("[1,\"abc\",null]"), std::string((char*)res2.ptr, res2.len));
|
||||
|
||||
doris_udf::StringVal json_str3[1] = {""};
|
||||
doris_udf::StringVal res3 = JsonFunctions::json_array(context, 1, json_str3);
|
||||
EXPECT_EQ(std::string("[]"), std::string((char*)res3.ptr, res3.len));
|
||||
|
||||
doris_udf::StringVal json_str4[2] = {"null", "0"};
|
||||
doris_udf::StringVal res4 = JsonFunctions::json_array(context, 2, json_str4);
|
||||
EXPECT_EQ(std::string("[null]"), std::string((char*)res4.ptr, res4.len));
|
||||
delete context;
|
||||
}
|
||||
|
||||
TEST_F(JsonFunctionTest, json_object) {
|
||||
doris_udf::FunctionContext* context = new doris_udf::FunctionContext();
|
||||
doris_udf::StringVal json_str1[3] = {"id", "87", "52"};
|
||||
doris_udf::StringVal res1 = JsonFunctions::json_object(context, 3, json_str1);
|
||||
EXPECT_EQ(std::string("{\"id\":87}"), std::string((char*)res1.ptr, res1.len));
|
||||
|
||||
doris_udf::StringVal json_str2[5] = {"name", "Jack", "score", "[87,98,90]", "5555"};
|
||||
doris_udf::StringVal res2 = JsonFunctions::json_object(context, 5, json_str2);
|
||||
EXPECT_EQ(std::string("{\"name\":\"Jack\",\"score\":\"[87,98,90]\"}"),
|
||||
std::string((char*)res2.ptr, res2.len));
|
||||
|
||||
doris_udf::StringVal json_str3[3] = {"key", "null", "50"};
|
||||
doris_udf::StringVal res3 = JsonFunctions::json_object(context, 3, json_str3);
|
||||
EXPECT_EQ(std::string("{\"key\":null}"), std::string((char*)res3.ptr, res3.len));
|
||||
|
||||
doris_udf::StringVal json_str4[1] = {""};
|
||||
doris_udf::StringVal res4 = JsonFunctions::json_object(context, 1, json_str4);
|
||||
EXPECT_EQ(std::string("{}"), std::string((char*)res4.ptr, res4.len));
|
||||
delete context;
|
||||
}
|
||||
|
||||
TEST_F(JsonFunctionTest, int) {
|
||||
std::string json_string("{\"id\":\"name\",\"age\":11,\"money\":123000.789}");
|
||||
std::string path_string("$.age");
|
||||
rapidjson::Document document;
|
||||
rapidjson::Value* res = JsonFunctions::get_json_object(nullptr, json_string, path_string,
|
||||
JSON_FUN_INT, &document);
|
||||
EXPECT_EQ(res->GetInt(), 11);
|
||||
|
||||
std::string json_string1(
|
||||
"{\"list\":[{\"id\":[{\"aa\":1}]},{\"id\":[{\"aa\":\"cc\"}]},"
|
||||
"{\"id\":[{\"kk\":\"cc\"}]}]}");
|
||||
std::string path_string1("$.list.id.aa[0]");
|
||||
rapidjson::Document document1;
|
||||
rapidjson::Value* res1 = JsonFunctions::get_json_object(nullptr, json_string1, path_string1,
|
||||
JSON_FUN_INT, &document1);
|
||||
EXPECT_EQ(res1->GetInt(), 1);
|
||||
|
||||
std::string json_string2("[1,2,3,5,8,0]");
|
||||
std::string path_string2("$.[3]");
|
||||
rapidjson::Document document2;
|
||||
rapidjson::Value* res2 = JsonFunctions::get_json_object(nullptr, json_string2, path_string2,
|
||||
JSON_FUN_INT, &document2);
|
||||
EXPECT_EQ(res2->GetInt(), 5);
|
||||
|
||||
std::string json_string3("{\"price a\": [0,1,2],\"couponFee\":0.0}");
|
||||
std::string path_string3_1("$.price a[3]");
|
||||
rapidjson::Document document3_1;
|
||||
rapidjson::Value* res3_1 = JsonFunctions::get_json_object(nullptr, json_string3, path_string3_1,
|
||||
JSON_FUN_INT, &document3_1);
|
||||
EXPECT_TRUE(res3_1 == nullptr);
|
||||
|
||||
std::string path_string3_2("$.couponFee");
|
||||
rapidjson::Document document3_2;
|
||||
rapidjson::Value* res3_2 = JsonFunctions::get_json_object(nullptr, json_string3, path_string3_2,
|
||||
JSON_FUN_INT, &document3_2);
|
||||
EXPECT_FALSE(res3_2->IsInt());
|
||||
}
|
||||
|
||||
TEST_F(JsonFunctionTest, double) {
|
||||
std::string json_string("{\"id\":\"name\",\"age\":11,\"money\":123000.789}");
|
||||
std::string path_string("$.money");
|
||||
rapidjson::Document document;
|
||||
rapidjson::Value* res = JsonFunctions::get_json_object(nullptr, json_string, path_string,
|
||||
JSON_FUN_DOUBLE, &document);
|
||||
EXPECT_EQ(res->GetDouble(), 123000.789);
|
||||
|
||||
std::string path_string2("$.age");
|
||||
rapidjson::Document document2;
|
||||
rapidjson::Value* res2 = JsonFunctions::get_json_object(nullptr, json_string, path_string2,
|
||||
JSON_FUN_DOUBLE, &document2);
|
||||
EXPECT_EQ(res2->GetInt(), 11);
|
||||
}
|
||||
|
||||
TEST_F(JsonFunctionTest, special_char) {
|
||||
std::string json_string("{\"key with.dot\": [\"v1\", \"v2\"]}");
|
||||
std::string path_string("$.\"key with.dot\"[1]");
|
||||
rapidjson::Document document;
|
||||
rapidjson::Value* res = JsonFunctions::get_json_object(nullptr, json_string, path_string,
|
||||
JSON_FUN_DOUBLE, &document);
|
||||
EXPECT_FALSE(res->GetString() == nullptr);
|
||||
EXPECT_EQ(std::string(res->GetString()), "v2");
|
||||
|
||||
std::string json_string2("{\"key with|\": [\"v1\", \"v2\"]}");
|
||||
std::string path_string2("$.key with|[0]");
|
||||
rapidjson::Document document2;
|
||||
rapidjson::Value* res2 = JsonFunctions::get_json_object(nullptr, json_string2, path_string2,
|
||||
JSON_FUN_DOUBLE, &document2);
|
||||
EXPECT_FALSE(res2->GetString() == nullptr);
|
||||
EXPECT_EQ(std::string(res2->GetString()), "v1");
|
||||
|
||||
std::string json_string3("{\"key with.dot\": [{\"key2.dot\":\"v1\"}, {\"key3.dot\":\"v2\"}]}");
|
||||
std::string path_string3("$.\"key with.dot\"[0].\"key2.dot\"");
|
||||
rapidjson::Document document3;
|
||||
rapidjson::Value* res3 = JsonFunctions::get_json_object(nullptr, json_string3, path_string3,
|
||||
JSON_FUN_DOUBLE, &document3);
|
||||
EXPECT_FALSE(res3->GetString() == nullptr);
|
||||
EXPECT_EQ(std::string(res3->GetString()), "v1");
|
||||
}
|
||||
|
||||
TEST_F(JsonFunctionTest, json_path1) {
|
||||
bool wrap_explicitly;
|
||||
std::string json_raw_data(
|
||||
|
||||
Reference in New Issue
Block a user