Skip to content

Commit 46e381b

Browse files
add logs and metrics docs (#30537)
Co-authored-by: Michael Cretzman <[email protected]>
1 parent 3ad2788 commit 46e381b

File tree

1 file changed

+72
-0
lines changed

1 file changed

+72
-0
lines changed

content/en/ddsql_reference/_index.md

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ This documentation covers the SQL support available and includes:
3333
- [SQL functions](#functions)
3434
- [Window functions](#window-functions)
3535
- [JSON functions](#json-functions-and-operators)
36+
- [Table functions](#table-functions)
3637
- [Tags](#tags)
3738

3839

@@ -453,6 +454,77 @@ This table provides an overview of the supprted window functions. For comprehens
453454
| json_extract_path_text(text json, text path…) | text | Extracts a JSON sub-object as text, defined by the path. Its behavior is equivalent to the [Postgres function with the same name][3]. For example, `json_extract_path_text(col, ‘forest')` returns the value of the key `forest` for each JSON object in `col`. See the example below for a JSON array syntax.|
454455
| json_extract_path(text json, text path…) | JSON | Same functionality as `json_extract_path_text`, but returns a column of JSON type instead of text type.|
455456

457+
## Table functions
458+
459+
{{< callout url="https://www.datadoghq.com/product-preview/logs-metrics-support-in-ddsql-editor/" >}}
460+
Querying Logs and Metrics through DDSQL is in Preview. Use this form to request access.
461+
{{< /callout >}}
462+
463+
Table functions are used to query Logs and Metrics
464+
465+
<table style="width: 100%; table-layout: fixed;">
466+
<thead>
467+
<tr>
468+
<th style="width: 33%;">Function</th>
469+
<th style="width: 33%;">Description</th>
470+
<th style="width: 33%;">Example</th>
471+
</tr>
472+
</thead>
473+
<tbody>
474+
<tr>
475+
<td>
476+
<pre>
477+
dd.logs(
478+
filter => varchar,
479+
columns => array < varchar >,
480+
indexes ? => array < varchar >,
481+
from_timestamp ? => timestamp,
482+
to_timestamp ? => timestamp
483+
) AS (column_name type [, ...])</pre>
484+
</td>
485+
<td>Returns log data as a table. The columns parameter specifies which log fields to extract, and the AS clause defines the schema of the returned table. Optional: filtering by index or time range. When time is not specified, we default to the past 1 hour of data.</td>
486+
<td>
487+
{{< code-block lang="sql" >}}
488+
SELECT timestamp, host, service, message
489+
FROM dd.logs(
490+
filter => 'source:java',
491+
columns => ARRAY['timestamp','host', 'service','message']
492+
) AS (
493+
timestamp TIMESTAMP,
494+
host VARCHAR,
495+
service VARCHAR,
496+
message VARCHAR
497+
){{< /code-block >}}
498+
</td>
499+
</tr>
500+
<tr>
501+
<td>
502+
<pre>
503+
dd.metric_scalar(
504+
query varchar,
505+
reducer varchar [, from_timestamp timestamp, to_timestamp timestamp]
506+
)</pre>
507+
</td>
508+
<td>Returns metric data as a scalar value. The function accepts a metrics query (with optional grouping), a reducer to determine how values are aggregated (avg, max, etc.), and optional timestamp parameters (default 1 hour) to define the time range.</td>
509+
<td>
510+
{{< code-block lang="sql" >}}
511+
SELECT *
512+
FROM dd.metric_scalar(
513+
'avg:system.cpu.user{*} by {service}',
514+
'avg',
515+
TIMESTAMP '2025-07-10 00:00:00.000-04:00',
516+
TIMESTAMP '2025-07-17 00:00:00.000-04:00'
517+
)
518+
ORDER BY value DESC;{{< /code-block >}}
519+
</td>
520+
</tr>
521+
</tbody>
522+
</table>
523+
524+
525+
526+
527+
456528
## Tags
457529

458530
DDSQL exposes tags as an `hstore` type, which you can query using the PostgreSQL arrow operator. For example:

0 commit comments

Comments
 (0)