
Introduction In today’s competitive landscape, efficient customer support is essential for retaining customers and driving
Go Faster.
Grow Bigger.
Designed from the ground up to handle
When to use GridDB?
RDBMS can be used as the core for IoT and Big Data Systems, but often a hybrid approach with specialized databases like GridDB offers better performance, scalability, and efficiency.
GridDB’s hybrid composition of In-Memory and Disk architecture is designed for maximum performance. I/O is a common bottleneck in any DBMS that can cause the CPU to be under-utilized. GridDB overcomes this bottleneck with the ‘Memory first, Storage second’ structure where the ‘primary’ data that is frequently accessed resides in memory and the rest is passed on to disks (SSD and HDD).
Read the WhitepaperVarious architectural innovations, such as in-memory orientation with "memory as the main unit and disk as the secondary unit" and event-driven design with minimal overhead, have been incorporated to achieve processing capabilities that can handle petabyte-scale applications.
Read the WhitepaperGridDB’s Key Container data model and Time Series functions are built for IoT. The Key Container data model of GridDB extends the typical NoSQL Key-Value store. The Key Container model represents data in the form of collections that are referenced by keys. The key and container are rough equivalents of the table name and table data in Relational Databases (RDB). Data modeling in GridDB is easier than with other NoSQL databases as we can define the schema and design the data similar to that of an RDB.
Read the WhitepaperHybrid NoSQL Interface for Data Ingestion and SQL for Query
// for more information, please visit the docs
// https://docs.griddb.net/latest/gettingstarted/java/
import java.util.Properties;
import com.toshiba.mwcloud.gs.*;
Properties props = new Properties();
props.setProperty("notificationMember", "127.0.0.1:10001");
props.setProperty("clusterName", "myCluster");
props.setProperty("user", "admin");
props.setProperty("password", "admin");
GridStore store = GridStoreFactory.getInstance().getGridStore(props);
static class Point {
@RowKey Date timestamp;
boolean active;
double voltage;
}
TimeSeries ts = store.putTimeSeries("point01", Point.class);
Point point = new Point();
point.active = false;
point.voltage = 100;
// Store the time-series element (GridStore sets its timestamp)
ts.append(point);
Date now = TimestampUtils.current();
Date before = TimestampUtils.add(now, -6, TimeUnit.HOUR);
}
RowSet rs = ts.query(before, now).fetch();
while (rs.hasNext()) {
point = rs.next();
System.out.println(
"Time=" + TimestampUtils.format(point.timestamp) +
" Active=" + point.active +
" Voltage=" + point.voltage);
}
// for more information, please visit the docs
// https://docs.griddb.net/latest/jdbcdriver/introduction/
import java.util.Properties;
import java.sql.Connection;
import java.sql.DriverManager;
String notificationMember = "127.0.0.1:20001";
String clusterName = "myCluster";
String databaseName = "public";
String username = "admin";
String password = "admin";
String encodeClusterName = URLEncoder.encode(clusterName, "UTF-8");
String encodeDatabaseName = URLEncoder.encode(databaseName, "UTF-8");
String jdbcUrl = "jdbc:gs://" + notificationMember + "/";
jdbcUrl = jdbcUrl + encodeClusterName + "/" + encodeDatabaseName;
Properties prop = new Properties();
prop.setProperty("user", username);
prop.setProperty("password", password);
Connection con = DriverManager.getConnection(jdbcUrl, prop);
String str = "CREATE TABLE device";
str = str+"(ts TIMESTAMP PRIMARY KEY, co DOUBLE,";
str = str+"humidity DOUBLE,light BOOL,lpg DOUBLE,motion BOOL,smoke DOUBLE,temp DOUBLE)";
str = str+" USING TIMESERIES WITH (expiration_type='PARTITION',";
str = str+" expiration_time=90,expiration_time_unit='DAY')";
str = str+" PARTITION BY RANGE (ts) EVERY (60, DAY) SUBPARTITION BY HASH (ts) SUBPARTITIONS 64;";
Statement stmt = con.createStatement();
stmt.executeUpdate("DROP TABLE IF EXISTS device");
stmt.executeUpdate(str);
System.out.println("Successfully created device");
PreparedStatement pstmt = con.prepareStatement("INSERT into device14 (ts,co,humidity,light,lpg,motion,smoke,temp) VALUES (?,?,?,?,?,?,?,?) ");
pstmt.setTimestamp(1, new Timestamp(System.currentTimeMillis()));
pstmt.setDouble(2,0.002978);
pstmt.setDouble(3,52.2);
pstmt.setBoolean(4,false);
pstmt.setDouble(5,0.007938);
pstmt.setBoolean(6,true);
pstmt.setDouble(7,0.0368453);
pstmt.setDouble(8,23.9);
pstmt.execute();
PreparedStatement pstmt = con.prepareStatement("SELECT temp from device WHERE temp > ?");
pstmt.setDouble(1, 23.0);
ResultSet rs = pstmt.executeQuery();
while( rs.next() ){
double temp = rs.getDouble(1);
System.out.println("SQL Row temp: " + temp);
}
con.close();
# for more information, please visit the docs
# https://docs.griddb.net/latest/gettingstarted/python/
import griddb_python as griddb
factory = griddb.StoreFactory.get_instance()
DB_HOST = "127.0.0.1:10001"
DB_CLUSTER = "myCluster"
DB_USER = "admin"
DB_PASS = "admin"
try:
# Fixed list method
gridstore = factory.get_store(
notification_member=DB_HOST,
cluster_name=DB_CLUSTER,
username=DB_USER,
password=DB_PASS)
print("Succesfully connected to GridDB!")
except griddb.GSException as e:
for i in range(e.get_error_stack_size()):
print("[", i, "]")
print(e.get_error_code(i))
print(e.get_location(i))
print(e.get_message(i))
# Create the container
conInfo = griddb.ContainerInfo(name="device",
column_info_list=[["ts", griddb.Type.TIMESTAMP],
["co", griddb.Type.DOUBLE],
["humidity", griddb.Type.DOUBLE],
["light", griddb.Type.BOOL],
["lpg", griddb.Type.DOUBLE],
["motion", griddb.Type.BOOL],
["smoke", griddb.Type.DOUBLE],
["temperature", griddb.Type.DOUBLE]],
type=griddb.ContainerType.TIME_SERIES)
ts = gridstore.put_container(conInfo)
print(conInfo.name, "container succesfully created")
# (2) Insert Data
device = gridstore.get_container("device")
if device == None:
print("ERROR Container not found.")
device.put(["2022-09-21T12:00:01.234Z", 0.003551, 50.0,
False, 0.00754352, False, 0.0232432, 21.6])
print("Single row successfully inserted!")
query = device.query("SELECT *")
rs = query.fetch()
# Get results
while rs.has_next():
row = rs.next()
print("ts=", row[0], ", co=", row[1], ", humidity=", row[2], ",light=",row[3], ",lpg=", row[4], ",motion=", row[5], ",smoke=", row[6])
// for more information, please visit the docs
// https://docs.griddb.net/latest/gettingstarted/nodejs/
const griddb = require('griddb-node-api');
const factory = griddb.StoreFactory.getInstance();
const store = factory.getStore({
"notificationMember": "127.0.0.1:10001",
"clusterName": "myCluster",
"username": "admin",
"password": "admin"
});
const containerName = "device";
const conInfo = new griddb.ContainerInfo({
'name': containerName,
'columnInfoList': [
["ts", griddb.Type.TIMESTAMP],
["co", griddb.Type.DOUBLE],
["humidity", griddb.Type.DOUBLE],
["light", griddb.Type.BOOL],
["lpg", griddb.Type.DOUBLE],
["motion", griddb.Type.BOOL],
["smoke", griddb.Type.DOUBLE],
["temp", griddb.Type.DOUBLE],
],
'type': griddb.ContainerType.TIME_SERIES, 'rowKey': true
});
const getRandomFloat = (min, max) => Math.random() * (max - min) + min;
async function createContIngestData() {
const row = [];
row[0] = new Date();
row[1] = parseFloat(getRandomFloat(1, 10).toFixed(2));
row[2] = parseFloat(getRandomFloat(1, 10).toFixed(2));
row[3] = true;
row[4] = parseFloat(getRandomFloat(1, 10).toFixed(2));
row[5] = false;
row[6] = parseFloat(getRandomFloat(1, 10).toFixed(2));
row[7] = parseFloat(getRandomFloat(1, 10).toFixed(2));
try {
await store.dropContainer(containerName);
const cont = await store.putContainer(conInfo)
await cont.put(row);
} catch (error) {
console.log("error: ", error)
}
}
const queryStr = "SELECT *";
const queryCont = async (queryStr) => {
const data = []
try {
const ts = await store.getContainer(containerName);
const query = await ts.query(queryStr);
const rs = await query.fetch(query);
while(rs.hasNext()) {
data.push(rs.next())
}
console.log("Rows: ", data);
return data
} catch (error) {
console.log("Query Error: ", error)
}
}
// for more information, please visit the docs
// https://docs.griddb.net/latest/gettingstarted/go/
import griddb "github.com/griddb/go_client"
factory := griddb.StoreFactoryGetInstance()
// Get GridStore object
gridstore, err := factory.GetStore(map[string]interface{}{
"notification_member": "127.0.0.1:10001",
"cluster_name": "myCluster",
"username": "admin",
"password": "admin"})
if err != nil {
fmt.Println(err)
panic("err get store")
}
defer griddb_go.DeleteStore(gridstore)
conInfo, err := griddb_go.CreateContainerInfo(map[string]interface{} {
"name": "col01",
"column_info_list":[][]interface{}{
{"name", griddb_go.TYPE_STRING},
{"status", griddb_go.TYPE_BOOL},
{"count", griddb_go.TYPE_LONG},
{"lob", griddb_go.TYPE_BLOB}},
"type": griddb_go.CONTAINER_COLLECTION,
"row_key": true})
if (err != nil) {
fmt.Println("Create containerInfo failed, err:", err)
panic("err CreateContainerInfo")
}
defer griddb_go.DeleteContainerInfo(conInfo)
col, err := gridstore.PutContainer(conInfo)
if (err != nil) {
fmt.Println("put container failed, err:", err)
panic("err PutContainer")
}
defer griddb_go.DeleteContainer(col)
col.SetAutoCommit(false)
blob := []byte{65, 66, 67, 68, 69, 70, 71, 72, 73, 74}
err = col.Put([]interface{}{"name01", false, 1, blob})
if (err != nil) {
fmt.Println("put row name01 fail, err:", err)
}
col.Commit()
query, err := col.Query("select *")
if (err != nil) {
fmt.Println("create query failed, err:", err)
panic("err create query")
}
defer griddb_go.DeleteQuery(query)
// Execute query
rs, err := query.Fetch(update)
if (err != nil) {
fmt.Println("fetch failed, err:", err)
panic("err create rowset")
}
defer griddb_go.DeleteRowSet(rs)
for rs.HasNext() {
rrow, err := rs.NextRow()
if (err != nil) {
fmt.Println("NextRow from rs failed, err:", err)
panic("err NextRow from rowset")
}
rrow[2] = rrow[2].(int) + 1
fmt.Println("Person: name=", rrow[0]," status=", rrow[1]," count=", rrow[2]," lob=", rrow[3])
}
# For more information, please read the docs
# https://github.com/griddb/webapi/blob/master/GridDB_Web_API_Reference.md
#Connecting to GridDB
#Make an HTTP Request to the specified port (default: 8080)
#/:cluster/dbs/:database/checkConnection
$ curl -X GET --basic -u admin:admin http://127.0.0.1:8080/griddb/v2/myCluster/dbs/public/checkConnection
# http://[host]:[port]/griddb/v2/[clusterName]/dbs/public/containers
$ curl -X POST --basic -u admin:admin -H "Content-type:application/json" http://127.0.0.1:8080/griddb/v2/myCluster/dbs/public/containers -d
'{
"container_name": "test",
"container_type": "COLLECTION",
"rowkey": true,
"columns": [
{
"name": "col1",
"type": "STRING",
"index": [
"TREE"
]
},
{
"name": "col2",
"type": "INTEGER"
},
{
"name": "col3",
"type": "BOOL"
}
]
}'
# Append a Row of Data
# http://[host]:[port]/griddb/v2/[clusterName]/dbs/public/containers/[containerName]/rows
$ curl -X PUT --basic -u admin:admin -H "Content-type:application/json" http://127.0.0.1:8080/griddb/v2/myCluster/dbs/public/containers -d
'[["value", 1, true]]'
Introduction In today’s competitive landscape, efficient customer support is essential for retaining customers and driving