BatchGetTablesResult.cc 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. /*
  2. * Copyright 2009-2017 Alibaba Cloud All rights reserved.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #include <alibabacloud/datalake/model/BatchGetTablesResult.h>
  17. #include <json/json.h>
  18. using namespace AlibabaCloud::DataLake;
  19. using namespace AlibabaCloud::DataLake::Model;
  20. BatchGetTablesResult::BatchGetTablesResult() :
  21. ServiceResult()
  22. {}
  23. BatchGetTablesResult::BatchGetTablesResult(const std::string &payload) :
  24. ServiceResult()
  25. {
  26. parse(payload);
  27. }
  28. BatchGetTablesResult::~BatchGetTablesResult()
  29. {}
  30. void BatchGetTablesResult::parse(const std::string &payload)
  31. {
  32. Json::Reader reader;
  33. Json::Value value;
  34. reader.parse(payload, value);
  35. setRequestId(value["RequestId"].asString());
  36. auto allTableErrorsNode = value["TableErrors"]["TableErrorsItem"];
  37. for (auto valueTableErrorsTableErrorsItem : allTableErrorsNode)
  38. {
  39. TableErrorsItem tableErrorsObject;
  40. if(!valueTableErrorsTableErrorsItem["TableName"].isNull())
  41. tableErrorsObject.tableName = valueTableErrorsTableErrorsItem["TableName"].asString();
  42. auto errorDetailNode = value["ErrorDetail"];
  43. if(!errorDetailNode["Code"].isNull())
  44. tableErrorsObject.errorDetail.code = errorDetailNode["Code"].asString();
  45. if(!errorDetailNode["Message"].isNull())
  46. tableErrorsObject.errorDetail.message = errorDetailNode["Message"].asString();
  47. tableErrors_.push_back(tableErrorsObject);
  48. }
  49. auto allTablesNode = value["Tables"]["TablesItem"];
  50. for (auto valueTablesTablesItem : allTablesNode)
  51. {
  52. TablesItem tablesObject;
  53. if(!valueTablesTablesItem["Cascade"].isNull())
  54. tablesObject.cascade = valueTablesTablesItem["Cascade"].asString() == "true";
  55. if(!valueTablesTablesItem["CreateTime"].isNull())
  56. tablesObject.createTime = std::stoi(valueTablesTablesItem["CreateTime"].asString());
  57. if(!valueTablesTablesItem["CreatedBy"].isNull())
  58. tablesObject.createdBy = valueTablesTablesItem["CreatedBy"].asString();
  59. if(!valueTablesTablesItem["DatabaseName"].isNull())
  60. tablesObject.databaseName = valueTablesTablesItem["DatabaseName"].asString();
  61. if(!valueTablesTablesItem["LastAccessTime"].isNull())
  62. tablesObject.lastAccessTime = std::stoi(valueTablesTablesItem["LastAccessTime"].asString());
  63. if(!valueTablesTablesItem["LastAnalyzedTime"].isNull())
  64. tablesObject.lastAnalyzedTime = std::stoi(valueTablesTablesItem["LastAnalyzedTime"].asString());
  65. if(!valueTablesTablesItem["Owner"].isNull())
  66. tablesObject.owner = valueTablesTablesItem["Owner"].asString();
  67. if(!valueTablesTablesItem["OwnerType"].isNull())
  68. tablesObject.ownerType = valueTablesTablesItem["OwnerType"].asString();
  69. if(!valueTablesTablesItem["Parameters"].isNull())
  70. tablesObject.parameters = valueTablesTablesItem["Parameters"].asString();
  71. if(!valueTablesTablesItem["Retention"].isNull())
  72. tablesObject.retention = std::stoi(valueTablesTablesItem["Retention"].asString());
  73. if(!valueTablesTablesItem["RewriteEnabled"].isNull())
  74. tablesObject.rewriteEnabled = valueTablesTablesItem["RewriteEnabled"].asString() == "true";
  75. if(!valueTablesTablesItem["TableName"].isNull())
  76. tablesObject.tableName = valueTablesTablesItem["TableName"].asString();
  77. if(!valueTablesTablesItem["TableType"].isNull())
  78. tablesObject.tableType = valueTablesTablesItem["TableType"].asString();
  79. if(!valueTablesTablesItem["Temporary"].isNull())
  80. tablesObject.temporary = valueTablesTablesItem["Temporary"].asString() == "true";
  81. if(!valueTablesTablesItem["UpdateTime"].isNull())
  82. tablesObject.updateTime = std::stoi(valueTablesTablesItem["UpdateTime"].asString());
  83. if(!valueTablesTablesItem["ViewExpandedText"].isNull())
  84. tablesObject.viewExpandedText = valueTablesTablesItem["ViewExpandedText"].asString();
  85. if(!valueTablesTablesItem["ViewOriginalText"].isNull())
  86. tablesObject.viewOriginalText = valueTablesTablesItem["ViewOriginalText"].asString();
  87. if(!valueTablesTablesItem["TableId"].isNull())
  88. tablesObject.tableId = valueTablesTablesItem["TableId"].asString();
  89. auto allPartitionKeysNode = valueTablesTablesItem["PartitionKeys"]["PartitionKeysItem"];
  90. for (auto valueTablesTablesItemPartitionKeysPartitionKeysItem : allPartitionKeysNode)
  91. {
  92. TablesItem::PartitionKeysItem partitionKeysObject;
  93. if(!valueTablesTablesItemPartitionKeysPartitionKeysItem["Comment"].isNull())
  94. partitionKeysObject.comment = valueTablesTablesItemPartitionKeysPartitionKeysItem["Comment"].asString();
  95. if(!valueTablesTablesItemPartitionKeysPartitionKeysItem["Name"].isNull())
  96. partitionKeysObject.name = valueTablesTablesItemPartitionKeysPartitionKeysItem["Name"].asString();
  97. if(!valueTablesTablesItemPartitionKeysPartitionKeysItem["Parameters"].isNull())
  98. partitionKeysObject.parameters = valueTablesTablesItemPartitionKeysPartitionKeysItem["Parameters"].asString();
  99. if(!valueTablesTablesItemPartitionKeysPartitionKeysItem["Type"].isNull())
  100. partitionKeysObject.type = valueTablesTablesItemPartitionKeysPartitionKeysItem["Type"].asString();
  101. tablesObject.partitionKeys.push_back(partitionKeysObject);
  102. }
  103. auto privilegesNode = value["Privileges"];
  104. if(!privilegesNode["GroupPrivileges"].isNull())
  105. tablesObject.privileges.groupPrivileges = privilegesNode["GroupPrivileges"].asString();
  106. if(!privilegesNode["RolePrivileges"].isNull())
  107. tablesObject.privileges.rolePrivileges = privilegesNode["RolePrivileges"].asString();
  108. if(!privilegesNode["UserPrivileges"].isNull())
  109. tablesObject.privileges.userPrivileges = privilegesNode["UserPrivileges"].asString();
  110. auto sdNode = value["Sd"];
  111. if(!sdNode["Compressed"].isNull())
  112. tablesObject.sd.compressed = sdNode["Compressed"].asString() == "true";
  113. if(!sdNode["InputFormat"].isNull())
  114. tablesObject.sd.inputFormat = sdNode["InputFormat"].asString();
  115. if(!sdNode["Location"].isNull())
  116. tablesObject.sd.location = sdNode["Location"].asString();
  117. if(!sdNode["NumBuckets"].isNull())
  118. tablesObject.sd.numBuckets = std::stoi(sdNode["NumBuckets"].asString());
  119. if(!sdNode["OutputFormat"].isNull())
  120. tablesObject.sd.outputFormat = sdNode["OutputFormat"].asString();
  121. if(!sdNode["Parameters"].isNull())
  122. tablesObject.sd.parameters = sdNode["Parameters"].asString();
  123. if(!sdNode["StoredAsSubDirectories"].isNull())
  124. tablesObject.sd.storedAsSubDirectories = sdNode["StoredAsSubDirectories"].asString() == "true";
  125. auto allColsNode = sdNode["Cols"]["ColsItem"];
  126. for (auto sdNodeColsColsItem : allColsNode)
  127. {
  128. TablesItem::Sd::ColsItem colsItemObject;
  129. if(!sdNodeColsColsItem["Comment"].isNull())
  130. colsItemObject.comment = sdNodeColsColsItem["Comment"].asString();
  131. if(!sdNodeColsColsItem["Name"].isNull())
  132. colsItemObject.name = sdNodeColsColsItem["Name"].asString();
  133. if(!sdNodeColsColsItem["Parameters"].isNull())
  134. colsItemObject.parameters = sdNodeColsColsItem["Parameters"].asString();
  135. if(!sdNodeColsColsItem["Type"].isNull())
  136. colsItemObject.type = sdNodeColsColsItem["Type"].asString();
  137. tablesObject.sd.cols.push_back(colsItemObject);
  138. }
  139. auto allSortColsNode = sdNode["SortCols"]["SortColsItem"];
  140. for (auto sdNodeSortColsSortColsItem : allSortColsNode)
  141. {
  142. TablesItem::Sd::SortColsItem sortColsItemObject;
  143. if(!sdNodeSortColsSortColsItem["Col"].isNull())
  144. sortColsItemObject.col = sdNodeSortColsSortColsItem["Col"].asString();
  145. if(!sdNodeSortColsSortColsItem["Order"].isNull())
  146. sortColsItemObject.order = std::stoi(sdNodeSortColsSortColsItem["Order"].asString());
  147. tablesObject.sd.sortCols.push_back(sortColsItemObject);
  148. }
  149. auto serDeInfoNode = sdNode["SerDeInfo"];
  150. if(!serDeInfoNode["Name"].isNull())
  151. tablesObject.sd.serDeInfo.name = serDeInfoNode["Name"].asString();
  152. if(!serDeInfoNode["Parameters"].isNull())
  153. tablesObject.sd.serDeInfo.parameters = serDeInfoNode["Parameters"].asString();
  154. if(!serDeInfoNode["SerializationLib"].isNull())
  155. tablesObject.sd.serDeInfo.serializationLib = serDeInfoNode["SerializationLib"].asString();
  156. auto skewedInfoNode = sdNode["SkewedInfo"];
  157. if(!skewedInfoNode["SkewedColValueLocationMaps"].isNull())
  158. tablesObject.sd.skewedInfo.skewedColValueLocationMaps = skewedInfoNode["SkewedColValueLocationMaps"].asString();
  159. auto allSkewedColNames = skewedInfoNode["SkewedColNames"]["null"];
  160. for (auto value : allSkewedColNames)
  161. tablesObject.sd.skewedInfo.skewedColNames.push_back(value.asString());
  162. auto allSkewedColValues = skewedInfoNode["SkewedColValues"]["null"];
  163. for (auto value : allSkewedColValues)
  164. tablesObject.sd.skewedInfo.skewedColValues.push_back(value.asString());
  165. auto allBucketCols = sdNode["BucketCols"]["null"];
  166. for (auto value : allBucketCols)
  167. tablesObject.sd.bucketCols.push_back(value.asString());
  168. auto tableVersionNode = value["TableVersion"];
  169. if(!tableVersionNode["Table"].isNull())
  170. tablesObject.tableVersion.table = tableVersionNode["Table"].asString();
  171. if(!tableVersionNode["VersionId"].isNull())
  172. tablesObject.tableVersion.versionId = std::stoi(tableVersionNode["VersionId"].asString());
  173. tables_.push_back(tablesObject);
  174. }
  175. if(!value["Code"].isNull())
  176. code_ = value["Code"].asString();
  177. if(!value["Message"].isNull())
  178. message_ = value["Message"].asString();
  179. if(!value["Success"].isNull())
  180. success_ = value["Success"].asString() == "true";
  181. }
  182. std::string BatchGetTablesResult::getMessage()const
  183. {
  184. return message_;
  185. }
  186. std::vector<BatchGetTablesResult::TableErrorsItem> BatchGetTablesResult::getTableErrors()const
  187. {
  188. return tableErrors_;
  189. }
  190. std::vector<BatchGetTablesResult::TablesItem> BatchGetTablesResult::getTables()const
  191. {
  192. return tables_;
  193. }
  194. std::string BatchGetTablesResult::getCode()const
  195. {
  196. return code_;
  197. }
  198. bool BatchGetTablesResult::getSuccess()const
  199. {
  200. return success_;
  201. }