行操作
更新时间:2023-11-22
单条写入
描述
写入一行数据。
请求参数
参数名称 | 参数类型 | 说明 |
---|---|---|
instance_name | String | 实例名称 |
table_name | String | 表的名称 |
row | Row | 期望写入的行 |
+rowkey | String | 行主键 |
+cells | List | 每个column,value对的列表 |
++column | String | 列名,命名规则满足正则[a-zA-Z_][a-za-z0-9\_]{0,254} |
++value | String | 列值 |
返回参数
无
示例
Plain Text
1# 示例1
2if __name__ == "__main__":
3 client = BtsClient(bts_sample_conf.config)
4 instance_name = b'instance1'
5 table_name = b'tab01'
6 row = Row()
7 row.rowkey = "row1"
8 cell1 = Cell("c1", "v1_1")
9 cell2 = Cell("c2", "v2_1")
10 cells = [cell1.__dict__, cell2.__dict__]
11 row.cells = cells
12 try:
13 response = client.put_row(instance_name, table_name, row)
14 print(response)
15 except Exception as e:
16 print(e)
17# 示例2
18if __name__ == "__main__":
19 client = BtsClient(bts_sample_conf.config)
20 instance_name = b'instance1'
21 table_name = b'tab01'
22 row = Row()
23 row.rowkey = "row1"
24 cell1 = Cell("c1", "v1_1")
25 cell2 = Cell("c2", "v2_1")
26 cells = [cell1, cell2]
27 row.cells = cells
28 try:
29 response = client.put_row(instance_name, table_name, row)
30 print(response)
31 except Exception as e:
32 print(e)
批量写入
描述
批量写入多行数据。
请求参数
参数名称 | 参数类型 | 说明 |
---|---|---|
instance_name | String | 实例名称 |
table_name | String | 表的名称 |
batch_put_row | BatchPutRowArgs | 期望写入的行 |
+rows | List | 期望写入的行列表 |
++rowkey | String | 行主键 |
++cells | List |
每个column,value对的列表 |
+++column | String | 列名,命名规则满足正则[a-zA-Z_][a-za-z0-9\_]{0,254} |
+++value | String | 列值 |
返回参数
无
示例
Plain Text
1# 示例1
2if __name__ == "__main__":
3 client = BtsClient(bts_sample_conf.config)
4 instance_name = b'instance1'
5 table_name = b'tab01'
6 batch_put_row = BatchPutRowArgs()
7 for i in range(1, 15):
8 row = Row()
9 row.rowkey = "row" + str(i)
10 for j in range(3):
11 col = "c" + str(j)
12 val = "v" + str(j) + "_1"
13 cell = Cell(col, val)
14 row.cells.append(cell.__dict__)
15 batch_put_row.rows.append(row.__dict__)
16 try:
17 response = client.batch_put_row(instance_name, table_name, batch_put_row)
18 print(response)
19 except Exception as e:
20 print(e)
21 # 示例2
22 if __name__ == "__main__":
23 client = BtsClient(bts_sample_conf.config)
24 instance_name = b'instance1'
25 table_name = b'tab01'
26 batch_put_row = BatchPutRowArgs()
27 for i in range(1, 15):
28 row = Row()
29 row.rowkey = "row" + str(i)
30 for j in range(3):
31 col = "c" + str(j)
32 val = "v" + str(j) + "_1"
33 cell = Cell(col, val)
34 row.cells.append(cell)
35 batch_put_row.rows.append(row)
36 try:
37 response = client.batch_put_row(instance_name, table_name, batch_put_row)
38 print(response)
39 except Exception as e:
40 print(e)
单条删除
描述
删除一整行数据或该行数据的部分列。
请求参数
参数名称 | 参数类型 | 说明 |
---|---|---|
instance_name | String | 实例名称 |
table_name | String | 表的名称 |
query_row_args | QueryRowArgs | 指定要删除的行 |
+rowkey | String | 主键 |
+cells | List | 待删除column列表,不写默认返回全部列 |
++column | String | 待删除的列名称 |
返回参数
无
示例
Plain Text
1# 示例1
2if __name__ == "__main__":
3 client = BtsClient(bts_sample_conf.config)
4 instance_name = b'instance1'
5 table_name = b'tab01'
6 query_row_args = QueryRowArgs()
7 query_row_args.rowkey = "row1"
8 cell1 = QueryCell()
9 cell1.column = "c1"
10 query_row_args.cells.append(cell1.__dict__)
11 try:
12 response = client.delete_row(instance_name, table_name, query_row_args)
13 print(response)
14 except Exception as e:
15 print(e)
16# 示例2
17if __name__ == "__main__":
18 client = BtsClient(bts_sample_conf.config)
19 instance_name = b'instance1'
20 table_name = b'tab01'
21 query_row_args = QueryRowArgs()
22 query_row_args.rowkey = "row1"
23 cell1 = QueryCell()
24 cell1.column = "c1"
25 query_row_args.cells.append(cell1)
26 try:
27 response = client.delete_row(instance_name, table_name, query_row_args)
28 print(response)
29 except Exception as e:
30 print(e)
批量删除
描述
批量删除若干行数据。
请求参数
参数名称 | 参数类型 | 说明 |
---|---|---|
instance_name | String | 实例名称 |
table_name | String | 表的名称 |
batch_query_row_args | BatchQueryRowArgs | 指定要删除的所有行 |
+rows | List | 指定要删除的行列表 |
++rowkey | String | 主键 |
++cells | List |
待删除column列表,不写默认返回全部列 |
+++column | String | 待删除的列名称 |
返回参数
无
示例
Plain Text
1# 示例1
2if __name__ == "__main__":
3 client = BtsClient(bts_sample_conf.config)
4 instance_name = b'instance1'
5 table_name = b'tab01'
6 batch_query_row_args = BatchQueryRowArgs()
7 query_row_args1 = QueryRowArgs()
8 query_row_args1.rowkey = "row1"
9 query_row_args1.cells.append(QueryCell("c0").__dict__)
10 query_row_args1.cells.append(QueryCell("c1").__dict__)
11 batch_query_row_args.rows.append(query_row_args1.__dict__)
12 query_row_args2 = QueryRowArgs()
13 query_row_args2.rowkey = "row2"
14 query_row_args2.cells.append(QueryCell("c1").__dict__)
15 query_row_args2.cells.append(QueryCell("c2").__dict__)
16 batch_query_row_args.rows.append(query_row_args2.__dict__)
17 try:
18 response = client.batch_delete_row(instance_name, table_name, batch_query_row_args)
19 print(response)
20 except Exception as e:
21 print(e)
22# 示例2
23 if __name__ == "__main__":
24 client = BtsClient(bts_sample_conf.config)
25 instance_name = b'instance1'
26 table_name = b'tab01'
27 batch_query_row_args = BatchQueryRowArgs()
28 query_row_args1 = QueryRowArgs()
29 query_row_args1.rowkey = "row1"
30 query_row_args1.cells.append(QueryCell("c0"))
31 query_row_args1.cells.append(QueryCell("c1"))
32 batch_query_row_args.rows.append(query_row_args1)
33 query_row_args2 = QueryRowArgs()
34 query_row_args2.rowkey = "row2"
35 query_row_args2.cells.append(QueryCell("c1"))
36 query_row_args2.cells.append(QueryCell("c2"))
37 batch_query_row_args.rows.append(query_row_args2)
38 try:
39 response = client.batch_delete_row(instance_name, table_name, batch_query_row_args)
40 print(response)
41 except Exception as e:
42 print(e)
单条随机读
描述
查询一行,或一行中的某些列。
请求参数
参数名称 | 参数类型 | 说明 |
---|---|---|
instance_name | String | 实例名称 |
table_name | String | 表的名称 |
query_row_args | QueryRowArg | 指定要查询的行 |
+rowkey | String | 主键 |
+max_versions | int | 指定读取的最大版本数。设置该值后,用户可读取之前的版本到最新版本之间共maxVersions个版本的数据 |
+cells | List |
待查询column列表,不写默认返回全部列 |
++column | String | 待查询的列名称 |
返回参数
参数名称 | 参数类型 | 说明 |
---|---|---|
rowkey | String | 主键 |
cells | List |
cell列表 |
+column | String | 列名 |
+value | String | 列值 |
+timestamp | long | 时间戳 |
示例
Plain Text
1# 示例1
2if __name__ == "__main__":
3 client = BtsClient(bts_sample_conf.config)
4 instance_name = b'instance1'
5 table_name = b'tab01'
6 query_row_args = QueryRowArgs()
7 query_row_args.rowkey = "row1"
8 query_row_args.cells.append(QueryCell("c1").__dict__)
9 query_row_args.cells.append(QueryCell("c2").__dict__)
10 query_row_args.max_versions = 2
11 try:
12 response = client.get_row(instance_name, table_name, query_row_args)
13 if response.result is not None:
14 print("rowkey: " + response.result[0].rowkey)
15 for i in range(len(response.result[0].cells)):
16 print(" column: " + response.result[0].cells[i].column)
17 print(" value: " + response.result[0].cells[i].value)
18 print(" timestamp: " + str(response.result[0].cells[i].timestamp))
19 except Exception as e:
20 print(e)
21# 示例2
22if __name__ == "__main__":
23 client = BtsClient(bts_sample_conf.config)
24 instance_name = b'instance1'
25 table_name = b'tab01'
26 query_row_args = QueryRowArgs()
27 query_row_args.rowkey = "row1"
28 query_row_args.cells.append(QueryCell("c1"))
29 query_row_args.cells.append(QueryCell("c2"))
30 query_row_args.max_versions = 2
31 try:
32 response = client.get_row(instance_name, table_name, query_row_args)
33 if response.result is not None:
34 print("rowkey: " + response.result[0].rowkey)
35 for i in range(len(response.result[0].cells)):
36 print(" column: " + response.result[0].cells[i].column)
37 print(" value: " + response.result[0].cells[i].value)
38 print(" timestamp: " + str(response.result[0].cells[i].timestamp))
39 except Exception as e:
40 print(e)
批量随机读
描述
批量查询一行,或一行中的某些列。
请求参数
参数名称 | 参数类型 | 说明 |
---|---|---|
instance_name | String | 实例名称 |
table_name | String | 表的名称 |
batch_query_row_args | BatchQueryRowArgs | 指定要查询的所有行 |
+rows | List | 指定要查询的行列表 |
++rowkey | String | 主键 |
++max_versions | int | 指定读取的最大版本数。设置该值后,用户可读取之前的版本到最新版本之间共maxVersions个版本的数据 |
++cells | List |
待查询column列表,不写默认返回全部列 |
+++column | String | 待查询的列名称 |
返回参数
参数名称 | 参数类型 | 说明 |
---|---|---|
results | List | 结果列表 |
+rowkey | String | 主键 |
+cells | List | cell列表 |
++column | String | 列名 |
++value | String | 列值 |
++timestamp | long | 时间戳 |
示例
Plain Text
1# 示例1
2if __name__ == "__main__":
3 client = BtsClient(bts_sample_conf.config)
4 instance_name = b'instance1'
5 table_name = b'tab01'
6 batch_query_row_args = BatchQueryRowArgs()
7 batch_query_row_args.max_versions = 2
8 query_row_args1 = QueryRowArgs()
9 query_row_args1.rowkey = "row12"
10 query_row_args1.cells.append(QueryCell("c0").__dict__)
11 query_row_args1.cells.append(QueryCell("c1").__dict__)
12 batch_query_row_args.rows.append(query_row_args1.__dict__)
13 query_row_args2 = QueryRowArgs()
14 query_row_args2.rowkey = "row13"
15 query_row_args2.cells.append(QueryCell("c1").__dict__)
16 query_row_args2.cells.append(QueryCell("c2").__dict__)
17 batch_query_row_args.rows.append(query_row_args2.__dict__)
18 try:
19 response = client.batch_get_row(instance_name, table_name, batch_query_row_args)
20 if response.result is not None:
21 for i in range(len(response.result)):
22 print("rowkey: " + response.result[i].rowkey)
23 for j in range(len(response.result[i].cells)):
24 print(" column: " + response.result[i].cells[j].column)
25 print(" value: " + response.result[i].cells[j].value)
26 print(" timestamp: " + str(response.result[i].cells[j].timestamp))
27 except Exception as e:
28 print(e)
29# 示例2
30if __name__ == "__main__":
31 client = BtsClient(bts_sample_conf.config)
32 instance_name = b'instance1'
33 table_name = b'tab01'
34 batchQueryRowArgs1 = BatchQueryRowArgs()
35 batchQueryRowArgs1.max_versions = 2
36
37 queryRowArgs1 = QueryRowArgs()
38 queryRowArgs1.rowkey = "row2"
39 queryRowArgs1.cells.append(QueryCell("p1"))
40 batchQueryRowArgs1.rows.append(queryRowArgs1)
41
42 queryRowArgs2 = QueryRowArgs()
43 queryRowArgs2.rowkey = "row3"
44 queryRowArgs2.cells.append(QueryCell("c2"))
45 batchQueryRowArgs1.rows.append(queryRowArgs2)
46
47 try:
48 response = client.batch_get_row(instance_name, table_name, batchQueryRowArgs1)
49 if response.result is not None:
50 for i in range(len(response.result)):
51 print("rowkey: " + response.result[i].rowkey)
52 for j in range(len(response.result[i].cells)):
53 print(" column: " + response.result[i].cells[j].column)
54 print(" value: " + response.result[i].cells[j].value)
55 print(" timestamp: " + str(response.result[i].cells[j].timestamp))
56 except exception.BceError as e:
57 __logger.debug(e)
区间读
描述
扫描若干行数据。
请求参数
参数名称 | 参数类型 | 说明 |
---|---|---|
instance_name | String | 实例名称 |
table_name | String | 表的名称 |
scan_args | ScanArgs | 查询参数 |
+start_rowkey | String | scan的起始rowkey,默认表的第一个rowkey |
+include_start | boolean | 是否包含起始rowkey,默认包含 |
+stop_rowkey | String | scan的终止rowkey,默认表的最后一个rowkey |
+include_stop | boolean | 是否包含终止rowkey,默认不包含 |
+selector | List | 待查询的column列表,不写默认返回全部列 |
++column | String | 待查询的列名称 |
+limit | int | 限定查询行数,其值必须为整型,设为其他类型无效 |
+max_versions | int | 指定读取的最大版本数。设置该值后,用户可读取之前的版本到最新版本之间共maxVersions个版本的数据 |
返回参数
参数名称 | 参数类型 | 说明 |
---|---|---|
results | List |
结果列表 |
+rowkey | String | 主键 |
+cells | List |
cell列表 |
++column | String | 列名 |
++value | String | 列值 |
++timestamp | long | 时间戳 |
next_start_key | String | 若本次扫描未结束,返回下一次扫描的起始key,用户应用此值发起下一次scan操作 |
示例
Plain Text
1# 示例1
2if __name__ == "__main__":
3 client = BtsClient(bts_sample_conf.config)
4 instance_name = b'instance1'
5 table_name = b'tab01'
6 scan_args = ScanArgs()
7 scan_args.start_rowkey = "row10"
8 scan_args.include_start = "true"
9 scan_args.stop_rowkey = "row14"
10 scan_args.include_stop = "false"
11 scan_args.selector.append(QueryCell("c0").__dict__)
12 scan_args.selector.append(QueryCell("c1").__dict__)
13 scan_args.selector.append(QueryCell("c2").__dict__)
14 scan_args.max_versions = 2
15 scan_args.limit = 20
16 try:
17 response = client.scan(instance_name, table_name, scan_args)
18 if response.result is not None:
19 for i in range(len(response.result)):
20 print("rowkey: " + response.result[i].rowkey)
21 for j in range(len(response.result[i].cells)):
22 print(" column: " + response.result[i].cells[j].column)
23 print(" value: " + response.result[i].cells[j].value)
24 print(" timestamp: " + str(response.result[i].cells[j].timestamp))
25 except Exception as e:
26 print(e)
27 # 示例2
28 if __name__ == "__main__":
29 client = BtsClient(bts_sample_conf.config)
30 instance_name = b'instance1'
31 table_name = b'tab01'
32 scan_args = ScanArgs()
33 scan_args.start_rowkey = "row1"
34 scan_args.include_start = "true"
35 scan_args.stop_rowkey = "row5"
36 scan_args.include_stop = "false"
37 scan_args.selector.append(QueryCell("c0"))
38 scan_args.selector.append(QueryCell("c1"))
39 scan_args.max_versions = 2
40 try:
41 response = client.scan(instance_name, table_name, scan_args)
42 if response.result is not None:
43 for i in range(len(response.result)):
44 print("rowkey: " + response.result[i].rowkey)
45 for j in range(len(response.result[i].cells)):
46 print(" column: " + response.result[i].cells[j].column)
47 print(" value: " + response.result[i].cells[j].value)
48 print(" timestamp: " + str(response.result[i].cells[j].timestamp))
49 except Exception as e:
50 print(e)