Skip to content

Commit 93e481f

Browse files
committed
add sample codes for main features
1 parent 62b5266 commit 93e481f

18 files changed

+963
-0
lines changed

sample/ArrayData.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#!/usr/bin/python
2+
3+
import griddb_python as griddb
4+
import sys
5+
6+
factory = griddb.StoreFactory.get_instance()
7+
8+
argv = sys.argv
9+
10+
try:
11+
12+
# Get GridStore object
13+
gridstore = factory.get_store(host=argv[1], port=int(argv[2]), cluster_name=argv[3], username=argv[4], password=argv[5])
14+
15+
# When operations such as container creation and acquisition are performed, it is connected to the cluster.
16+
gridstore.get_container("containerName")
17+
print("Connect to Cluster")
18+
19+
# Create Collection
20+
conInfo = griddb.ContainerInfo(name="SamplePython_ArrayData",
21+
column_info_list=
22+
[["id", griddb.Type.INTEGER],
23+
["string_array", griddb.Type.STRING_ARRAY],
24+
["integer_array", griddb.Type.INTEGER_ARRAY]],
25+
type=griddb.ContainerType.COLLECTION,
26+
row_key=True)
27+
28+
col = gridstore.put_container(conInfo)
29+
print("Create Collection name=SamplePython_ArrayData")
30+
31+
# Register array type data
32+
# (1)Array type data
33+
stringArray = ["Sales", "Development", "Marketing", "Research"]
34+
integerArray = [39, 92, 18, 51 ]
35+
# (2)Register a row
36+
col.put([0, stringArray, integerArray])
37+
print("Put Row (Array)")
38+
39+
# Get array type data
40+
row = col.get(0)
41+
print("Get Row ", row)
42+
print("success!")
43+
44+
except griddb.GSException as e:
45+
for i in range(e.get_error_stack_size()):
46+
print("[", i, "]")
47+
print(e.get_error_code(i))
48+
print(e.get_location(i))
49+
print(e.get_message(i))

sample/BlobData.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#!/usr/bin/python
2+
3+
import griddb_python as griddb
4+
import sys
5+
import os
6+
factory = griddb.StoreFactory.get_instance()
7+
8+
argv = sys.argv
9+
10+
try:
11+
12+
# Get GridStore object
13+
gridstore = factory.get_store(host=argv[1], port=int(argv[2]), cluster_name=argv[3], username=argv[4], password=argv[5])
14+
15+
# When operations such as container creation and acquisition are performed, it is connected to the cluster.
16+
gridstore.get_container("containerName")
17+
print("Connect to Cluster")
18+
19+
# Create Collection
20+
conInfo = griddb.ContainerInfo(name="SamplePython_BlobData",
21+
column_info_list=
22+
[["id", griddb.Type.INTEGER],
23+
["blob", griddb.Type.BLOB]],
24+
type=griddb.ContainerType.COLLECTION,
25+
row_key=True)
26+
27+
col = gridstore.put_container(conInfo)
28+
print("Create Collection name=SamplePython_BlobData")
29+
30+
# Register binary
31+
# (1)Read binary file
32+
f = open("BlobData.py","rb")
33+
blobString = f.read().decode("utf-8")
34+
f.close()
35+
36+
# (2)Register a row
37+
col.put([0, blobString])
38+
print("Put Row (Blob)")
39+
40+
# Get binary
41+
row = col.get(0);
42+
print("Get Row (Blod string = ", row[1])
43+
print("success!")
44+
45+
except griddb.GSException as e:
46+
for i in range(e.get_error_stack_size()):
47+
print("[", i, "]")
48+
print(e.get_error_code(i))
49+
print(e.get_location(i))
50+
print(e.get_message(i))

