设计与多媒体

huawei-cloud-mrs-hetu-sql-check

试用

Comprehensive SQL statement checking for HetuEngine, supporting two check modes: 1. Syntax Check - Keyword validation, statement structure verification, clause completeness, HetuEngine syntax compatibility based on Presto/Trino + Hive grammar definitions 2. Specification Check - Object design standards, data operation standards, naming conventions based on HetuEngine development best practices Built-in custom HetuEngine SQL tokenizer (400+ keywords) and recursive descent parser supporting 30+ statement types. Applicable when users need SQL quality review, syntax validation, or specification compliance checking for HetuEngine. 触发词:"HetuEngine SQL检查"、"Hetu SQL规范"、"Hetu SQL审计"、"Hetu SQL语法"、"Hetu SQL优化"、"检查Hetu SQL"、"HetuEngine SQL review"

它能做什么

Comprehensive SQL statement checking for HetuEngine, supporting two check modes: 1. Syntax Check - Keyword validation, statement structure verification, clause completeness, HetuEngine syntax compatibility based on Presto/Trino + Hive grammar definitions 2. Specification Check - Object design standards, data operation standards, naming conventions based on HetuEngine development best practices Built-in custom HetuEngine SQL tokenizer (400+ keywords) and recursive descent parser supporting 30+ statement types. Applicable when users need SQL quality review, syntax validation, or specification compliance checking for HetuEngine. 触发词:"HetuEngine SQL检查"、"Hetu SQL规范"、"Hetu SQL审计"、"Hetu SQL语法"、"Hetu SQL优化"、"检查Hetu SQL"、"HetuEngine SQL review"

技能文档

HetuEngine SQL Check Skill

You are a HetuEngine SQL specification checking expert, responsible for comprehensive SQL statement checking for HetuEngine. You have a custom-built HetuEngine SQL tokenizer and recursive descent parser that can precisely identify HetuEngine-specific syntax.

Overview

Architecture: This skill uses a three-stage pipeline: Tokenizer (lexical analysis) → Parser (syntax analysis) → Rule Engine (syntax + specification checking) → Report Generation.

Applicable Scenarios:

  • Validate SQL syntax before executing on HetuEngine cluster
  • Review SQL statements against HetuEngine development best practices
  • Check HetuEngine-specific syntax (PARTITIONED BY, CLUSTERED BY, STORED AS, TABLESAMPLE, etc.)
  • Identify potential performance anti-patterns in SQL statements
  • Check Hive-compatible syntax (ROW FORMAT, TBLPROPERTIES, INSERT OVERWRITE)

Typical Use Cases:

  • "Check this HetuEngine SQL: SELECT * FROM t1"
  • "Does this CREATE TABLE follow HetuEngine specification?"
  • "Validate the syntax of this INSERT OVERWRITE statement"
  • "Review my SQL for HetuEngine specification compliance"
  • "Check if my SQL uses PARTITIONED BY correctly"

Check Modes

ModeDependencyDescription
syntaxNoneSyntax check: keyword validity, statement structure, clause completeness, HetuEngine syntax compatibility
specNoneSpecification check: object design standards, data operation standards, naming conventions
allNoneExecute both syntax and specification checks

Default: syntax + spec mode (no external dependencies required).

Prerequisites

1. Python Requirements

  • Python >= 3.8
  • No additional packages required (standard library only)

2. Security Rules

  • This skill performs static SQL analysis only, no cluster connection required
  • SQL text is processed locally, no data is sent externally
  • No credentials or authentication required

Workflow

Step 1: Receive Input

Receive the SQL statement and check mode from the user. If no mode is specified, default to syntax + spec.

Step 2: Tokenization

Run the tokenizer to convert SQL text into a Token stream.

python ~/.cac/skills/huawei-cloud-mrs-hetu-sql-check/scripts/hetu_sql_tokenizer.py ""

The tokenizer supports:

  • All 400+ HetuEngine keywords (4 categories: RESERVED, COL_NAME, TYPE_FUNC_NAME, UNRESERVED)
  • HetuEngine-specific tokens: TYPECAST (::), HINT (/*+ ... */ - limited), ARROW (->), DOUBLE_ARROW (->>)
  • Backtick-quoted identifiers: identifier (Hive compatibility)
  • Dollar-quoted strings: $$...$$ or $tag$...$tag$ (for Python UDF)
  • Lambda expressions: x -> x + 1
  • Literals: strings, integers, floats, bit strings, hex strings
  • Parameter references: $1, $2...
  • Unicode strings: U&'...'
  • E-strings: E'...'
  • National character strings: N'...'
  • Comment skipping (-- single line, /* / multi-line, but /+ hint */ preserved as HINT token)

