Skip to content

query.ebnf(select): sync with query.pest

Artur Sabirov requested to merge asabirov/fix_select_diagram into main

Summarize the changes

  • query.ebnf: add scan diagram
  • query.ebnf(select): sync with query.pest
  • query.ebnf(update): sync with query.pest
  • query.ebnf: replace with "query" where needed

В продолжение обсуждения в docs#244 (closed)

Должен быть влит после !492 (merged)

Предлагаемые изменения

  1. Добавить диаграмму scan
  2. Изменить определение диаграммы select
  3. Изменить определение диаграммы update
  4. Переименовать диаграмму cte -> query и заменить select на query в диаграммах — согласно определениям из query.pest
Диаграмма `query.svg`

query.svg

Диаграмма `select.svg`

select.svg

Диаграмма `scan.svg`

scan.svg

Диаграмма `update.svg`

update.svg

Описание

В query.pest есть три выражения SELECT:

  1. SelectFull:

    SelectFull = {
        (^"with" ~ Cte ~ ("," ~ Cte)*)?
        ~ SelectWithOptionalContinuation
    }
    Подвыражения

    Cte, CteColumn:

    Cte = { Identifier ~ ("(" ~ CteColumn ~ ("," ~ CteColumn)* ~ ")")? ~ ^"as"
            ~ "(" ~ (SelectWithOptionalContinuation | Values) ~ ")" }
    CteColumn = @{ Identifier }
  2. SelectWithOptionalContinuation – сокращу до SelectWOC:

    SelectWithOptionalContinuation = { Select ~ (SelectOp ~ Select)* }
    SelectOp = _{ UnionAllOp | ExceptOp | UnionOp }
        UnionOp = { ^"union" }
        ExceptOp = { (^"except" ~ ^"distinct") | ^"except" }
        UnionAllOp = { ^"union" ~ ^"all" }
  3. Select:

    Select = {
        ^"select" ~ Projection ~ ^"from" ~ Scan ~
        Join* ~ WhereClause? ~
        (^"group" ~ ^"by" ~ GroupBy)? ~
        (^"having" ~ Having)? ~
        (^"order" ~ ^"by" ~ OrderBy)?
    }
    Подвыражения

    Projection, WhereClause, Scan, Join, GroupBy, Having, OrderBy:

    Projection = { Distinct? ~ ProjectionElement ~ ("," ~ ProjectionElement)* }
        ProjectionElement = _{ Asterisk | Column }
        Column = { Expr ~ ((^"as")? ~ Identifier)? }
        Asterisk = { (Identifier ~ ".")? ~ "*" }
    WhereClause = _{ ^"where" ~ Selection }
    Selection = { Expr }
    Scan = { (ScanCteOrTable| SubQuery) ~ ((^"as")? ~ Identifier)? }
    Join = { JoinKind? ~ ^"join" ~ Scan ~ ^"on" ~ Expr }
        JoinKind = _{ ( InnerJoinKind | LeftJoinKind ) }
            InnerJoinKind = { ^"inner" }
            LeftJoinKind = { ^"left" ~ (^"outer")? }
    GroupBy = { Expr ~ ("," ~ Expr)* }
    Having = { Expr }
    OrderBy = { OrderByElement ~ ("," ~ OrderByElement)* }
        OrderByElement = { Expr ~ OrderFlag? }
        OrderFlag = _{ Asc | Desc }
            Asc = { ^"asc" }
            Desc = { ^"desc" }
    SubQuery = { "(" ~ (SelectFull | Values) ~ ")" }

Использование

  1. Select:

  2. SelectWOC:

  3. SelectFull — все остальные диаграммы

Ensure that

  • New code is covered by unit and integration tests.
  • Related issues would be automatically closed with gitlab's closing pattern (Closes #1, #2).
  • Public modules are documented (check the rendered version with cargo doc --open).
  • (if PEST grammar is changed) EBNF grammar reflects these changes (check the result with railroad diagram generator.

Next steps

Edited by Artur Sabirov

Merge request reports