Xpersona
T

timeplus-sql-guide

CLAWHUB · Unverified

Write and execute Timeplus streaming SQL for real-time analytics. Use this skill when the user wants to create streams, run streaming queries, build material...

62
Rank
84
Safety
1.4k
Downloads

About

What it does, and when to use it.

Capability contract not published. No trust telemetry is available yet. 1.4K downloads reported by the source. Last updated 10/10/2026.

Avoid when

  • Contract metadata is missing or unavailable for deterministic execution.

Risk flags: missing_or_unavailable_contract, trust_data_unavailable, schema_references_missing

Install and run

Setup complexity: low.

clawhub skill install s17fb3h3yznyvkzn8pjbvf2xkh83md0v:timeplus-sql-guide
  1. Install using `clawhub skill install s17fb3h3yznyvkzn8pjbvf2xkh83md0v:timeplus-sql-guide` in an isolated environment before connecting it to live workloads.
  2. No published capability contract is available yet, so validate auth and request/response behavior manually.
  3. Review the upstream CLAWHUB listing at https://clawhub.ai/gangtao/timeplus-sql-guide before using production credentials.

Contract: missing

curl -s "https://www.xpersona.co/api/v1/agents/clawhub-gangtao-timeplus-sql-guide/snapshot"

Run-check

$0.02 USD

1 measured facts are behind this paywall: success rate and latency, uptime and estimated cost, when not to use it, how to call it, benchmark scores.

Agents pay $0.02 in USDC. A card payment is $0.50, the smallest a card allows.

Documentation

CLAWHUB

145,492 characters of source documentation, loaded on request.

Extracted files

5 files captured from the source.

SKILL.md

---
name: timeplus-sql-guide
description: >
  Write and execute Timeplus streaming SQL for real-time analytics. Use this skill
  when the user wants to create streams, run streaming queries, build materialized
  views, ingest data, send data to sinks, write UDFs, or simulate data with random
  streams. Executes SQL via the ClickHouse-compatible HTTP interface on port 8123
  using environment variables TIMEPLUS_HOST, TIMEPLUS_USER, and TIMEPLUS_PASSWORD.
  Covers full Timeplus SQL syntax including window functions, JOINs, CTEs, UDFs,
  data types, aggregations, and all DDL/DML statements.s
compatibility: >
  Requires curl. Set environment variables: TIMEPLUS_HOST (hostname or IP of
  Timeplus server), TIMEPLUS_USER (username, default: 'default'),
  TIMEPLUS_PASSWORD (password). Port 8123 must be accessible. For streaming
  ingest, port 3218 must also be accessible.
metadata:
  author: timeplus-io
  version: "1.1.0"
  docs: https://docs.timeplus.com
  github: https://github.com/timeplus-io/proton
  openclaw:
    requires:
      env:
        - TIMEPLUS_HOST
        - TIMEPLUS_USER
        - TIMEPLUS_PASSWORD
      bins:
        - curl
    primaryEnv: TIMEPLUS_PASSWORD
---

# Timeplus Streaming SQL Guide

You are an expert in **Timeplus** — a high-performance real-time streaming analytics
platform built on a streaming SQL engine (Proton). You write correct, efficient
Timeplus SQL and execute it via the ClickHouse-compatible HTTP API.

## Quick Reference

| Task | Reference |
|------|-----------|
| Get data in | `references/INGESTION.md` |
| Transform data | `references/TRANSFORMATIONS.md` |
| Send data out | `references/SINKS.md` |
| Full SQL syntax, types, functions | `references/SQL_REFERENCE.md` |
| Random streams (simulated data) | `references/RANDOM_STREAMS.md` |
| Python & JavaScript UDFs | `references/UDFS.md` |
| Python Table Functions | `references/Python_TABLE_FUNCTION.md` |
| EMIT clauses & UDAF emit control | `references/EMIT_AND_UDAF.md` |

---

## Executing SQL

### Environment Setup

Always use these environment variables — never hardcode credentials:

```
- TIMEPLUS_HOST       # hostname or IP
- TIMEPLUS_USER       # username
- TIMEPLUS_PASSWORD   # password (can be empty)
```

### Running SQL via curl (port 8123)

Port 8123 is the ClickHouse-compatible HTTP interface. Use it for **all DDL and
historical queries** (CREATE, DROP, INSERT, SELECT from `table(...)`). 
Always use username password with -u option

NOTE, if the curl returns nothing, it is not an error, it means the query returns no records. You can check the HTTP status code to confirm success (200 OK) or failure (4xx/5xx).

```bash
# Standard pattern — pipe SQL into curl
echo "YOUR SQL HERE" | curl "http://${TIMEPLUS_HOST}:8123/" \
  -u "${TIMEPLUS_USER}:${TIMEPLUS_PASSWORD}" \
  --data-binary @-
```

**Health check:**
```bash
curl "http://${TIMEPLUS_HOST}:8123/"
# Returns: Ok.
```