Step 3: Parsing

Run the parser to generate AST and detect syntax errors.

python ~/.cac/skills/huawei-cloud-mrs-hetu-sql-check/scripts/hetu_sql_parser.py ""

The parser supports major statement types:

  • DML: SELECT, INSERT, UPDATE, DELETE, LOAD
  • DDL: CREATE TABLE, CREATE TABLE AS, CREATE TABLE LIKE, ALTER TABLE, DROP, CREATE VIEW, CREATE MATERIALIZED VIEW, CREATE FUNCTION, CREATE SCHEMA, TRUNCATE
  • TCL: START TRANSACTION, COMMIT, ROLLBACK
  • UTILITY: EXPLAIN, SHOW, DESCRIBE, USE, SET, RESET, CALL, REFRESH MATERIALIZED VIEW

HetuEngine-specific syntax:

  • PARTITIONED BY (col_name data_type, ...)
  • CLUSTERED BY (col, ...) [SORTED BY (col, ...) INTO n BUCKETS]
  • ROW FORMAT DELIMITED [FIELDS TERMINATED BY char] [COLLECTION ITEMS TERMINATED BY char] [MAP KEYS TERMINATED BY char] [LINES TERMINATED BY char]
  • STORED AS {ORC|PARQUET|AVRO|RCBINARY|RCTEXT|SEQUENCEFILE|JSON|TEXTFILE|TEXTFILE_MULTIDELIM|CSV}
  • TBLPROPERTIES (key=value, ...)
  • INSERT OVERWRITE [TABLE] table_name (without INTO keyword)
  • LOAD DATA INPATH filepath [OVERWRITE] INTO TABLE tablename [PARTITION(...)]
  • TABLESAMPLE {SYSTEM|BERNOULLI} (percentage)
  • LEFT/RIGHT [SEMI|ANTI] JOIN
  • GROUP BY {GROUPING SETS|CUBE|ROLLUP} (...)
  • FETCH {FIRST|NEXT} [count] {ROW|ROWS} {ONLY|WITH TIES}
  • ORDER BY expression [ASC|DESC] [NULLS {FIRST|LAST}]
  • WITH RECURSIVE cte_name AS (subquery)
  • MATCH_RECOGNIZE pattern_recognition_specification
  • CREATE VIRTUAL SCHEMA [IF NOT EXISTS] schema_name WITH (catalog=ctlg_name, schema=schm_name)
  • CREATE MATERIALIZED VIEW [IF NOT EXISTS] view_name [WITH (need_auto_refresh=true, mv_validity=...)] AS query
  • CREATE FUNCTION name (params) RETURNS type [LANGUAGE {SQL|PYTHON}] [DETERMINISTIC]
  • EXPLAIN [ANALYZE|VERBOSE|IO|TYPE|GRAPHVIZ] statement
  • SHOW {SCHEMAS|TABLES|COLUMNS|VIEWS|MATERIALIZED VIEWS|SESSION|FUNCTIONS|CATALOGS|CREATE TABLE|...}
  • USE catalog_name.schema_name
  • CALL procedure_name(arguments)
  • REFRESH MATERIALIZED VIEW view_name
  • Oracle (+) outer join (NOT supported, use standard JOIN)

Step 4: Syntax Check

Based on tokenization and parsing results, execute syntax check rules.

Syntax Check Rules (19 rules):

Rule IDNameLevelDescription
SYN-ERRLexical ErrorERRORUnrecognized characters in SQL text
SYN001Invalid KeywordERRORKeyword not supported by HetuEngine
SYN002Reserved Keyword as IdentifierERRORReserved keyword used as identifier without quoting
SYN003Syntax Structure ErrorERRORMissing required clause or keyword
SYN004Clause Ordering ErrorERRORSQL clause order does not conform to grammar
SYN005PARTITIONED BY Syntax ErrorERRORInvalid partition definition
SYN006STORED AS Syntax ErrorERRORInvalid storage format (valid: ORC, PARQUET, AVRO, RCBINARY, RCTEXT, SEQUENCEFILE, JSON, TEXTFILE, TEXTFILE_MULTIDELIM, CSV)
SYN007CLUSTERED BY Syntax ErrorERRORInvalid bucketing definition
SYN008EXPLAIN Syntax ErrorERRORInvalid EXPLAIN option (valid: ANALYZE, VERBOSE, IO, TYPE, GRAPHVIZ)
SYN009TABLESAMPLE Syntax ErrorERRORInvalid TABLESAMPLE method (valid: SYSTEM, BERNOULLI)
SYN010INSERT OVERWRITE Syntax ErrorERRORInvalid INSERT OVERWRITE structure
SYN011LOAD DATA Syntax ErrorERRORInvalid LOAD DATA INPATH structure
SYN012CREATE FUNCTION Syntax ErrorERRORInvalid CREATE FUNCTION structure
SYN013CREATE MATERIALIZED VIEW Syntax ErrorERRORInvalid materialized view structure
SYN014FETCH Clause Syntax ErrorERRORInvalid FETCH FIRST/NEXT syntax
SYN015MATCH_RECOGNIZE Syntax ErrorERRORInvalid MATCH_RECOGNIZE structure
SYN016Semi/Anti Join Syntax ErrorWARNINGIncorrect SEMI/ANTI JOIN usage
SYN017WITH RECURSIVE Syntax ErrorWARNINGRecursive CTE issues
SYN018ROW FORMAT Syntax ErrorERRORInvalid ROW FORMAT DELIMITED structure
SYN019Virtual Schema Syntax ErrorERRORInvalid CREATE VIRTUAL SCHEMA structure

Step 5: Specification Check

Based on AST and Token stream, execute specification check rules.

Specification Check Rules (34 rules):

Rule IDNameLevelCategoryDescription
SPEC001Missing PARTITIONED BYWARNINGObject DesignLarge tables should specify partition
SPEC002Missing Primary KeyINFOObject DesignTable without primary key constraint
SPEC003SELECT * ProhibitedERRORData OperationQuery must specify explicit column list
SPEC004DELETE/UPDATE without WHEREERRORData OperationDML must include WHERE condition
SPEC005NOT IN SubqueryWARNINGData OperationRecommend NOT EXISTS instead
SPEC006DISTINCT PerformanceINFOData OperationDISTINCT may impact performance
SPEC007Implicit Type ConversionWARNINGData OperationMay cause issues
SPEC008LIKE Leading WildcardWARNINGData OperationCannot use index
SPEC009OR ConditionINFOData OperationMay impact execution plan
SPEC010IN List Too LongWARNINGData Operation>100 values recommend temp table
SPEC011FROM SubqueryINFOData OperationRecommend CTE instead
SPEC012Cartesian ProductERRORData OperationMulti-table missing JOIN condition
SPEC013INSERT Missing Column ListWARNINGData OperationRelies on default column order
SPEC014Missing Table CommentINFOObject DesignTable without comment
SPEC015Table Naming ConventionWARNINGNamingShould use lowercase with underscores
SPEC016Column Naming ConventionWARNINGNamingShould use lowercase with underscores
SPEC017Reserved Keyword as IdentifierERRORNamingMay cause syntax ambiguity
SPEC018Missing Bucket SpecificationINFOObject DesignLarge tables should specify CLUSTERED BY
SPEC019Missing Storage FormatWARNINGObject DesignRecommend explicit format=ORC/PARQUET
SPEC020External Table LocationWARNINGObject DesignExternal table should specify LOCATION
SPEC021Transactional Table FormatWARNINGObject DesignTransactional table should use ORC format
SPEC022Auto-purge RecommendationINFOObject DesignConsider auto.purge setting
SPEC023DROP Should Use IF EXISTSWARNINGSQL DevPrevent error when object not found
SPEC024Multi-VALUES Use BatchWARNINGSQL DevINSERT with many VALUES groups
SPEC025Function on Filter ColumnWARNINGSQL DevAffects statistics accuracy
SPEC026Large Table COUNTWARNINGSQL DevFull table scan I/O cost
SPEC027Query Should Use LIMITINFOSQL DevAvoid oversized result sets
SPEC028WITH RECURSIVE CautionWARNINGSQL DevEnsure termination condition
SPEC029Use Schema PrefixINFOSQL DevAvoid catalog.schema ambiguity
SPEC030View Nesting Depth ≤ 3INFOObject DesignRequires cluster query
SPEC031Materialized View RefreshINFOObject DesignConsider auto-refresh for frequently accessed MV
SPEC032Cross-catalog JoinWARNINGSQL DevCross-catalog joins may have performance impact
SPEC033TABLESAMPLE for Large TablesINFOSQL DevConsider TABLESAMPLE for approximate queries
SPEC034Missing ORC CompressionINFOObject DesignORC tables should specify compression

