<feed xmlns='http://www.w3.org/2005/Atom'>
<title>ydb/yql/essentials/sql/v1/result.cpp, branch main</title>
<subtitle>Mirror of YDB github repos</subtitle>
<id>https://code.mastervirt.ru/ydb/atom?h=main</id>
<link rel='self' href='https://code.mastervirt.ru/ydb/atom?h=main'/>
<link rel='alternate' type='text/html' href='https://code.mastervirt.ru/ydb/'/>
<updated>2026-04-02T14:46:24Z</updated>
<entry>
<title>YQL-21108: Introduce YqlSelect TranslationSetting</title>
<updated>2026-04-02T14:46:24Z</updated>
<author>
<name>vitya-smirnov</name>
<email>vitya-smirnov@yandex-team.com</email>
</author>
<published>2026-04-02T12:53:19Z</published>
<link rel='alternate' type='text/html' href='https://code.mastervirt.ru/ydb/commit/?id=47959cd8414607789ce443ed033d11d34129f9c9'/>
<id>urn:sha1:47959cd8414607789ce443ed033d11d34129f9c9</id>
<content type='text'>
commit_hash:c969a8e417caf0cc0aeb913d7843ca717c8b8271
</content>
</entry>
<entry>
<title>YQL-20436: Translate GROUP BY  to YqlSelect</title>
<updated>2025-12-08T15:16:01Z</updated>
<author>
<name>vitya-smirnov</name>
<email>vitya-smirnov@yandex-team.com</email>
</author>
<published>2025-12-08T14:46:39Z</published>
<link rel='alternate' type='text/html' href='https://code.mastervirt.ru/ydb/commit/?id=f17e74500d2eff35de5842c8afb076827cbacf7d'/>
<id>urn:sha1:f17e74500d2eff35de5842c8afb076827cbacf7d</id>
<content type='text'>
This patch adds a support for a basic aggregation on `YqlSelect` and
includes translation, type annotation, expansion changes.

There are `count`, `min`, `max`, `sum`, `avg` and other aggregations
without parameters supported.

`HAVING` support will be added in a future PRs. Support for (2+)-arg
aggregation is postponed, as it is not required for TPCH queries.

### Translator

The `std::expected` was passed though the function call hierarchy to
gracefully do not support some aggregation functions.

The translation unit `select_yql_aggregation` was introduced.
It implements an alternative aggregation translation to
`YqlAggFactory` and `YqlAgg` callables.

It reuses an `extractor` body and `aggregation_traits_factory` from
a legacy code, via dirty hack with a `friend` keyword, as I decided
to make minimal changes on an existing code.

For a query fragment:

```yql
... Sum(body) ...
```

Resulting YQLs AST looks like this:

```yqls
(YqlAggApply
  (YqlAggFactory '"sum")
  '()    # &lt;-- Options
  (Void) # &lt;-- Result type stub
  body')
```

### Type Annotation

I followed a plan described at the https://nda.ya.ru/t/psA5Gaji7PDe9R.

Besides, new `PgXXX` to `YqlXXX` renames, there were introduced
`YqlAggFactoryWrapper` and `YqlAggWrapper`. First just checks
argument count and types, but the second does more sofisticated work.

`YqlAggWrapper` acts in 2 stages. On the first stage it will write
an expression with a `TypeOf` of a `Result` to a result type stub
and then calls for a transformation pipeline repetition.
On the second stage result type stub is typed and so it
just defines its type to be equal to a type of the stub.

The tricky thing here is to contruct this expression with `Result` type.
To do this it needs to instantiate an aggregation traits factory with a
correct `list_type` and an `extractor`. The `list_type` is just a
`(ListType (TypeOf row))`, where `row` is an `Argument` from an enclosing
`lambda` at `YqlResultItem`. An `extractor` is just a `(lambda (row) body')`.
The traits are imported from the `mount/lib/aggregate.yqls`, then they are
beta-reduced with constructed `list_type` and `extractor` expressions. Then
the `state` method is extracted and beta-reduced with a `body`. Then the
`finish` method is extracted and beta-reduced with a some `state`-expression.
So the resulting expression is constructed.

### Expansion

The `YqlAgg` is expanded at `BuildAggregationTraits` from `yql_co_pgselect`,
that is nicely integrated  into `PgSelect` expansion infrastructure. There it
is sufficient just to import an aggregation traits factory and beta-reduce it
with `list_type` and `extractor`, that are provided by the `PgSelect`-related
code.

### Refactoring

Loading an `ExprNode`s from a module, so I extracted a logic to
`ImportReadonly` and `ImportDeeplyCopied` at `yql_module_helpers`.
commit_hash:9303f00567dd423bedc334e7c7514584f5bd8cff
</content>
</entry>
<entry>
<title>YQL-20436: Use std::expected at sql_expression</title>
<updated>2025-11-21T15:50:14Z</updated>
<author>
<name>vitya-smirnov</name>
<email>vitya-smirnov@yandex-team.com</email>
</author>
<published>2025-11-21T15:12:18Z</published>
<link rel='alternate' type='text/html' href='https://code.mastervirt.ru/ydb/commit/?id=aaaa21e476afc02584e70962f47ec8d466cdc704'/>
<id>urn:sha1:aaaa21e476afc02584e70962f47ec8d466cdc704</id>
<content type='text'>
This patch introduces a new `TSQLV1Result` for error-handling in
YQL translator.

A nullable `TNodePtr` with 2 states was sufficient
for error reporting, but `YqlSelect` feature fallback mode requires
one more state `YqlSelectUnsupported`.

`TSQLV1Result` is used at `YqlSelect` sub-translator and
`sql_expression`. The last is needed to support `YqlSelect`-subqueries.

For an error-handling `std::expected` is used with `TNonNull` pointer
decorator to prevent implicit casts and ensure safety.

For a legacy code interoperability `Wrap` and `Unwrap` methods where
added. They convert `nullptr` to `ESQLV1Error::Basic` Unwrap is used
in places, where `TSqlExpression` is called without `YqlSelect`
configuration, so `YqlSelectUnsupported` is impossible.

Also I noticed some strange error ignorance at JSON API translation
and added `FIXME`s.
commit_hash:47c1e05ef02574bfd3af4712bd8bfa652ab7868b
</content>
</entry>
</feed>
