Skip to content

Commit 79a7a74

Browse files
update the approx_topk_distinct documentation (#92)
* update approx_topk page and restructure SQL References by creating individual function pages under /sql-functions folder * address review comments on sql functions pages * update the approx_topk_distinct documentation
1 parent 193d236 commit 79a7a74

File tree

7 files changed

+52
-4
lines changed

7 files changed

+52
-4
lines changed

docs/sql-functions/aggregate.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
2+
---
3+
title: histogram() Function in OpenObserve
4+
description: This page explains how to use the histogram() function in OpenObserve to group time-based log data into fixed intervals for trend analysis. It includes syntax options with or without interval specification, use with aggregate functions such as COUNT(), and guidance on interpreting the result. A detailed example shows how logs are grouped into 30-second time buckets, along with the output format. Users are advised to specify intervals explicitly to ensure consistent and predictable results. The page also includes a visual example to support understanding.
5+
---
6+
17
Aggregate functions compute a single result from a set of input values. For usage of standard SQL aggregate functions such as `COUNT`, `SUM`, `AVG`, `MIN`, and `MAX`, refer to [PostgreSQL documentation](https://www.postgresql.org/docs/).
28

39
---

docs/sql-functions/approximate-aggregate/.pages

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,5 @@ nav:
22

33
- Overview: index.md
44
- approx_topk : approx-topk.md
5+
- approx-topk-distinct: approx-topk-distinct.md
6+

docs/sql-functions/approximate-aggregate/approx-topk-distinct.md

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
1+
---
2+
title: approx_topk_distinct() Function in OpenObserve
3+
description: This page explains how to use the approx_topk_distinct() function in OpenObserve to identify the top K values in one field based on the highest number of distinct values in another field. It introduces the combined use of HyperLogLog and Space-Saving algorithms to efficiently process large, high-cardinality datasets. The guide includes SQL syntax, a usage example, and demonstrates how to flatten the result using the unnest() function. It also provides a sample output to help users understand the structure and interpretation of the result. For top values based only on frequency, refer to the approx_topk() function.
4+
---
5+
16
This page provides instructions on using the `approx_topk_distinct()` function.
27
If you only need to find the top K most frequently occurring values in a field, refer to the [approx_topk()](../approx-topk/) function.
38

4-
## What is approx_topk_distinct()
5-
The approx_topk_distinct() function returns an approximate list of the top K values from one field (field1) that have the most number of distinct values in another field (field2). It is designed to handle large-scale, high-cardinality datasets efficiently by combining two algorithms:
9+
## What is approx_topk_distinct?
10+
The `approx_topk_distinct()` function returns an approximate list of the top K values from one field (field1) that have the most number of distinct values in another field (field2). It is designed to handle large-scale, high-cardinality datasets efficiently by combining two algorithms:
611

712
- **HyperLogLog**: Used to estimate the number of distinct values in field2 per field1.
813
- **Space-Saving**: Used to select the top K field1 values with the highest estimated distinct counts.
@@ -56,4 +61,22 @@ FROM (
5661
ORDER BY distinct_user_agent_count DESC
5762
```
5863
**Result**
59-
![approx_topk_distinct](../../images/approx-topk-distinct.png)
64+
<br>
65+
This query using approx_topk_distinct() with unnest() returns a flat result, where each row represents a value from field1 and its corresponding approximate distinct count from field2: <br>
66+
![approx_topk_distinct](../../images/approx-topk-distinct.png)
67+
68+
## Performance Considerations
69+
The `approx_topk_distinct()` function is designed for high-cardinality fields and large datasets. It uses the same distributed and memory-efficient architecture as `approx_topk()`.
70+
71+
For details on how this approach compares to traditional GROUP BY queries in terms of performance and memory usage, see the [approx_topk() guide](../approx-topk/).
72+
73+
---
74+
75+
## Limitations
76+
The following are the known limitations of `approx_topk_distinct()` function:
77+
78+
Results are approximate, not guaranteed to be exact. Not recommended when exact accuracy is critical for analysis or reporting.
79+
Accuracy depends on data distribution across partitions.
80+
81+
![approx_topk_distinct](../../images/approx-topk-distinct.png)
82+

docs/sql-functions/approximate-aggregate/approx-topk.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
2+
---
3+
title: approx_topk() Function in OpenObserve
4+
description: This page explains how to use the approx_topk() function in OpenObserve to identify the most frequent values in high-cardinality fields. It provides the SQL syntax, a usage example, result structure, and comparison with the traditional GROUP BY approach. The guide includes a detailed performance comparison and highlights memory efficiency in distributed query processing. It also demonstrates how to use approx_topk() with unnest() for flat output and explains scenarios where this function offers a practical advantage. Limitations and frequently asked questions are included to help users understand when to use this approximate method.
5+
---
6+
17
This page provides instructions on using the `approx_topk()` function and explains its performance benefits compared to the traditional `GROUP BY` method.
28

39
## What is `approx_topk`?

docs/sql-functions/approximate-aggregate/index.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ OpenObserve provides the following approximate aggregate functions designed for
22

33
Learn more:
44

5-
- [approx_topk](../approximate-aggregate/approx-topk/)
5+
- [approx_topk](../approximate-aggregate/approx-topk/)
6+
- [approx_topk_distinct](../approximate-aggregate/approx-topk-distinct/)

docs/sql-functions/array.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
---
2+
title: Array Functions in OpenObserve
3+
description: This page lists all supported array functions in OpenObserve, along with their syntax, descriptions, and usage examples. These functions operate on fields that contain stringified JSON arrays, enabling users to sort, count, extract subsets, join, and combine array elements. Functions such as arrsort, arrjoin, arrindex, arrzip, spath, and cast_to_arr help process and transform array data effectively.
4+
---
5+
16
This page lists the array functions supported in OpenObserve, along with their usage formats, descriptions, and examples.
27

38
The array functions operate on fields that contain arrays. In OpenObserve, array fields are typically stored as stringified JSON arrays.

docs/sql-functions/full-text-search.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
---
2+
title: Full-Text Search Functions in OpenObserve
3+
description: This page describes the full-text search functions supported in OpenObserve, including their syntax, behavior, and examples. Functions such as str_match, str_match_ignore_case, match_all, re_match, and re_not_match allow users to filter logs based on exact string matches, case-insensitive searches, keyword searches across multiple fields, and pattern-based filtering using regular expressions. The guide also explains the role of inverted indexing and how to enable it for enhanced search coverage. Sample queries and output visuals are provided to help users apply these functions effectively in log analysis.
4+
---
5+
16
The full-text search functions allow you to filter records based on keyword or pattern matches within one or more fields. <br>This page lists the full-text search functions supported in OpenObserve, along with their usage formats, descriptions, and examples.
27

38
---

0 commit comments

Comments
 (0)