Harness Query Language (HQL) Reference
Complete reference for Harness Query Language (HQL), a domain-specific language for querying events, entities, metrics, and views across the Harness Data Platform.
HQL is a domain-specific query language for querying heterogeneous data sources in the Harness Data Platform. It provides a unified interface for querying events, entities, metrics, and views across multiple database backends (StarRocks, AlloyDB, BigQuery, PostgreSQL, MySQL) with pipe-based operations and automatic SQL generation.
Data sources
HQL supports four types of data sources. Type identifiers can be unquoted for simple names or quoted for names with special characters (like colons).
event
Time-series and log data
Spans, logs, cost events, clickstream
entity
Business objects and transactional data
Pipeline executions, artifacts, API entities
metric
Aggregated and analytical data
Aggregated cost metrics, performance metrics
view
Virtual tables that expand to CTEs at query time
Custom views like successful_pipelines
-- Unquoted identifier
find event span
-- Quoted identifier with special characters
find event "ccm:unified_table"
-- Entity type
find entity "pipeline:pipeline_execution"
-- Metric type
find metric "ccm:cost_metrics"Table aliases
Assign aliases to data sources for use in joins and field references.
Operations
Operations are chained using the pipe (|) operator. Each operation transforms the result of the previous one.
Filter
Filters rows based on conditions. Supports equality, comparison, pattern matching, membership, string containment, and null checks.
=, !=
Equality / Inequality
>, >=, <, <=
Comparison
=~
Pattern matching (regex)
in, !in
Membership
contains, !contains
String containment
is null, is not null
Null checks
is empty, is not empty
Empty checks
and, or
Logical operators (and has higher precedence)
Select
Selects specific fields or expressions. Use -> for nested field access.
Group by
Groups rows by specified expressions. All non-aggregated fields in select must be included in group_by.
Aggregate
Performs second-order aggregations (aggregations on already aggregated data).
Order by, limit, offset, distinct
Functions
Aggregation functions
count()
Count of rows
count(expr)
Count of non-null values
sum(expr)
Sum of values
avg(expr)
Average of values
min(expr)
Minimum value
max(expr)
Maximum value
approx_count_distinct(expr)
Approximate distinct count
String functions
lower(str)
Convert to lowercase
upper(str)
Convert to uppercase
trim(str)
Remove leading/trailing whitespace
concat(a, b, ...)
Concatenate strings
substr(str, start, len)
Substring extraction
length(str)
String length
replace(str, from, to)
Replace occurrences
Math functions
abs(n)
Absolute value
round(n, d)
Round to d decimal places
floor(n)
Round down
ceil(n)
Round up
mod(n, m)
Modulo
sqrt(n)
Square root
pow(n, e)
Raise to power
Time functions
now()
Current timestamp
ago(duration)
Timestamp relative to now (e.g., ago(30d), ago(1h))
date_trunc(unit, ts)
Truncate timestamp to unit ('day', 'hour', 'week', 'month')
date_diff(unit, a, b)
Difference between two timestamps
to_timestamp(expr)
Cast to timestamp
extract(field from ts)
Extract field from timestamp (year, month, day, etc.)
Conditional expressions (CASE WHEN)
Cast and interval expressions
Common table expressions (CTEs)
CTEs let you define named subqueries that can be referenced in the main query. They are useful for breaking down complex queries, reusing subqueries, and improving readability. CTEs cannot be nested (no CTEs inside CTE definitions).
Joins
HQL supports joining CTEs or direct data sources with inner (default), left, right, and full join types.
Examples
Cost analysis by region
Pipeline execution statistics
Top API endpoints by latency
Conditional aggregation (success rate)
Nested field access
Time-series analysis
Error rate with CTEs
Best practices
1. Use aliases for clarity
2. Filter early
Apply filters as early as possible to reduce data processing.
3. Use CTEs for complex queries
4. Group by all non-aggregated fields
All fields in select that are not wrapped in an aggregation function must appear in group_by.
5. Quote type identifiers with special characters
6. Always limit result sets
Use limit for queries that might return large result sets to avoid performance issues.
Reference
Operation precedence
Operations are applied in the order they appear in the query.
1
find (data source)
2
filter
3
select
4
group_by
5
aggregate
6
order_by
7
limit / offset
Expression precedence
1 (highest)
Parentheses ()
2
Multiplicative * / %
3
Additive + -
4
Comparison = != > >= < <=
5
Logical AND
6 (lowest)
Logical OR
Data type mapping
string
VARCHAR / TEXT
VARCHAR
int
INTEGER
INT
long
BIGINT
BIGINT
double
DOUBLE PRECISION
DOUBLE
bool
BOOLEAN
BOOLEAN
timestamp
TIMESTAMP
DATETIME
Reserved keywords
The following keywords are reserved but can be used as field names in qualified references (e.g., alias.select).
find, filter, select, group_by, aggregate, order_by, limit, offset, distinct, join, left, right, inner, full, on, with, as, and, or, not, in, is, null, true, false, case, when, then, else, end, cast, asc, desc, contains, by
Last updated
Was this helpful?