| 69 | } |
| 70 | |
| 71 | bool 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 | |
| 111 | template <typename T> |
| 112 | bool APIServerImpl::AppendJsonValue(const butil::rapidjson::Value& v, hybridse::sdk::DataType type, bool is_not_null, |