id: temporal_resample
name: Resample
description: >
  Resample a time series to a different frequency. Groups rows into time
  buckets and aggregates values within each bucket using the specified method.
version: 1.0.0
category: transform
type: table-to-table
default_implementation: duckdb

inputs:
  - name: table
    type: table
    format: parquet
    description: Input table with a timestamp column
    required: true

requires: {}

outputs:
  - name: result
    type: table
    format: parquet
    description: Resampled time series

params:
  time_column:
    type: string
    description: Name of the timestamp column
    required: true
  freq:
    type: string
    description: >
      Target frequency. Shorthand format: '1h' (hourly), '1D' (daily),
      '1W' (weekly), '30min' (30 minutes), '1M' (monthly), '1Y' (yearly).
    required: true
  agg_method:
    type: string
    default: mean
    enum: [mean, sum, min, max, first, last, count]
    description: Aggregation method applied within each time bucket
  value_columns:
    type: array
    items:
      type: string
    description: >
      Columns to aggregate. If omitted, all numeric columns except the
      time column are aggregated.

# backends: audited 2026-08-14 (defect 50). A key means a runtime that DISPATCHES this op —
# folia-engine `dispatch_op` (products/sdk/folia-engine/src/lib.rs), a `registerOp`/OP_TABLE
# entry in packages/compute, `_BUILTIN_OP_MAP` in folia/compute.py, or a backend manifest
# (folia/backends/*/backend.yaml).
backends:
  rust-wasm:
    op: temporal_resample
    dispatch: packages/compute/src/ops/wasm-bridge.ts registerOp
  js:
    function: temporal_resample
    dispatch: packages/compute/src/ops/wasm-bridge.ts
  python:
    function: temporal.ops.resample
    dispatch: folia/compute.py _BUILTIN_OP_MAP

display_hints:
  chart:
    renderer: observable-plot
    chartType: line
    xAxis: { field: ts }