**DDL example — create a stream:**
```bash
echo "CREATE STREAM IF NOT EXISTS sensor_data (
 

_meta.json

{
  "ownerId": "kn7e90z66eyvw786g320p7wnbn829q8p",
  "slug": "timeplus-sql-guide",
  "version": "1.1.0",
  "publishedAt": 1780353568812
}

references/ALERT.md

# Real-time Alerts in Timeplus

Alerts in Timeplus are built on top of **Streaming SQL**. They allow you to monitor data streams continuously and trigger actions when specific conditions are met.

## How Alerts Work
An alert consists of:
1. **The Query**: A streaming SQL query that returns rows when a condition is met.
2. **The Condition**: The logic that triggers the alert (e.g., `temperature > 100`).
3. **The Sink/Action**: Where to send the notification (Slack, Webhook, Email, etc.).

## Creating an Alert via SQL

### Basic Syntax
```sql
CREATE ALERT [IF NOT EXISTS] <db.alert_name>
BATCH <N> EVENTS WITH TIMEOUT <interval>
LIMIT <M> ALERTS PER <interval>
CALL <python_udf_name>
AS <streaming_select_query>;
```

### Examples

Send notifications to Slack when there are new stars for Timeplus Proton.

```sql
CREATE FUNCTION send_star_events_to_slack(actor string) 
RETURNS string 
LANGUAGE PYTHON AS $$
import json
import requests

def send_star_events_to_slack(value):
    for github_id in value:
        requests.post(
            "https://hooks.slack.com/services/T123/B456/other_id",
            data=json.dumps({
                "text": f"New 🌟 for Timeplus Proton from https://github.com/{github_id}"
            })
        )
    return value
$$

CREATE ALERT default.watch_event_alert
BATCH 10 EVENTS WITH TIMEOUT 5s
LIMIT 1 ALERTS PER 15s
CALL send_star_events_to_slack
AS 
SELECT actor 
FROM github_events 
WHERE repo = 'timeplus-io/proton' AND type = 'WatchEvent';
```

## Alert Management

| Action | SQL Command |
| --- | --- |
| **List Alerts** | `SHOW ALERTS` |
| **View Definition** | `SHOW CREATE ALERT alert_name` |
| **Remove Alert** | `DROP ALERT alert_name` |

## Best Practices
- **Avoid Noise**: Use `HAVING` clauses or `windowing` functions to prevent an alert from firing every millisecond.
- **Deduplication**: Use `LAG` or stateful functions if you only want to be alerted when a status *changes* from 'OK' to 'FAIL'.
- **Security**: When using Webhook sinks, store authentication tokens in environment variables (`${WEBHOOK_TOKEN}`) rather than plain text in the SQL definition.

references/EMIT_AND_UDAF.md

# EMIT Clauses & UDAF Emit Control

Two underused Proton features that solve problems people commonly try to hand-roll:

1. **`EMIT AFTER SESSION CLOSE IDENTIFIED BY (ts_col, start_col, end_col)`** — a
   declarative event-terminated session window. Use it when an aggregation should
   start on one event and emit on another, rather than on a wall-clock window or
   inactivity gap.
2. **`has_customized_emit: true`** in a JS/Python UDAF — the UDAF itself decides how
   many rows to emit per flush by returning an integer from `process()`. Returning
   `0` means "engine skips emit entirely." This replaces fragile manual
   `this.emitted = false` flags.

This file covers the full EMIT vocabulary, the engine constraints around
`SESSION CLOSE` / `KEY EXPIRE`, and the UDAF emit-count contract. For the basic
`EMIT AFTER WATERMARK` / `ON UPDATE` window policies, see
`TRANSFORMATIONS.md → EMIT Policies`. For UDAF structure (`initialize` / `process` /
`finalize` / `serialize` / `merge`), see `UDFS.md → JavaScript UDAF`.

**When to reach for this file:**

- Writing a streaming MV that fires on a specific event, not on a time window.
- Writing a JS or Python UDAF that emits duplicate rows or stray `false` rows.
- About to add `WHERE event_time > now() - INTERVAL N MINUTE` just to bound state in
  a streaming `GROUP BY`.
- Hand-rolling `this.emitted = false` / `this.fired = true` inside a UDAF to prevent
  re-emit.
- Hitting install-time errors like
  `NOT_IMPLEMENTED: EMIT AFTER SESSION CLOSE`,
  `UNSUPPORTED: MAXSPAN only supports millisecond, second or minute interval`, or
  `TIMEOUT interval shall be great or equal to MAXSPAN interval`.

**Do NOT use** for: scalar UDFs (stateless per-row); ClickHouse-only deployments
(these features are Proton-specific); historical-only batch queries (use
`table(stream)` and a regular `GROUP BY`).

---

## Full EMIT clause vocabulary

```
EMIT [STREAM | CHANGELOG | DELTA]
EMIT STREAM AFTER WINDOW CLOSE [WITH DELAY <interval>] [AND TIMEOUT <interval>]
EMIT STREAM PERIODIC <interval> [REPEAT] [WITH DELAY <interval>] [AND TIMEOUT <interval>]
EMIT ON UPDATE [WITH BATCH <interval>] [WITH DELAY <interval>] [AND TIMEOUT <interval>]
EMIT PER EVENT [WITH DELAY <interval>] [AND TIMEOUT <interval>]
EMIT LAST <interval> [ON PROCTIME]
EMIT [STREAM] AFTER KEY EXPIRE   [IDENTIFIED BY <ts_col>]                            WITH [ONLY] MAXSPAN <interval> [AND TIMEOUT <interval>]
EMIT [STREAM] AFTER SESSION CLOSE [IDENTIFIED BY (<ts_col>, <start_col>, <end_col>)] WITH [ONLY] MAXSPAN <interval> [AND TIMEOUT <interval>]
```

**`AFTER KEY EXPIRE` and `AFTER SESSION CLOSE` are aliases.** They share the same
execution machinery. The conventional distinction is the `IDENTIFIED BY` tuple shape:

- 1-tuple `IDENTIFIED BY ts_col` — "KEY EXPIRE" idiom: inactivity-only, no
  start/end events.
- 3-tuple `IDENTIFIED BY (ts_col, start_col, end_col)` — "SESSION CLOSE" idiom:
  event-bounded.

Whichever keyword you write, the same engine constraints apply (se

references/INGESTION.md

# Getting Data Into Timeplus

## 1. CREATE STREAM (Native Streams)

### Append Stream (default — immutable event log)

```sql
CREATE STREAM IF NOT EXISTS sensor_data (
    device_id   string,
    temperature float32,
    humidity    float32,
    location    string,
    ts          datetime64(3, 'UTC') DEFAULT now64(3, 'UTC')
)
SETTINGS
    event_time_column    = 'ts',
    logstore_retention_ms = 86400000,   -- 1 day retention
    shards               = 1,
    replication_factor   = 1;
