Skip to content

Upstreaming improvements #492

@dgeelen-uipath

Description

@dgeelen-uipath

Dear maintainers,

We are looking to use SqlKata in one of our products. Our use case is that we want to be able to write queries that we can run against both our production database (Snowflake) and in our unit tests (SQLite). To this end we will be forking SqlKata and implementing Snowflake support. We do however also want to make other changes, such as improving the support for aggregate functions. The current support is too limited for our use case, where our immediate need is to be able to do multiple aggregates in one query, with the ability to give each aggregate column a name (alias). We intend to upstream as much of the non-snowflake-specific changes as possible. To this end we would like to ask you a few questions.

Current work

We have currently done roughly the following as our first steps:

  • Ensure consistent white space throughout all files, to ease development effort on our side. This introduces an .editorconfig.
  • Implement AS keyword support for aggregates. This makes it so that you can name an aggregate with a custom name, rather than always using 'as '. The existing behaviour is kept as a default, but this could be discussed. Additionally the was existing support for using as (with that spacing and casing) in a column name is preserved, although it is not implemented for aggregates as we believe that providing the alias explicitly is a superior approach.
  • Extend aggregate support to multiple columns. This enables the writing of queries like SELECT MIN(COLUMN), MAX(COLUMN), SUM(COLUMN) FROM TABLE. The existing behaviour for handling multiple COUNT() columns is preserved.

The last two changes should fix e.g. #203. Q: Are PRs for these improvements likely be accepted?

Next steps

Next we are going to implement additional aggregate functions, starting with ANY_VALUE, APPROX_PERCENTILE, and PERCENTAGE. Our intent is to implement these with compiler-specific implementations for Snowflake and/or SQLite, and (where possible) a generic implementation for the rest of the supported engines. Q: What would be the best way to handle cases where a generic implementation would not be possible?

Another type of operation that we would like to be able to support is to generate more free-form expressions, such as for example SUM(A)/COUNT(DISTINCT B). This seems quite difficult to implement at the current time, so Q: we would like to know what (if any) plans there are to improve the extensibility and expressiveness of the library (and its interface) in the future?

Kind regards,
UiPath

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions