SuperAPI AI Directory

smart-data-query

Data & analytics

View repository

Updated 10-16 05:05

About this skill

Goal

Generate executable final SQL based on the "requirements text + data warehouse catalog", satisfying readability, executability, and acceptance.

Default strategy (reduce questions, produce results first)

Core principle: do not ask too many questions; produce the SQL first, and adjust based on user feedback after they review it.

Item Default behavior
Data warehouse catalog Current catalog (ask only if not found)
Output fields Decide on your own (do not ask the user)
Time range Latest partition MAX(dt)(do not ask)
Layered table selection ADS → DWS → DWT (do not ask)
Table name format With database name prefix, prod environment
Process
  1. Build catalog index: Run scripts/build_catalog.py to generate the catalog
  2. Select tables: By ADS → DWS → DWT priority, use scripts/search_catalog.py to search
  3. Read table documentation: Confirm granularity, partition fields, and metric definitions
  4. Assemble SQL:
    • For array fields, by default use LATERAL VIEW EXPLODE to fully expand
    • For multi-condition filtering, clarify intersection/union logic
    • For partition filtering, use SELECT MAX(dt) for dynamic retrieval
    • CTE structure:base → agg → dim → final
  5. Self-check: Fields exist, join key types are consistent, group by matches select, partition pushdown
  6. Output: Executable SQL with database names + Chinese aliases
Guardrails
  • Prohibit generating destructive statements (DROP/TRUNCATE/DELETE/INSERT OVERWRITE)
  • Prohibit TRANSFORM functions and subquery expressions in SELECT/ON (Hive compatibility)
  • When definitions are uncertain, provide multi-branch SQL or explain assumptions in comments
Wrap-up

After each delivery:

  1. Write to log (scripts/log_qa.py)
  2. Ask the user: "Is this result usable? Reply good or bad + reason"
  3. Update log tags

See references/日志与迭代机制.md

Resources
Purpose Path
Generate index scripts/build_catalog.py
Search candidate tables scripts/search_catalog.py
SQL static check scripts/check_query.py
Record logs scripts/log_qa.py
Requirements questionnaire references/问数需求问卷模板.md
Dialect compatibility references/方言与兼容性.md
Usage examples references/调用示例.md