I’m using GridDB 5.3 with the Java client to store IoT sensor readings. Each reading is stored in a collection, and one of the columns contains a JSON payload as a string.
Here’s a minimal Java example of how I’m inserting the data:
Properties props = new Properties();
props.setProperty("host", "127.0.0.1");
props.setProperty("port", "10001");
props.setProperty("clusterName", "defaultCluster");
props.setProperty("user", "admin");
props.setProperty("password", "admin");
GridStore store = GridStoreFactory.getInstance().getGridStore(props);
ContainerInfo info = new ContainerInfo();
info.setName("sensor_data");
info.setType(ContainerType.COLLECTION);
info.setColumnInfoList(Arrays.asList(
new ColumnInfo("id", GSType.INTEGER),
new ColumnInfo("timestamp", GSType.TIMESTAMP),
new ColumnInfo("payload", GSType.STRING) // JSON data stored here
));
store.putContainer(info);
Collection<Integer, Row> col = store.getCollection("sensor_data", Row.class);
String json1 = "{\"deviceId\":\"A1\",\"temp\":22.5}";
String json2 = "{\"deviceId\":\"A2\",\"temp\":28.1}";
Row row1 = col.createRow();
row1.setInteger(0, 1);
row1.setTimestamp(1, new Date());
row1.setString(2, json1);
Row row2 = col.createRow();
row2.setInteger(0, 2);
row2.setTimestamp(1, new Date());
row2.setString(2, json2);
col.put(row1);
col.put(row2);
What I want is a query like:
Find all rows where payload.deviceId = "A2".
Currently, the only way I’ve found is:
- Select all rows
- Parse the JSON in Java
- Filter manually
This works but is slow with large datasets.
My question:
Is there a way in GridDB to filter rows directly by a nested JSON value inside a STRING column, without retrieving and parsing everything in the application?
I’m not looking for schema redesign advice right now — I just want to know if native querying of nested JSON is possible in GridDB, and if so, how to do it in Java.