sample/Connect.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/usr/bin/python
2+
3+
import griddb_python as griddb
4+
import sys
5+
import os
6+
factory = griddb.StoreFactory.get_instance()
7+
8+
argv = sys.argv
9+
10+
try:
11+
12+
# (1)Get GridStore object
13+
# Multicast method
14+
gridstore = factory.get_store(host=argv[1], port=int(argv[2]), cluster_name=argv[3], username=argv[4], password=argv[5])
15+
16+
# Fixed list method
17+
#gridstore = factory.get_store(notification_member=argv[1], cluster_name=argv[2], username=argv[3], password=argv[4])
18+
19+
# Provider method
20+
#gridstore = factory.get_store(notification_provider=argv[1], cluster_name=argv[2], username=argv[3], password=argv[4])
21+
22+
# (2)When operations such as container creation and acquisition are performed, it is connected to the cluster.
23+
gridstore.get_container("containerName")
24+
print("Connect to Cluster")
25+
print("success!")
26+
27+
except griddb.GSException as e:
28+
for i in range(e.get_error_stack_size()):
29+
print("[", i, "]")
30+
print(e.get_error_code(i))
31+
print(e.get_location(i))
32+
print(e.get_message(i))

sample/ContainerInformation.py

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#!/usr/bin/python
2+
3+
import griddb_python as griddb
4+
import sys
5+
6+
factory = griddb.StoreFactory.get_instance()
7+
8+
argv = sys.argv
9+
10+
try:
11+
12+
# Get GridStore object
13+
gridstore = factory.get_store(host=argv[1], port=int(argv[2]), cluster_name=argv[3], username=argv[4], password=argv[5])
14+
15+
# When operations such as container creation and acquisition are performed, it is connected to the cluster.
16+
gridstore.get_container("containerName")
17+
print("Connect to Cluster")
18+
19+
# Create Collection
20+
conInfo = griddb.ContainerInfo(name="SamplePython_Info",
21+
column_info_list=
22+
[["id", griddb.Type.INTEGER],
23+
["productName", griddb.Type.STRING],
24+
["count", griddb.Type.INTEGER]],
25+
type=griddb.ContainerType.COLLECTION,
26+
row_key=True)
27+
28+
col = gridstore.put_container(conInfo)
29+
print("Sample data generation: Create Collection name=SamplePython_Info")
30+
31+
# Get container information
32+
# (1)Get container information
33+
containerInfor = gridstore.get_container_info("SamplePython_Info")
34+
35+
# (2)Display container information
36+
print("Get ContainerInfo:\n name =", containerInfor.name)
37+
38+
if (containerInfor.type == griddb.ContainerType.COLLECTION):
39+
print(" type=Collection")
40+
else:
41+
print(" type=Timeseries")
42+
43+
print(" rowKeyAssigned=", containerInfor.row_key)
44+
45+
count = len(containerInfor.column_info_list)
46+
print(" columnCount=", count)
47+
48+
for i in range(0, count):
49+
print(" column (", containerInfor.column_info_list[i][0],",", containerInfor.column_info_list[i][1],")")
50+
print("success!")
51+
52+
except griddb.GSException as e:
53+
for i in range(e.get_error_stack_size()):
54+
print("[", i, "]")
55+
print(e.get_error_code(i))
56+
print(e.get_location(i))
57+
print(e.get_message(i))

sample/ContainerNames.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/usr/bin/python
2+
3+
import griddb_python as griddb
4+
import sys
5+
6+
factory = griddb.StoreFactory.get_instance()
7+
8+
argv = sys.argv
9+
10+
try:
11+
12+
#Get GridStore object
13+
gridstore = factory.get_store(host=argv[1], port=int(argv[2]), cluster_name=argv[3], username=argv[4], password=argv[5])
14+
gridstore.get_container("containerName")
15+
print("Connect to Cluster")
16+
17+
# Get a list of container names
18+
# (1)Get partition controller and number of partitions
19+
pc = gridstore.partition_info
20+
count = pc.partition_count
21+
# (2) Loop by the number of partitions to get a list of container names
22+
for i in range(0, count):
23+
list_container_names = pc.get_container_names(i, 0)
24+
for j in range(0, len(list_container_names)):
25+
print(list_container_names[j])
26+
27+
except griddb.GSException as e:
28+
for i in range(e.get_error_stack_size()):
29+
print("[", i, "]")
30+
print(e.get_error_code(i))
31+
print(e.get_location(i))
32+
print(e.get_message(i))

