|
| 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)) |
0 commit comments