```

Key `CREATE STREAM` settings:

| Setting | Default | Description |
|---------|---------|-------------|
| `event_time_column` | `_tp_time` | Column to use as event time |
| `logstore_retention_ms` | 604800000 | Log retention in ms (7 days) |
| `logstore_retention_bytes` | ∞ | Log retention in bytes |
| `shards` | 1 | Number of shards (parallelism) |
| `replication_factor` | 1 | Replication factor |
| `logstore_codec` | none | Compression: `none`, `zstd`, `lz4` |
| `storage_type` | `streaming` | `streaming`, `hybrid`, `memory` |

**TTL (auto-expiry):**
```sql
CREATE STREAM events (
    id string,
    payload string
) TTL _tp_time + INTERVAL 7 DAY;
```

---

### Versioned KV Stream (latest value per key)

Use for dimension tables / lookup tables that change over time.

```sql
CREATE STREAM IF NOT EXISTS products (
    product_id string,
    name       string,
    price      float32,
    category   string
)
PRIMARY KEY (product_id)
SETTINGS mode = 'versioned_kv';
```

- Only the **latest** row per primary key is retained for lookups.
- You can JOIN an append stream to a versioned_kv stream to enrich events.
- Composite primary keys: `PRIMARY KEY (tenant_id, product_id)`.

---

### Changelog KV Stream (insert / update / delete tracking)

```sql
CREATE STREAM IF NOT EXISTS inventory (
    item_id   string,
    quantity  int32,
    updated   datetime64(3) DEFAULT now64(3)
)
PRIMARY KEY (item_id)
SETTINGS mode = 'changelog_kv';
```

Write `_tp_delta = 1` for INSERT/UPDATE, `_tp_delta = -1` for DELETE.

---

### Mutable Stream (Enterprise — full row-level mutations)

```sql
CREATE MUTABLE STREAM IF NOT EXISTS user_profiles (
    user_id   string,
    name      string,
    email     string,
    score     float32,
    INDEX idx_email (email) UNIQUE
)
PRIMARY KEY (user_id)
SETTINGS ttl_seconds = 604800;
```

Supports `UPDATE` and `DELETE` statements. Good for entity tables.

---

## 2. INSERT INTO (Direct Write)

```sql
-- Single row
INSERT INTO sensor_data (device_id, temperature, humidity, location)
VALUES ('dev-001', 23.5, 61.2, 'warehouse-a');

-- Multiple rows
INSERT INTO sensor_data (device_id, temperature, humidity, location) VALUES
('dev-002', 19.1, 70.0, 'office'),
('dev-003', 31.4, 45.5, 'rooftop');

-- From another stream (batch copy)
INSERT INTO sensor_data SELECT device_id, temperature, humidity, location
FROM table(sensor_data_archive);
```

**Via curl:**
```bash
echo "INSERT INTO sensor_data (device_id, temperature) VALUES ('dev-1', 22.0)" | \
  curl "http:/

Sponsored

Ads related to timeplus-sql-guide and adjacent AI workflows.