semantic-sql-history-profiler
GitHub在编写语义模型YAML前,通过分析历史SQL和列分布数据来挖掘证据。该工作流用于生成统计信息、数据分布分析及SQL挖掘,为模型形状决策提供依据,包括关系推断、键验证及字段描述优化。
Trigger Scenarios
Install
npx skills add Datus-ai/Datus-agent --skill semantic-sql-history-profiler -g -y
SKILL.md
Frontmatter
{
"name": "semantic-sql-history-profiler",
"tags": [
"semantic-model",
"sql-history",
"profiling"
],
"version": "1.1.0",
"description": "Optional semantic-model profiling workflow that mines historical SQL and bounded column distributions before YAML authoring",
"allowed_agents": [
"semantic_modeling",
"gen_semantic_model"
],
"user_invocable": false,
"disable_model_invocation": false
}
Semantic SQL History Profiler
Use this workflow when the skill is loaded because the user explicitly asked for profiling, statistics, data-distribution analysis, or mining/analyzing historical SQL. Providing SQL alone is not a trigger. Once loaded, run the profiler before semantic YAML authoring.
Workflow
-
Call
profile_semantic_model_evidencebefore writing semantic model YAML.- When historical SQL is provided inline, pass every provided SQL statement via
sql_entries_jsonorsql_queries; do not choose only representative examples. Default toprofile_mode="sql_only". - Use
query_textonly when direct SQL text is unavailable and existing reference SQL must be searched. - Use
profile_mode="lightweight"with the targettableswhen the user asks for statistics or field distributions — this also works with no SQL at all (pure bounded distribution profiling). - Use
profile_mode="deep"only when the user explicitly allows a slower exploration. - Set conservative bounds such as
max_tables,max_columns_per_table,top_n, andmax_profile_seconds.
- When historical SQL is provided inline, pass every provided SQL statement via
-
Use the evidence to decide the model shape:
- Join relationships from historical SQL become relationship and candidate-key hints, not proven keys. When one JOIN clause has multiple equality predicates, keep its ordered
source_columns/target_columnstogether as one composite relationship. - Before putting historical target columns in
unique_keys, collect every complete ordered target list you intend to use and submit them together tovalidate_semantic_key_candidates. Only passing full-table results are key evidence; profiling samples are not. - Group-by and filter fields are dimension candidates.
- Aggregate expressions and numeric profiles are measure candidates.
- Min/max values, percentiles, and null/fill rates help describe numeric ranges and data quality.
- Date spans, freshness, and duration profiles help identify usable time columns and common lifecycle intervals.
- Top values and distinct ratios help detect enum-like categorical columns.
- Referential coverage and join fanout hints help judge relationship reliability.
- Common filter templates help capture reusable row-selection semantics without copying long SQL.
- Join relationships from historical SQL become relationship and candidate-key hints, not proven keys. When one JOIN clause has multiple equality predicates, keep its ordered
-
Put useful distribution evidence into YAML descriptions while keeping them readable:
- Start with the DDL comment or stable business meaning.
- Add a compact distribution note when it helps downstream generation:
- numeric fields: include observed min/max, p50/p90, or null rate when material.
- date/time fields: include observed span, freshness, or paired duration when useful.
- low-cardinality categorical fields: include distinct count and representative stable values.
- enum-like fields: include the full stable code mapping when available.
- relationship hints: mention low referential coverage or fanout only when it affects join semantics.
- filter templates: mention common equality/range/text-search/function filters only when backed by history.
- Convert raw evidence into concise semantic phrasing. Prefer "Order status, 4 distinct values; common values include paid/refund" over dumping profiler JSON.
- Do not include SQL snippets longer than a short operator/function hint, and do not paste entire top-N lists or long filter examples.
- Prefer omitting a field over writing a low-confidence or very verbose description.
-
Treat profiling evidence as non-exhaustive.
- Sampled top values and min/max values are hints, not hard constraints.
- Historical JOIN frequency, referential coverage, and sampled distinct ratios do not prove uniqueness.
- If evidence conflicts with DDL comments or validation, prefer DDL comments and validated schema.
-
Validate and publish exactly as in the active semantic-model authoring workflow.
Version History
- 8fb79f6 Current 2026-08-20 12:34


