[Feature request] Add LTTB downsampling as a built-in table function for the Table Model
@DaZuiZui y travaille déjà.
Depuis le 27/8/2026.
Évaluation
Cette issue n'a pas encore été évaluée.
Description
Search before asking
- I searched in the issues and found nothing similar.
Motivation
Motivation
Large time-series datasets usually need to be downsampled before visualization. Largest-Triangle-Three-Buckets (LTTB) can reduce the number of returned points while preserving the visual characteristics of the original series, including significant peaks and valleys.
IoTDB currently does not provide a native LTTB implementation for the Table Model. Implementing LTTB as a built-in table function would allow users to downsample data directly in SQL without transferring the full dataset to the client.
This feature is specifically for the Table Model and is unrelated to the sample UDF implementations in the Tree Model library-udf module.
References:
Proposed solution
Add a built-in Table Model table function named LTTB.
Its table argument and window-related parameters should follow the conventions already used by the built-in M4 table function.
The function should support two mutually exclusive modes:
- Target-count mode, selected by
N - Window/bucket mode, selected by
SIZE
Exactly one of N and SIZE must be specified.
Parameters
-
DATAThe input table, using the same table-argument semantics as
M4. -
TIMECOLA descriptor identifying the input time column.
-
NA positive integer specifying the target number of sampled points for each partition and each participant column.
Nis mutually exclusive withSIZE,SLIDE, andORIGIN.The minimum valid value should be
3, because LTTB preserves the first point, the last point, and at least one intermediate point. -
SIZEDefines the bucket size, using the same conventions as
M4:- A duration value selects time-window mode.
- An integer value selects count-window mode.
SIZEis mutually exclusive withN. -
SLIDEDefines the window step and defaults to
SIZE.It is valid only when
SIZEis specified and is mutually exclusive withN. -
ORIGINDefines the time-window origin.
It is valid only for time-window mode and is mutually exclusive with
N.
No COL parameter is required. As with M4, participant columns should be determined from the input table automatically. Each supported numeric column other than the time column and partition columns should be processed independently.
Target-count mode
Example:
SELECT *
FROM LTTB(
DATA => TABLE(
SELECT time, temperature, pressure
FROM sensor_data
),
TIMECOL => DESCRIPTOR(time),
N => 500
);
For each partition and participant column:
- Construct an ordered sequence of
(time, value)points. - Ignore rows where the participant column is
NULL. - If the number of eligible points is less than or equal to
N, return all eligible points. - Otherwise, apply LTTB and return exactly
Npoints. - Preserve the first and last eligible points.
- Return sampled points in ascending time order.
Different participant columns may select different timestamps because LTTB is applied independently to each column.
The output should use window_index, consistent with the count-window output of M4:
window_index,
<partition columns>,
<column_1>_time,
<column_1>,
<column_2>_time,
<column_2>,
...
The selected points of each participant column are aligned by their output position. If participant columns produce different numbers of points, for example because of different NULL distributions, the shorter sequences should be padded with NULL.
Therefore, each partition produces at most N output rows.
Window/bucket mode
Example using count-based buckets:
SELECT *
FROM LTTB(
DATA => TABLE(
SELECT time, temperature, pressure
FROM sensor_data
),
TIMECOL => DESCRIPTOR(time),
SIZE => 100,
SLIDE => 100
);
Example using time-based buckets:
SELECT *
FROM LTTB(
DATA => TABLE(
SELECT time, temperature, pressure
FROM sensor_data
),
TIMECOL => DESCRIPTOR(time),
SIZE => 1m,
SLIDE => 1m,
ORIGIN => TIMESTAMP '2026-01-01 00:00:00'
);
The window construction rules should be consistent with M4.
For each participant column, LTTB should use:
- The previously selected point
- Candidate points in the current bucket
- The average point of the next bucket
The candidate that forms the largest triangle area should be selected.
The time-window output schema should follow M4:
window_start,
window_end,
<partition columns>,
<column_1>_time,
<column_1>,
<column_2>_time,
<column_2>,
...
The count-window output schema should also follow M4:
window_index,
<partition columns>,
<column_1>_time,
<column_1>,
<column_2>_time,
<column_2>,
...
Validation
The function should reject at least the following cases:
- Neither
NnorSIZEis specified. - Both
NandSIZEare specified. Nis used together withSLIDEorORIGIN.Nis less than3.SLIDEorORIGINis specified withoutSIZE.ORIGINis specified for count-window mode.TIMECOLdoes not identify a valid time column.- A participant column has an unsupported data type.
Example of an invalid invocation:
SELECT *
FROM LTTB(
DATA => TABLE(sensor_data),
TIMECOL => DESCRIPTOR(time),
N => 500,
SIZE => 1m
);
This should fail because N and SIZE select different execution modes and are mutually exclusive.
Implementation considerations
Target-count mode needs the total number of eligible points before the LTTB bucket boundaries can be determined. Its implementation may therefore require buffering the input for each partition and participant column, with appropriate memory accounting and spill handling where necessary.
Window/bucket mode may be implemented with bounded state by retaining the previous selected point and the current and next buckets.
The function should have set semantics, consistent with M4. In distributed execution, LTTB must be evaluated only after all rows belonging to the same partition have been gathered and ordered. Fragment-local sampling results cannot generally be merged into a globally correct LTTB result.
Suggested tests
Tests should cover:
- A known LTTB example with deterministic expected points.
- Preservation of the first and last points.
- Returning exactly
Npoints when the eligible input contains more thanNpoints. - Returning all points when the eligible input contains no more than
Npoints. window_indexoutput in target-count mode.- Multiple participant columns selecting different timestamps.
- Participant columns with different
NULLdistributions. - Partitioned input.
- Count-based and time-based
SIZE. - Default and explicit
SLIDE. - Time-based
ORIGIN. - Invalid parameter combinations.
- Consistent results between standalone and distributed execution.
Alternatives considered
- Perform LTTB downsampling on the client after querying all raw data. This requires transferring significantly more data and duplicates the implementation across clients.
- Use
M4for visualization downsampling. M4 and LTTB use different selection strategies and may serve different visualization requirements. - Use a Tree Model UDF. This does not provide a native Table Model interface or integration with Table Model planning and execution.
Solution
No response
Alternatives
No response
Are you willing to submit a PR?
- I'm willing to submit a PR!
- Langage dominant
- Java
- Étoiles
- 6.4k
- Forks
- 1.2k
- Merge moyen
- 1 j 17 h
- PR mergées (30 j)
- 152
Guide de contribution
Ouvrir le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de apache/iotdb
-
Difficulté 2/5 1-3 heures Accessibilité débutants 82/100
-
IoTDB Edge: stop-edge.sh does not stop its own process when IOTDB_HOME is set, and reports success Ouverte
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
-
[Bug] 执行start-all.sh后无法启动集群问题 Ouverte
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
-
[Bug] findColumn throws NullPointerException instead of SQLException for an unknown column name Ouverte
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
-
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
Toutes les issues de apache/iotdb
Issues similaires
-
area-deployment area-integrations triage:bot-seen
Difficulté 2/5 Une demi-journée Accessibilité débutants 86/100
-
Difficulté 2/5 1-3 heures Accessibilité débutants 75/100
apache/flink-agents#1156 ·
-
[source-shopify] FAILED bulk operation without partialDataUrl is silently treated as successful Ouvertearea/connectors autoteam community connectors/source/shopify needs-triage team/use type/bug
Difficulté 2/5 1-3 heures Accessibilité débutants 84/100
-
Difficulté 2/5 1-3 heures Accessibilité débutants 70/100
-
Difficulté 1/5 Moins d'une heure Accessibilité débutants 85/100