Skip to main content

Simple Query

A simple query retrieves raw time-series rows from CrateDB. You choose which columns to return and can apply filters, sorting, and time range restrictions. This is the most fundamental stream data query type — use it when you need individual data points rather than aggregated summaries.

Transient Simple Query

A transient query lets you specify query parameters directly in the request without saving a query definition first. Use the transientStreamDataQuery field under streamData.

Basic Usage

query {
streamData {
transientStreamDataQuery(
ckId: "Industry.Energy/EnergyMeter"
columnPaths: ["voltage", "power"]
) {
totalCount
pageInfo {
hasNextPage
endCursor
}
items {
rtId
ckTypeId
timestamp
rtWellKnownName
cells {
items {
attributePath
value
}
}
}
}
}
}

Response:

{
"data": {
"streamData": {
"transientStreamDataQuery": {
"totalCount": 4826,
"pageInfo": {
"hasNextPage": true,
"endCursor": "YXJyYXljb25uZWN0aW9uOjI0"
},
"items": [
{
"rtId": "65dc6d24cc529cdc46c84fcc",
"ckTypeId": "Industry.Energy/EnergyMeter",
"timestamp": "2024-03-21T16:22:47.676Z",
"rtWellKnownName": "EnergyMeter-001",
"cells": {
"items": [
{ "attributePath": "voltage", "value": 230.5 },
{ "attributePath": "power", "value": 1450.2 }
]
}
},
{
"rtId": "65dc6d24cc529cdc46c84fcc",
"ckTypeId": "Industry.Energy/EnergyMeter",
"timestamp": "2024-03-21T16:23:50.675Z",
"rtWellKnownName": "EnergyMeter-001",
"cells": {
"items": [
{ "attributePath": "voltage", "value": 231.1 },
{ "attributePath": "power", "value": 1465.8 }
]
}
}
]
}
}
}
}

Each result row contains the system fields (rtId, ckTypeId, timestamp, rtWellKnownName) and a cells connection with the requested column values.

Parameters

ParameterTypeRequiredDescription
ckIdString!YesThe CK type to query (e.g., "Industry.Energy/EnergyMeter")
columnPaths[String!]!YesData stream attribute names to return (e.g., ["voltage", "power"])
argStreamDataArgumentsNoTime range and limit overrides
fieldFilter[FieldFilter]NoField-level comparison filters
sortOrder[Sort]NoSort specification
rtIds[OctoObjectId]NoScope results to specific runtime entity IDs
firstIntNoMaximum number of items to return (pagination)
afterStringNoCursor for pagination (from pageInfo.endCursor)

Column Paths

The columnPaths parameter specifies which data stream attributes to include in the result. Use the attribute names as defined in the CK type.

# Single column
transientStreamDataQuery(
ckId: "Industry.Energy/EnergyMeter"
columnPaths: ["voltage"]
)

# Multiple columns
transientStreamDataQuery(
ckId: "Industry.Energy/EnergyMeter"
columnPaths: ["voltage", "power", "current", "frequency"]
)

The system fields rtId, ckTypeId, timestamp, and rtWellKnownName are always included regardless of the column paths specified.


Filtering

Use fieldFilter to restrict results based on attribute values. Each filter specifies an attribute path, an operator, and a comparison value.

Filter by Attribute Value

query {
streamData {
transientStreamDataQuery(
ckId: "Industry.Energy/EnergyMeter"
columnPaths: ["voltage", "power"]
fieldFilter: [
{
attributePath: "voltage"
operator: GREATER_THAN
comparisonValue: 220
}
]
) {
totalCount
items {
timestamp
cells {
items {
attributePath
value
}
}
}
}
}
}

Multiple Filters

Multiple filters are combined with AND logic:

fieldFilter: [
{
attributePath: "voltage"
operator: GREATER_EQUAL_THAN
comparisonValue: 220
},
{
attributePath: "voltage"
operator: LESS_EQUAL_THAN
comparisonValue: 240
}
]

Available Filter Operators

OperatorDescription
EQUALSExact match
NOT_EQUALSNot equal
GREATER_THANGreater than
GREATER_EQUAL_THANGreater than or equal
LESS_THANLess than
LESS_EQUAL_THANLess than or equal
LIKEPattern match (use % as wildcard)
MATCH_REG_EXRegular expression match
INValue in list
NOT_INValue not in list
ANY_EQAny element equals (for array fields)
ANY_LIKEAny element matches pattern (for array fields)

