阅读323 返回首页    go iPhone_iPad_Mac_手机_平板_苹果apple


BatchGetRow__API 概览_API 参考_表格存储-阿里云

行为:

批量读取一个或多个表中的若干行数据。

BatchGetRow 操作可视为多个 GetRow 操作的集合,各个操作独立执行,独立返回结果,独立计算服务能力单元。

与执行大量的 GetRow 操作相比,使用 BatchGetRow 操作可以有效减少请求的响应时间,提高数据的读取速率。

请求结构:

  1. message BatchGetRowRequest {
  2. repeated TableInBatchGetRowRequest tables = 1;
  3. }

tables:

  • 类型:repeated TableInBatchGetRowRequest

  • 是否必要参数:是。

  • 指定了需要要读取的行信息。

  • 若 tables 中出现了下述情况,则操作整体失败,返回错误。

    • tables 中任一表不存在。

    • tables 中任一表名不符合表名命名规范

    • tables 中任一行未指定主键、主键名称不符合规范或者主键类型不正确。

    • tables 中任一表的 columns_to_get 内的列名不符合列名命名规范

    • tables 中包含同名的表。

    • tables 中任一表内包含主键完全相同的行。

    • 所有 tables 中 RowInBatchGetRowRequest 的总个数超过 100 个。

    • tables 中任一表内不包含任何 RowInBatchGetRowRequest。

    • tables 中任一表的 columns_to_get 超过 128 列。

响应消息结构:

  1. message BatchGetRowResponse {
  2. repeated TableInBatchGetRowResponse tables = 1;
  3. }

tables:

  • 类型:repeated TableInBatchGetRowResponse

  • 对应了每个 table 下读取到的数据。

  • 响应消息中 TableInBatchGetRowResponse 对象的顺序与 BatchGetRowRequest 中的 TableInBatchGetRowRequest 对象的顺序相同;每个 TableInBatchGetRowResponse 下面的 RowInBatchGetRowResponse 对象的顺序与 TableInBatchGetRowRequest 下面的 RowInBatchGetRowRequest 相同。

  • 如果某行不存在或者某行在指定的 columns_to_get 下没有数据,仍然会在 TableInBatchGetRowResponse 中有一条对应的 RowInBatchGetRowResponse,但其 row 下面的 primary_key_columns 和 attribute_columns 将为空。

  • 若某行读取失败,该行所对应的 RowInBatchGetRowResponse 中 is_ok 将为 false,此时 row 将为空。

注意:BatchGetRow 操作可能会在行级别部分失败,此时返回的 HTTP 状态码仍为 200。应用程序必须对 RowInBatchGetRowResponse 中的 error 进行检查确认每一行的执行结果,并进行相应的处理。

服务能力单元消耗:

  • 如果本次操作整体失败,不消耗任何服务能力单元。

  • 如果请求超时,结果未定义,服务能力单元有可能被消耗,也可能未被消耗。

  • 其他情况将每个 RowInBatchGetRowRequest 视为一个 GetRow 操作独立计算写服务能力单元,GetRow服务能力单元消耗

请求示例:

  1. BatchGetRowRequest {
  2. tables {
  3. table_name: "consume_history"
  4. rows {
  5. primary_key {
  6. name: "CardID"
  7. value {
  8. type: STRING
  9. v_string: "2007035023"
  10. }
  11. }
  12. primary_key {
  13. name: "SellerID"
  14. value {
  15. type: STRING
  16. v_string: "00022"
  17. }
  18. }
  19. primary_key {
  20. name: "DeviceID"
  21. value {
  22. type: STRING
  23. v_string: "061104"
  24. }
  25. }
  26. primary_key {
  27. name: "OrderNumber"
  28. value {
  29. type: INTEGER
  30. v_int: 142857
  31. }
  32. }
  33. }
  34. rows {
  35. primary_key {
  36. name: "CardID"
  37. value {
  38. type: STRING
  39. v_string: "2007035023"
  40. }
  41. }
  42. primary_key {
  43. name: "SellerID"
  44. value {
  45. type: STRING
  46. v_string: "00026"
  47. }
  48. }
  49. primary_key {
  50. name: "DeviceID"
  51. value {
  52. type: STRING
  53. v_string: "065499"
  54. }
  55. }
  56. primary_key {
  57. name: "OrderNumber"
  58. value {
  59. type: INTEGER
  60. v_int: 153846
  61. }
  62. }
  63. }
  64. columns_to_get: "CardID"
  65. columns_to_get: "SellerID"
  66. columns_to_get: "DeviceID"
  67. columns_to_get: "OrderNumber"
  68. columns_to_get: "Amount"
  69. columns_to_get: "Remarks"
  70. }
  71. }

响应示例:

  1. BatchGetRowResponse {
  2. tables {
  3. table_name: "consume_history"
  4. rows {
  5. is_ok: true
  6. consumed {
  7. capacity_unit {
  8. read: 1
  9. }
  10. }
  11. row {
  12. primary_key_columns {
  13. name: "CardID"
  14. value {
  15. type: STRING
  16. v_string: "2007035023"
  17. }
  18. }
  19. primary_key_columns {
  20. name: "SellerID"
  21. value {
  22. type: STRING
  23. v_string: "00022"
  24. }
  25. }
  26. primary_key_columns {
  27. name: "DeviceID"
  28. value {
  29. type: STRING
  30. v_string: "061104"
  31. }
  32. }
  33. primary_key_columns {
  34. name: "OrderNumber"
  35. value {
  36. type: INTEGER
  37. v_int: 142857
  38. }
  39. }
  40. attribute_columns {
  41. name: "Amount"
  42. value {
  43. type: DOUBLE
  44. v_double: 2.5
  45. }
  46. }
  47. attribute_columns {
  48. name: "Remarks"
  49. value {
  50. type: STRING
  51. v_string: "ice cream"
  52. }
  53. }
  54. }
  55. }
  56. rows {
  57. is_ok: true
  58. consumed {
  59. capacity_unit {
  60. read: 1
  61. }
  62. }
  63. row {
  64. primary_key_columns {
  65. name: "CardID"
  66. value {
  67. type: STRING
  68. v_string: "2007035023"
  69. }
  70. }
  71. primary_key_columns {
  72. name: "SellerID"
  73. value {
  74. type: STRING
  75. v_string: "00026"
  76. }
  77. }
  78. primary_key_columns {
  79. name: "DeviceID"
  80. value {
  81. type: STRING
  82. v_string: "065499"
  83. }
  84. }
  85. primary_key_columns {
  86. name: "OrderNumber"
  87. value {
  88. type: INTEGER
  89. v_int: 153846
  90. }
  91. }
  92. attribute_columns {
  93. name: "Amount"
  94. value {
  95. type: DOUBLE
  96. v_double: 0.5
  97. }
  98. }
  99. }
  100. }
  101. }
  102. }

最后更新:2016-11-23 16:03:56

  上一篇:go GetRange__API 概览_API 参考_表格存储-阿里云
  下一篇:go BatchWriteRow__API 概览_API 参考_表格存储-阿里云