Run KaiwuDB inspection and health-check tasks. Use this skill for database health checks, metrics collection, anomaly detection, and inspection report generation.
数据分析
KWDB Text2SQL AIoT
试用Convert natural language queries to KWDB SQL for time series data, relational data and cross-model analysis. Use this skill whenever users ask to query KWDB databases, write SQL for KWDB, or convert natural language to KWDB-specific SQL syntax. Supports: CREATE DATABASE/TABLE, downsampling, interpolation, latest value queries, aggregation analysis, cross-model queries, window/session/event analysis.
它能做什么
Convert natural language queries to KWDB SQL for time series data, relational data and cross-model analysis. Use this skill whenever users ask to query KWDB databases, write SQL for KWDB, or convert natural language to KWDB-specific SQL syntax. Supports: CREATE DATABASE/TABLE, downsampling, interpolation, latest value queries, aggregation analysis, cross-model queries, window/session/event analysis.
技能文档
KWDB Text-to-SQL Skill
Query Type Routing
Based on the user's query, read the appropriate reference file:
| Query Type | Reference File |
|---|---|
| Query routing (start here) | references/scenarios.md |
| MCP integration | references/mcp-integration.md |
| 时序DDL (创建时序库/表) | references/ts-ddl.md |
| 聚合操作及降采样 (每小时/每天统计) | references/ts-downsampling.md |
| 插值/填充缺失值 | references/ts-interpolation.md |
| 最新值查询 | references/ts-latest-value.md |
| 滑动窗口/session/event | references/ts-window-events.md |
| 关系表查询 | references/relational.md |
| 跨模查询(时序表+关系表) | references/cross-model.md |
| 时序函数语法速查 | references/ts-functions.md |
| 关系函数语法速查 | references/relational-functions.md |
Quick Reference
| NL Pattern | SQL Pattern |
|---|---|
| 最近N分钟/小时/天的数据 | WHERE ts >= NOW() - INTERVAL 'N hour' |
| 每小时/每天的平均值 | time_bucket(ts, '1h/1d') + avg(col) |
| 每N分钟/小时/天降采样 | time_bucket(ts, 'X') + aggregation |
| 填充缺失值 | time_bucket_gapfill() + interpolate() |
| 最新数据 | last(col) or ORDER BY ts DESC LIMIT 1 |
| 滑动窗口 | TIME_WINDOW(ts, '1h', '15m') |
| 关联设备信息 | JOIN devices ON ... |
Workflow
Phase 0: MCP Detection & Schema Discovery (Recommended)
-
Detect MCP availability: Call
read-querywithSELECT 1- If successful → MCP is available
- If failed → MCP is unavailable, proceed to fallback
-
Get database name (if not provided by user):
- Ask user: "请提供要查询的数据库名称"
- Or execute
SHOW DATABASESto list all databases
-
Discover tables in database: Execute
SHOW TABLES FROM {database_name} -
Identify candidate tables:
- Match NL keywords to table names (e.g., "传感器" → sensor_data)
- If multiple candidates → ask user: "请确认表名: [A, B, C]?"
-
Get table schema: Execute
SHOW CREATE TABLE {database_name}.{table_name}, do not useDESCRIBE- Note column names, types, primary key, tags, comments
- Map NL field names to actual column names
-
Proceed to Phase 1 with verified schema
Phase 0 Fallback: No MCP Available
When MCP is unavailable:
-
Option A - Ask user: "请提供表结构信息(表名、列名)"
- Wait for user to describe the schema
- Proceed to Phase 1
-
Option B - Use assumed fields: "我将使用常见字段名生成 SQL,请验证"
- Use standard field names (ts, device_id, temperature, etc.)
- Mark output as "ASSUMED SCHEMA - please verify"
-
Proceed to Phase 1
Phase 1: Query Type Routing
- Read scenarios.md:
references/scenarios.md- single entry point with decision tree - Route to scenario file based on query type:
- aggregation/downsampling →
ts-downsampling.md - interpolation →
ts-interpolation.md - latest value →
ts-latest-value.md - window/session/event →
ts-window-events.md - cross-model →
cross-model.md - relational →
relational.md
- aggregation/downsampling →
- Function syntax → see
ts-functions.md(time-series) orrelational-functions.md(relational)
Phase 2: SQL Generation
- Extract entities: Table name, columns, time range, conditions
- Use schema from Phase 0 (if MCP was used)
- Generate SQL: Use patterns from reference to construct SQL
- Validate: Ensure SQL follows KWDB function syntax
Phase 3: Output
- Format output: Follow
assets/output-template.md - Include field mapping if MCP was used
- Mark assumptions if schema was assumed
- Add verification checklist
Phase 4: KWDB Execute
Prerequisite: SQL has been generated in Phase 2 and formatted in Phase 3.
Step 1: Check MCP Availability
Note: If MCP was successfully used in Phase 0 and schema was discovered, MCP is available. If Phase 0 indicated MCP was unavailable, skip this phase entirely.
If MCP availability is unknown (e.g., Phase 0 was skipped), verify now:
- Call
read-querywithSELECT 1 - If successful → MCP is available, proceed to Step 2
- If failed → MCP is unavailable, skip this phase entirely and end workflow
Step 2: Ask User for Execution Confirmation
Prompt user:
生成的 SQL 已准备就绪。是否需要通过 kwdb-mcp-server 执行该 SQL?
- 输入 "是" 或 "执行" → 继续执行
- 输入 "否" 或 "跳过" → 结束,不再执行
If user declines → end workflow.
Step 3: Determine Query Type
Analyze the generated SQL:
- Read query: SELECT, SHOW, EXPLAIN → use
read-query - Write query: INSERT, UPDATE, DELETE, CREATE, DROP, ALTER → use
write-query
Step 4: Execute Query
Call the appropriate MCP tool:
For read queries (read-query):
{
"sql": ""
}
For write queries (write-query):
{
"sql": ""
}
Step 5: Handle Execution Result
On Success: Report to user:
## Execution Result
- Status: success
- Query Type: read / write
- Row Count: N
- Auto-Limited: true/false
### Results
[formatted table if applicable]
On Failure:
- Parse the error message to identify error type (see Error Type table in Error Handling section below)
- If error indicates SQL generation issue (wrong table name, wrong column, syntax error):
- Explain to user: "SQL 执行失败,正在分析错误原因..."
- Report the error and analysis:
## Execution Result - Status: failed - Error: [error message] - Analysis: [cause analysis] - Return to Phase 1 with error context to regenerate SQL
- If error indicates user data issue (constraint violation, permission issue, etc.):
- Report the error and suggest fixes, but do not auto-regenerate
Reference Files
references/scenarios.md- Query routing entry point (decision tree)references/mcp-integration.md- How to use kwdb-mcp-server for schema discoveryreferences/ts-ddl.md- Time series DDL (CREATE DATABASE/TABLE with TAGS)references/ts-downsampling.md- time_bucket for fixed-interval downsamplingreferences/ts-interpolation.md- time_bucket_gapfill + interpolate for gap fillingreferences/ts-latest-value.md- first/last/last_row for latest value queriesreferences/ts-window-events.md- TIME_WINDOW, SESSION_WINDOW, EVENT_WINDOW, TWA, diffreferences/relational.md- Standard SQL for relational tablesreferences/cross-model.md- JOIN between relational and time seriesreferences/ts-functions.md- KWDB time-series function syntax referencereferences/relational-functions.md- KWDB relational function syntax reference
Guardrails
- Always verify table existence when MCP is available
- Confirm column names match actual schema before generating SQL
- Ask for time range if user doesn't specify
- Add LIMIT clause for queries without one (MCP auto-adds LIMIT 20, but you should be explicit)
- Mark assumed schema when MCP is unavailable
- Handle ambiguous NL by asking clarifying questions
Error Handling (Authoritative Reference)
This Error Type table is used by:
- Phase 4 Step 5 when SQL execution fails
- When user reports that generated SQL failed
When a user reports that generated SQL failed, diagnose and regenerate:
| Error Type | Likely Cause | Fix |
|---|---|---|
relation "xxx" does not exist | Wrong table name | Ask user to confirm table name, re-discover via MCP |
column "xxx" not found | Wrong column name | Use MCP to re-read schema, update field mapping |
syntax error | SQL syntax issue | Review KWDB SQL syntax, check function parameter order |
invalid interval | Wrong interval format | Use format like '1h', '1d', '5m' — not复合格式 like '1d1h' |
| Overflow / out of range | Aggregation result too large | Add filters to reduce result set size |
ambiguous column reference | Column name exists in both joined tables | Use fully-qualified column names (table.column) |
permission denied | No write permission | Report to user, do not regenerate |
duplicate key | Constraint violation | Report to user, do not regenerate |
When SQL fails:
- Read the error message to identify the error type
- If schema issue → re-run MCP discovery
- If syntax issue → check
ts-functions.mdorrelational-functions.mdand relevant reference file - If data issue → ask user for clarification
- Regenerate corrected SQL with explanation
Schema Discovery via MCP
Use read-query tool to execute SHOW commands:
| SQL Command | Purpose |
|---|---|
SHOW DATABASES | List all databases |
SHOW TABLES FROM {database_name} | List all tables in a database |
SHOW CREATE TABLE {database_name}.{table_name} | Get table structure (columns, types, tags, comments) |
相关技能
Design KWDB schemas and generate DDL for relational, time-series, and mixed workloads. Covers: CREATE/ALTER/DROP TABLE, INDEX, VIEW, constraints, partitioning, retention, tags. Trigger keywords: KWDB, schema, table, index, time-series, sensor, IoT, metrics, TAGS, PRIMARY TAGS, RETENTIONS, primary key, foreign key, DDL. NOT for: DML queries, deployment, backup, performance tuning.
Convert natural language to SQL, explore database schemas, execute queries safely, and get optimization suggestions.
Automates end-to-end anomaly detection for time-series data stored in KaiwuDB / KWDB. Use this skill whenever the user mentions: - anomaly detection, outliers, or unusual patterns in KWDB / KaiwuDB time-series data - inspecting sensor metrics, IoT telemetry, or monitoring data for spikes, dips, or drift - "find anomalies", "detect outliers", "3-sigma check", "STL decomposition", or "time-series anomaly" - analyzing historical trends, abnormal points, or data quality issues in TS tables Even if the user does not explicitly say "anomaly", trigger this skill when they ask to inspect, validate, or flag unusual values in time-series columns (integer, float, double).
Support generating SQL queries through natural language; use when users need to configure Text-to-SQL database, manage data topics, or generate SQL with natural language questions
Automated heterogeneous database migration skill for KaiwuDB / KWDB via KDTS REST API. Use this skill whenever the user mentions: - heterogeneous migration, cross-database migration, or data migration to KaiwuDB / KWDB - KDTS, migration tool, or data transfer between different databases - Specific source databases: MySQL, Oracle, PostgreSQL, SQL Server, ClickHouse, TDengine, InfluxDB, OpenTSDB, MongoDB, FTP, HDFS - Migration operations: create migration task, configure data source, test connection, import data, sync schema, batch migration - Migration management: query task status, view migration progress, check logs, kill migration, export/import config - Data type mapping, table structure sync, DDL generation, schema validation Even if the user does not explicitly say "migration", trigger this skill when they ask to transfer or sync data between databases with different engines.