Time Range Filtering

Use StreamDataArguments to restrict results to a specific time window:

query {
streamData {
transientStreamDataQuery(
ckId: "Industry.Energy/EnergyMeter"
columnPaths: ["voltage"]
arg: {
queryMode: DEFAULT
from: "2024-03-21T00:00:00Z"
to: "2024-03-22T00:00:00Z"
limit: 1000
}
) {
totalCount
items {
timestamp
cells {
items {
attributePath
value
}
}
}
}
}
}
FieldDescription
fromStart of the time range (inclusive)
toEnd of the time range (inclusive)
limitMaximum number of data points to return from CrateDB
queryModeSet to DEFAULT for standard queries

The limit in StreamDataArguments controls how many rows CrateDB returns before pagination is applied. The first parameter on the query field controls how many items are returned per page.


Sorting

Use sortOrder to control the order of results:

query {
streamData {
transientStreamDataQuery(
ckId: "Industry.Energy/EnergyMeter"
columnPaths: ["voltage"]
sortOrder: [
{ attributePath: "timestamp", sortOrder: DESCENDING }
]
) {
items {
timestamp
cells {
items {
attributePath
value
}
}
}
}
}
}

This returns the most recent data points first. You can sort by any column in the result set.


Scoping to Specific Entities

Use rtIds to limit results to data from specific runtime entities:

query {
streamData {
transientStreamDataQuery(
ckId: "Industry.Energy/EnergyMeter"
columnPaths: ["voltage", "power"]
rtIds: [
"65dc6d24cc529cdc46c84fcc",
"65dc6d24cc529cdc46c84fcd"
]
) {
totalCount
items {
rtId
rtWellKnownName
timestamp
cells {
items {
attributePath
value
}
}
}
}
}
}

This returns stream data only for the two specified energy meters.


Pagination

All stream data queries use cursor-based pagination. Use first to set the page size and after to fetch subsequent pages.

First Page

query {
streamData {
transientStreamDataQuery(
ckId: "Industry.Energy/EnergyMeter"
columnPaths: ["voltage"]
first: 50
) {
totalCount
pageInfo {
hasNextPage
endCursor
}
items {
timestamp
cells {
items {
attributePath
value
}
}
}
}
}
}

Next Page

Use the endCursor value from the previous response as the after parameter:

query {
streamData {
transientStreamDataQuery(
ckId: "Industry.Energy/EnergyMeter"
columnPaths: ["voltage"]
first: 50
after: "YXJyYXljb25uZWN0aW9uOjQ5"
) {
totalCount
pageInfo {
hasNextPage
endCursor
}
items {
timestamp
cells {
items {
attributePath
value
}
}
}
}
}
}

Continue fetching pages until hasNextPage is false.


Combining Parameters

All parameters can be combined. This example queries the last 24 hours of voltage data for a specific energy meter, filtered to values above 220V, sorted by timestamp descending, with pagination:

query {
streamData {
transientStreamDataQuery(
ckId: "Industry.Energy/EnergyMeter"
columnPaths: ["voltage", "power"]
arg: {
queryMode: DEFAULT
from: "2024-03-20T16:00:00Z"
to: "2024-03-21T16:00:00Z"
limit: 5000
}
rtIds: ["65dc6d24cc529cdc46c84fcc"]
fieldFilter: [
{ attributePath: "voltage", operator: GREATER_THAN, comparisonValue: 220 }
]
sortOrder: [
{ attributePath: "timestamp", sortOrder: DESCENDING }
]
first: 100
) {
totalCount
pageInfo {
hasNextPage
endCursor
}
items {
rtId
rtWellKnownName
timestamp
cells {
items {
attributePath
value
}
}
}
}
}
}

Typed vs Transient

For a comparison of typed and transient query approaches, see the Stream Data Access overview. In summary:

TypedTransient
Column selectionAll attributes of the typeExplicit columnPaths parameter
Result formatNamed fields (e.g., voltage)cells with attributePath / value pairs
Type safetyGraphQL schema validationRuntime validation
Use caseKnown type, all attributes neededDynamic column selection, ad-hoc analysis