HangyuanLiu commented on a change in pull request #3230: Support load json-data into Doris by RoutineLoad or StreamLoad URL: https://github.com/apache/incubator-doris/pull/3230#discussion_r400087109
########## File path: be/test/exprs/json_function_test.cpp ########## @@ -186,10 +186,57 @@ TEST_F(JsonFunctionTest, special_char) ASSERT_EQ(std::string(res3->GetString()), "v1"); } +TEST_F(JsonFunctionTest, json_path1) +{ + std::string json_raw_data("{\"jsonpath\":[{\"key\":\"colname1\",\"type\":\"string\",\"value\":\"$.store.book.category\"},{\"key\":\"colname2\",\"type\":\"string\",\"value\":\"$.store.book.author\"},{\"key\":\"colname3\",\"type\":\"string\",\"value\":\"$.store.book.title\"},{\"key\":\"colname4\",\"type\":\"float\",\"value\":\"$.store.book.price\"}],\"store\":{\"book\":[{\"category\":\"reference\",\"author\":\"NigelRees\",\"title\":\"SayingsoftheCentury\",\"price\":8.95},{\"category\":\"fiction\",\"author\":\"EvelynWaugh\",\"title\":\"SwordofHonour\",\"price\":12.99}],\"bicycle\":{\"color\":\"red\",\"price\":19.95}},\"expensive\":10}"); + rapidjson::Document jsonDoc; + ASSERT_FALSE(jsonDoc.Parse(json_raw_data.c_str()).HasParseError()); + if (!jsonDoc.HasMember("jsonpath") || !jsonDoc["jsonpath"].IsArray()) { + std::cout << jsonDoc.HasMember("jsonpath"); + std::cout << jsonDoc["jsonpath"].IsArray(); + ASSERT_TRUE(false); + } + const rapidjson::Value& arr = jsonDoc["jsonpath"]; + enum JsonFunctionType type; + rapidjson::Document jsonDoc2; + for (int i = 0; i < arr.Size(); i++) { + const rapidjson::Value& path = arr[i]; + if (!path["type"].IsString() || !path["key"].IsString() || !path["value"].IsString()) { + ASSERT_TRUE(false); + } + const char *c_type = path["type"].GetString(); + if (!strcmp(c_type, "integer")) { + type = JSON_FUN_INT; + } else if (!strcmp(c_type, "float")) { + type = JSON_FUN_DOUBLE; + } else if (!strcmp(c_type, "string")) { + type = JSON_FUN_STRING; + } else + { + ASSERT_TRUE(false); + } + rapidjson::Value* res3 = JsonFunctions::get_json_object(nullptr, json_raw_data, path["value"].GetString(), type, &jsonDoc2); + rapidjson::Value& value = *res3; + if (value.IsArray()) { + std::cout << "Array:" << path["value"].GetString() << std::endl; + + for (int i = 0; i < res3->Size(); i++) { + std::cout << (res3 + i)->GetString() << " "; + } + std::cout << std::endl; + } + } +} + } int main(int argc, char** argv) { - std::string conffile = std::string(getenv("DORIS_HOME")) + "/conf/be.conf"; + std::string home(getenv("DORIS_HOME")); + if (home.empty()) { + home = "."; + } + std::string conffile = home + "/conf/be.conf"; + std::cout<<conffile<<std::endl; Review comment: Do we need cout? ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org