Skip to content

Commit

Permalink
Add trendline documentation
Browse files Browse the repository at this point in the history
Signed-off-by: James Duong <[email protected]>
  • Loading branch information
jduo committed Oct 27, 2024
1 parent 79796be commit 655f136
Showing 1 changed file with 63 additions and 0 deletions.
63 changes: 63 additions & 0 deletions docs/user/ppl/cmd/trendline.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
=============
rename
=============

.. rubric:: Table of contents

.. contents::
:local:
:depth: 2


Description
============
| Use the ``trendline`` command to calculate the moving average on one or more fields in a search result.

Syntax
============
trendline <average-type>(<number-of-samples>, <source-field>) AS <target-field> [" " <average-type>(<number-of-samples>, <source-field>) AS <target-field> ]...

* average-type: mandatory. The moving average computation. Can be ``sma`` (simple moving average) currently.
* number-of-samples: mandatory. The number of samples to use in the average calculation. Must be a positive non-zero integer.
* source-field: mandatory. The field to compute the average on.
* target-field: mandatory. The field name to report the computation under.


Example 1: Calculate the moving average on one field.
=====================================================

The example shows how to calculate the moving average on one field.

PPL query::

os> source=accounts | trendline sma(2, account_number) as an | fields an;
fetched rows / total rows = 4/4
+------+
| an |
|------|
| null |
| 3.5 |
| 9.5 |
| 15.5 |
+------+


Example 2: Calculate the moving average on multiple fields.
===========================================================

The example shows how to calculate the moving average on multiple fields.

PPL query::

os> source=accounts | trendline sma(2, account_number) as an sma(2, age) as age_trend | fields an, age_trend ;
fetched rows / total rows = 4/4
+------+-----------+
| an | age_trend |
|------|-----------|
| null | null |
| 3.5 | 34.0 |
| 9.5 | 32.0 |
| 15.5 | 30.5 |
+------+-----------+

0 comments on commit 655f136

Please sign in to comment.