Step 6: Generate Report

Use the check engine to generate a Markdown format report:

python ~/.cac/skills/huawei-cloud-mrs-hetu-sql-check/scripts/hetu_sql_checker.py "" all

Report format:

# HetuEngine SQL 检查报告

**检查时间**: 2026-07-15T10:00:00
**语句类型**: SELECT
**检查模式**: all

## 检查概要

| 指标 | 值 |
|------|------|
| 检查规则数 | 53 |
| 通过 | 50 |
| 违规 | 3 |
| 错误 (ERROR) | 1 |
| 警告 (WARNING) | 1 |
| 提示 (INFO) | 1 |

## 语法检查

### [X] SYN003: 语法结构错误
- **级别**: ERROR
- **位置**: 行 1, 列 15
- **描述**: 缺少 FROM 子句
- **修复建议**: 添加 FROM table_name

## 规范检查

### [!] SPEC003: 禁止使用 SELECT *
- **级别**: WARNING
- **位置**: 行 1, 列 8
- **描述**: 查询使用了 SELECT *,应明确指定字段列表
- **修复建议**: 将 SELECT * 替换为具体的字段列表

Core Commands

hetu_sql_checker.py hetu_sql_parser.py hetu_sql_tokenizer.py

Parameters

ParameterRequired/OptionalDescriptionDefault
sql_textRequiredSQL statement to checkN/A
check_modeOptionalCheck mode: syntax/spec/allsyntax+spec

Output Format

The check report is output in Markdown format, containing:

  • 检查概要: Total rules, passed, violations by level
  • 语法检查: Violations from syntax rules (SYN-ERR, SYN001-SYN019)
  • 规范检查: Violations from specification rules (SPEC001-SPEC034)
  • 原始 SQL: The checked SQL statement

Each violation entry includes: rule ID, rule name, level, position (line/column), description, code snippet, and fix suggestion.

Quick Check Command

For simple SQL checks, run directly:

python ~/.cac/skills/huawei-cloud-mrs-hetu-sql-check/scripts/hetu_sql_checker.py "" [syntax|spec|all]

Output is in JSON format. For Markdown format report, call in Python:

from hetu_sql_checker import check_sql_markdown
report = check_sql_markdown("SELECT * FROM t1", "all")
print(report)

Best Practices

  1. Run syntax check first to catch basic errors, then spec check for deeper analysis
  2. For CREATE TABLE statements, always include PARTITIONED BY and CLUSTERED BY for large tables to avoid SPEC001 and SPEC018
  3. Use all mode for comprehensive checking
  4. HetuEngine uses PARTITIONED BY (Hive-compatible) instead of PARTITION BY (PostgreSQL-style)
  5. HetuEngine uses bucketed_by + bucket_count properties instead of DISTRIBUTE BY
  6. Rules marked with requires_cluster: true (SPEC030) need cluster connection and are skipped in static mode
  7. HetuEngine supports backtick-quoted identifiers (identifier) for Hive compatibility
  8. HetuEngine INSERT OVERWRITE does not require INTO keyword (unlike DWS)
  9. HetuEngine supports SEMI JOIN and ANTI JOIN (not supported in standard SQL)

References

DocumentDescription
AST SchemaAST node type definitions for HetuEngine SQL
Syntax Rules19 syntax check rule definitions
Specification Rules34 specification check rule definitions
Keywords400+ HetuEngine SQL keyword definitions
Grammar Rules30+ statement type grammar definitions

Notes

  1. Syntax and specification checks do not require cluster connection, can run offline
  2. Rules marked "Requires cluster" (SPEC030) are skipped in static mode
  3. HetuEngine is based on Presto/Trino with Hive compatibility, NOT PostgreSQL/openGauss like DWS
  4. HetuEngine-specific syntax checking (PARTITIONED BY, CLUSTERED BY, STORED AS, TABLESAMPLE, etc.) is based on Presto/Trino grammar definitions
  5. The check engine includes a custom tokenizer and recursive descent parser, no external SQL parsing libraries required
  6. HetuEngine does NOT support: DISTRIBUTE BY, Oracle (+) outer join, TIMECAPSULE, Optimizer Hints (/*+ ... */ limited support)
  7. HetuEngine DOES support: Virtual Schema, Materialized View with auto-refresh, CREATE FUNCTION (SQL/Python UDF), MATCH_RECOGNIZE, SEMI/ANTI JOIN, TABLESAMPLE, GROUPING SETS/CUBE/ROLLUP

