Skip to content

Commit fee8818

Browse files
committed
Add sample for put/fetch rows with DataFrame.
- PutRowsWithDataFrame.py : sample for put rows. - FetchRowsWithDataFrame.py : sample for fetch rows.
1 parent 37297ad commit fee8818

File tree

2 files changed

+87
-0
lines changed

2 files changed

+87
-0
lines changed

sample/FetchRowsWithDataFrame.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#!/usr/bin/python
2+
3+
import griddb_python as griddb
4+
import sys
5+
import pandas
6+
7+
factory = griddb.StoreFactory.get_instance()
8+
9+
argv = sys.argv
10+
11+
blob = bytearray([65, 66, 67, 68, 69, 70, 71, 72, 73, 74])
12+
containerName = "SamplePython_FetchRows"
13+
update = False
14+
15+
try:
16+
# Get GridStore object
17+
gridstore = factory.get_store(host=argv[1], port=int(argv[2]), cluster_name=argv[3], username=argv[4], password=argv[5])
18+
19+
# Create Collection
20+
conInfo = griddb.ContainerInfo(containerName,
21+
[["name", griddb.Type.STRING],
22+
["status", griddb.Type.BOOL],
23+
["count", griddb.Type.LONG],
24+
["lob", griddb.Type.BLOB]],
25+
griddb.ContainerType.COLLECTION, True)
26+
col = gridstore.put_container(conInfo)
27+
print("Create Collection name=", containerName)
28+
29+
# Put rows
30+
rows = pandas.DataFrame([["name01", True, 1, blob], ["name02", False, 2, blob]])
31+
col.put_rows(rows)
32+
print("Put rows with DataFrame")
33+
34+
# Fetch rows
35+
query = col.query("select *")
36+
rs = query.fetch(update)
37+
print("Fetch rows with DataFrame")
38+
result = rs.fetch_rows()
39+
print(result)
40+
print("Success!")
41+
42+
except griddb.GSException as e:
43+
for i in range(e.get_error_stack_size()):
44+
print("[", i, "]")
45+
print(e.get_error_code(i))
46+
print(e.get_location(i))
47+
print(e.get_message(i))

sample/PutRowsWithDataFrame.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#!/usr/bin/python
2+
3+
import griddb_python as griddb
4+
import sys
5+
import pandas
6+
7+
factory = griddb.StoreFactory.get_instance()
8+
9+
argv = sys.argv
10+
11+
blob = bytearray([65, 66, 67, 68, 69, 70, 71, 72, 73, 74])
12+
update = False
13+
containerName = "SamplePython_PutRows"
14+
15+
try:
16+
# Get GridStore object
17+
gridstore = factory.get_store(host=argv[1], port=int(argv[2]), cluster_name=argv[3], username=argv[4], password=argv[5])
18+
19+
# Create Collection
20+
conInfo = griddb.ContainerInfo(containerName,
21+
[["name", griddb.Type.STRING],
22+
["status", griddb.Type.BOOL],
23+
["count", griddb.Type.LONG],
24+
["lob", griddb.Type.BLOB]],
25+
griddb.ContainerType.COLLECTION, True)
26+
col = gridstore.put_container(conInfo)
27+
print("Create Collection name=", containerName)
28+
29+
# Put rows
30+
rows = pandas.DataFrame([["name01", False, 1, blob], ["name02", False, 1, blob]])
31+
col.put_rows(rows)
32+
print("Put rows with DataFrame")
33+
print("Success!")
34+
35+
except griddb.GSException as e:
36+
for i in range(e.get_error_stack_size()):
37+
print("[", i, "]")
38+
print(e.get_error_code(i))
39+
print(e.get_location(i))
40+
print(e.get_message(i))

0 commit comments

Comments
 (0)