Skip to content

tdfs4ds.genai.operators.ts_compress

tdfs4ds.genai.operators.ts_compress

The td-ts-compressor ts_compress_to table operator: see operator_context.

The operator (https://github.com/denismolin/td-ts-compressor) keeps, per series, the points that matter geometrically: the endpoints, then repeatedly the point farthest (in perpendicular distance) from its active segment, in a scaled coordinate system. Its output keeps the selected input rows plus compression_importance (selection order) and compression_distance. A process view usually wraps it in the aggregation that feature_sql of the package generates (compression_ratio, distance_rank_N ...).

Detected by the mapping / function name (any qualifier, any case) or, for a renamed mapping, by its USING signature. TD_SYSFNLIB.ts_compress is an unrelated Teradata system function (a time-series compression of its own, no USING names of this operator), so the bare name ts_compress is accepted only with the signature.

KNOWN_NAMES module-attribute

KNOWN_NAMES = ('ts_compress_seq_to_map', 'ts_compress_seq_to', 'ts_compress_to')

_SIGNATURE_REQUIRED module-attribute

_SIGNATURE_REQUIRED = ('time_column_index', 'value_column_index')

_SIGNATURE_ANY module-attribute

_SIGNATURE_ANY = ('tol_x', 'tol_y')

FEATURE_NAMES module-attribute

FEATURE_NAMES = ('original_points', 'remaining_points', 'compressed_points', 'retained_ratio', 'retained_pct', 'compression_ratio', 'reduction_pct', 'max_selected_distance', 'avg_selected_distance', 'std_selected_distance')

_FEATURE_TEXT module-attribute

_FEATURE_TEXT = {'original_points': 'number of observations of the series before compression', 'remaining_points': 'number of points kept by the compressor', 'compressed_points': 'number of points kept by the compressor (same as remaining_points)', 'retained_ratio': 'kept points / original points (0 to 1)', 'retained_pct': '100 * retained_ratio', 'compression_ratio': 'original points / kept points (higher = stronger compression, a series that is simple geometrically compresses more)', 'reduction_pct': '100 * (1 - retained_ratio), the share of observations removed', 'max_selected_distance': 'largest compression_distance among kept points (in practice the most prominent departure from a straight line between the endpoints)', 'avg_selected_distance': 'mean compression_distance of the kept points (endpoints count as 0)', 'std_selected_distance': 'sample standard deviation of compression_distance of the kept points'}

_DEFAULTS module-attribute

_DEFAULTS = {'distance_max': '1.0', 'n_max': '-1', 'tol_x': 'auto', 'tol_y': 'auto', 'plot_width_px': '1600', 'plot_height_px': '900', 'plot_x_fraction': '0.95', 'auto_log_drop': '1.5', 'time_unit': 'second', 'time_type': 'auto'}

_IDENT module-attribute

_IDENT = '(?:"[^"]+"|[\\w$#]+)'

_NAME_RE module-attribute

_NAME_RE = compile('(?<![\\w$#."])(' + _IDENT + '(?:\\s*\\.\\s*' + _IDENT + ')*)\\s*\\(')

_USING_PAIR_RE module-attribute

_USING_PAIR_RE = compile("([A-Za-z_]\\w*)\\s*\\(\\s*'((?:[^']|'')*)'\\s*\\)")

_LABEL_RE module-attribute

_LABEL_RE = compile("SELECT\\s+'((?:[^']|'')*)'\\s+AS\\s+(" + _IDENT + ')', I)

_PARAM_ORDER module-attribute

_PARAM_ORDER = ('distance_max', 'n_max', 'auto_log_drop', 'min_relative_gain', 'min_absolute_gain', 'tol_x', 'tol_y', 'plot_width_px', 'plot_height_px', 'plot_x_fraction')

_mask

_mask(sql: str) -> str

sql with comments blanked (same length); string literals kept.

_balanced

_balanced(text: str, open_at: int)

End index (of the closing parenthesis) of the group opened at open_at, or None.

_top_level

_top_level(text: str, keyword_re) -> int

Index of the first match of keyword_re outside parentheses and strings, -1 if none.

_split_commas

_split_commas(text: str) -> list

_unquote

_unquote(name: str) -> str

_clauses

_clauses(body: str) -> dict

ON / PARTITION BY / ORDER BY / USING parts of a table-operator call body.

_source_of

_source_of(on_text: str) -> str

_wrapper

_wrapper(masked: str) -> dict

detect

detect(sql: str) -> list

collect

collect(found: list) -> list

Whether the mapping exists, and where. Best effort, one DBC read per distinct name.

The operator is configured entirely by the SQL (nothing is stored in a model table), so the database adds only one fact: is the mapping installed, and in which database. That is cheap, and tells the reader a renamed or unqualified mapping resolves to something.

_mode

_mode(using: dict) -> str

Mirror of td-ts-compressor's own _mode_description.

_param_text

_param_text(using: dict) -> str

render

render(items: list) -> str