MCPcopy Create free account
hub / github.com/4paradigm/OpenMLDB / Json2SQLRequestRow

Method Json2SQLRequestRow

src/apiserver/api_server_impl.cc:71–109  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

69}
70
71bool APIServerImpl::Json2SQLRequestRow(const butil::rapidjson::Value& non_common_cols_v,
72 const butil::rapidjson::Value& common_cols_v,
73 std::shared_ptr<fedb::sdk::SQLRequestRow> row) {
74 auto sch = row->GetSchema();
75
76 // scan all strings to init the total string length
77 decltype(common_cols_v.Size()) str_len_sum = 0;
78 decltype(common_cols_v.Size()) non_common_idx = 0, common_idx = 0;
79 for (decltype(sch->GetColumnCnt()) i = 0; i < sch->GetColumnCnt(); ++i) {
80 if (sch->GetColumnType(i) != hybridse::sdk::kTypeString) {
81 continue;
82 }
83 if (sch->IsConstant(i)) {
84 str_len_sum += common_cols_v[common_idx].GetStringLength();
85 ++common_idx;
86 } else {
87 str_len_sum += non_common_cols_v[non_common_idx].GetStringLength();
88 ++non_common_idx;
89 }
90 }
91 row->Init(static_cast<int32_t>(str_len_sum));
92
93 non_common_idx = 0, common_idx = 0;
94 for (decltype(sch->GetColumnCnt()) i = 0; i < sch->GetColumnCnt(); ++i) {
95 if (sch->IsConstant(i)) {
96 if (!AppendJsonValue(common_cols_v[common_idx], sch->GetColumnType(i), sch->IsColumnNotNull(i), row)) {
97 return false;
98 }
99 ++common_idx;
100 } else {
101 if (!AppendJsonValue(non_common_cols_v[non_common_idx], sch->GetColumnType(i), sch->IsColumnNotNull(i),
102 row)) {
103 return false;
104 }
105 ++non_common_idx;
106 }
107 }
108 return true;
109}
110
111template <typename T>
112bool APIServerImpl::AppendJsonValue(const butil::rapidjson::Value& v, hybridse::sdk::DataType type, bool is_not_null,

Callers

nothing calls this directly

Calls 3

GetSchemaMethod · 0.45
SizeMethod · 0.45
InitMethod · 0.45

Tested by

no test coverage detected