sample/CreateCollectionByMethod.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/usr/bin/python
2+
3+
import griddb_python as griddb
4+
import sys
5+
6+
factory = griddb.StoreFactory.get_instance()
7+
8+
argv = sys.argv
9+
10+
try:
11+
12+
# Get GridStore object
13+
gridstore = factory.get_store(host=argv[1], port=int(argv[2]), cluster_name=argv[3], username=argv[4], password=argv[5])
14+
15+
# When operations such as container creation and acquisition are performed, it is connected to the cluster.
16+
gridstore.get_container("containerName")
17+
print("Connect to Cluster")
18+
19+
# Create Collection
20+
conInfo = griddb.ContainerInfo(name="SamplePython_collection1",
21+
column_info_list=
22+
[["id", griddb.Type.INTEGER],
23+
["productName", griddb.Type.STRING],
24+
["columnInfo", griddb.Type.INTEGER]],
25+
type=griddb.ContainerType.COLLECTION,
26+
row_key=True)
27+
col = gridstore.put_container(conInfo)
28+
print("Create Collection name=SamplePython_collection1")
29+
print("success!")
30+
31+
except griddb.GSException as e:
32+
for i in range(e.get_error_stack_size()):
33+
print("[", i, "]")
34+
print(e.get_error_code(i))
35+
print(e.get_location(i))
36+
print(e.get_message(i))

sample/CreateIndex.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#!/usr/bin/python
2+
3+
import griddb_python as griddb
4+
import sys
5+
6+
factory = griddb.StoreFactory.get_instance()
7+
8+
argv = sys.argv
9+
containerName = "SamplePython_Index"
10+
11+
try:
12+
13+
# Get GridStore object
14+
gridstore = factory.get_store(host=argv[1], port=int(argv[2]), cluster_name=argv[3], username=argv[4], password=argv[5])
15+
16+
# When operations such as container creation and acquisition are performed, it is connected to the cluster.
17+
gridstore.get_container("containerName")
18+
print("Connect to Cluster")
19+
20+
# Create Collection
21+
conInfo = griddb.ContainerInfo(name=containerName,
22+
column_info_list=
23+
[["id", griddb.Type.INTEGER],
24+
["productName", griddb.Type.STRING],
25+
["count", griddb.Type.INTEGER]],
26+
type=griddb.ContainerType.COLLECTION,
27+
row_key=True)
28+
gridstore.drop_container(containerName)
29+
col = gridstore.put_container(conInfo)
30+
print("Create Collection name=",containerName)
31+
32+
# Get the container
33+
col1 = gridstore.get_container(containerName)
34+
if col1 == None:
35+
print( "ERROR Container not found. name=",containerName)
36+
37+
# Create an index
38+
col1.create_index(column_name="count", index_type=griddb.IndexType.HASH, name="hash_index")
39+
print("Create Index")
40+
41+
print("success!")
42+
43+
except griddb.GSException as e:
44+
for i in range(e.get_error_stack_size()):
45+
print("[", i, "]")
46+
print(e.get_error_code(i))
47+
print(e.get_location(i))
48+
print(e.get_message(i))

sample/CreateTimeSeriesByMethod.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/usr/bin/python
2+
3+
import griddb_python as griddb
4+
import sys
5+
6+
factory = griddb.StoreFactory.get_instance()
7+
8+
argv = sys.argv
9+
10+
try:
11+
12+
# Get GridStore object
13+
gridstore = factory.get_store(host=argv[1], port=int(argv[2]), cluster_name=argv[3], username=argv[4], password=argv[5])
14+
15+
# When operations such as container creation and acquisition are performed, it is connected to the cluster.
16+
gridstore.get_container("containerName")
17+
print("Connect to Cluster")
18+
19+
# Create a timeseries container
20+
conInfo = griddb.ContainerInfo(name="SamplePython_timeseries1",
21+
column_info_list=
22+
[["date", griddb.Type.TIMESTAMP],
23+
["value", griddb.Type.DOUBLE]],
24+
type=griddb.ContainerType.TIME_SERIES)
25+
26+
ts = gridstore.put_container(conInfo)
27+
print("Create TimeSeries name=SamplePython_timeseries1")
28+
print("success!")
29+
30+
except griddb.GSException as e:
31+
for i in range(e.get_error_stack_size()):
32+
print("[", i, "]")
33+
print(e.get_error_code(i))
34+
print(e.get_location(i))
35+
print(e.get_message(i))

0 commit comments

Comments
 (0)