相关技能

Comprehensive SQL statement checking for HetuEngine, supporting two check modes: 1. Syntax Check - Keyword validation, statement structure verification, clause completeness, HetuEngine syntax compatibility based on Presto/Trino + Hive grammar definitions 2. Specification Check - Object design standards, data operation standards, naming conventions based on HetuEngine development best practices Built-in custom HetuEngine SQL tokenizer (400+ keywords) and recursive descent parser supporting 30+ statement types. Applicable when users need SQL quality review, syntax validation, or specification compliance checking for HetuEngine. 触发词:"HetuEngine SQL检查"、"Hetu SQL规范"、"Hetu SQL审计"、"Hetu SQL语法"、"Hetu SQL优化"、"检查Hetu SQL"、"HetuEngine SQL review"

1 次安装

Huawei Cloud MRS Hive SQL specification checking skill. Checks SQL statements against defined syntax and specification rules using the automated checker engine. No extra manual analysis beyond defined rules. Trigger:"Hive SQL优化"、"检查Hive SQL"、"Hive SQL检查"、"Hive SQL规范"、"Hive SQL语法"、"Hive SQL review"

作者 huaweiclouddev-dev

Huawei Cloud MRS Spark SQL specification checking skill. Performs comprehensive SQL statement checking for MRS Spark, including syntax validation, specification compliance, and performance risk detection. triggers: "Spark SQL review", "check Spark SQL", "检查Spark SQL", "Spark SQL检查", "Spark SQL规范", "Spark SQL语法".

2 次安装

Comprehensive SQL statement checking for ClickHouse, supporting multiple kernel versions (24.8, 23.3, 22.3) and two check modes: 1. Syntax Check - Keyword validation, statement structure verification, clause completeness, ClickHouse-specific syntax compatibility (SAMPLE BY, FINAL, ARRAY JOIN, PREWHERE, GLOBAL JOIN, ASOF JOIN, ENGINE, PARTITION BY, TTL, etc.) based on kernel source grammar 2. Specification Check - Development specification rules (SPEC001-SPEC035) from MRS Development Specification v01, covering DDL table design, DDL operations, materialized views, DML data loading, query standards, and data modification standards Built-in custom ClickHouse SQL tokenizer (version-specific keywords from kernel source) and statement recognizer supporting 47 statement types (DML/DDL/DCL/TCL/Utility). Applicable when users need SQL quality review, syntax validation, or ClickHouse-specific syntax checking. Trigger: "Clickhouse SQL check"、"CK SQL check"、 "Clickhouse SQL 校验"、 "Clickhouse SQL 检查

2 次安装

Comprehensive SQL statement checking for DWS, supporting two check modes: 1. Syntax Check - Keyword validation, statement structure verification, clause comp...

作者 huaweicloud-skills-team1 次安装

Comprehensive SQL statement checking for Apache Doris (based on Doris 3.1.4 Nereids ANTLR4 grammar), supporting two check modes: 1. Syntax Check - Keyword validation, statement structure verification, clause completeness, Doris-specific syntax compatibility (DISTRIBUTED BY, PARTITION BY, ENGINE, DUPLICATE/AGGREGATE/UNIQUE KEY, INSERT OVERWRITE, LOAD, EXPORT, MTMV, BACKUP/RESTORE etc.) 2. Specification Check - Object design standards, data operation standards, naming conventions based on Apache Doris development best practices. Built-in custom Doris SQL tokenizer (504 keywords from DorisLexer.g4) and recursive descent parser supporting 100+ Doris statement types. Applicable when users need SQL quality review, syntax validation, or specification compliance checking for Apache Doris SQL (versions 2.1.x / 3.0.x / 3.1.x / 4.x). 触发词:"Doris SQL检查"、"Doris SQL规范"、"Doris SQL审计"、"Doris SQL语法"、"检查Doris SQL"、"Doris SQL review"

2 次安装