Skip to content

feat(sql): breaking change 💥 - use expression as column aliases#5802

Merged
bluestreak01 merged 29 commits intomasterfrom
raph_expression_alias
Jul 4, 2025
Merged

feat(sql): breaking change 💥 - use expression as column aliases#5802
bluestreak01 merged 29 commits intomasterfrom
raph_expression_alias

Conversation

@RaphDal
Copy link
Copy Markdown
Contributor

@RaphDal RaphDal commented Jul 2, 2025

This PR changes the way column aliases are generated when they aren't provided by the user.

Instead of using the function/column name or fall-backing on "column", we are now using a stable version of the user-provided expression.

Additionally, this PR adds a new configuration settings (cairo.sql.column.alias.generated.max.size) to restrict the maximum size of generated aliases.

Feature flag

To disable this feature, you need to set the cairo.sql.column.alias.expression.enabled to false.

Example

Here is a simple query with many functions:

SELECT 1+1, symbol, count(), avg(price), sum(amount), floor(avg(price*amount))
FROM trades
WHERE symbol LIKE '%-USDC'
GROUP BY symbol
ORDER BY symbol;

And here is the result when executed against:

  • the main branch:
┌────────┬───────────┬──────────┬────────────────────┬────────────────────┬────────┐
| column | symbol    | count    | avg                | sum                | floor  |
├────────┼───────────┼──────────┼────────────────────┼────────────────────┼────────┤
| 2      | ADA-USDC  | 1870557  | 0.8343108829616019 | 590365817.8445977  | 246.0  |
| 2      | BTC-USDC  | 19332538 | 88675.13834078645  | 329416.58393461775 | 1487.0 |
| 2      | ETH-USDC  | 20333012 | 2649.7562137641034 | 6977408.255760606  | 897.0  |
| 2      | USDT-USDC | 4760916  | 1.0000365604643942 | 6996907779.650375  | 1469.0 |
└────────┴───────────┴──────────┴────────────────────┴────────────────────┴────────┘
  • this PR:
┌───────┬───────────┬──────────┬────────────────────┬────────────────────┬─────────────────────────────┐
| 1 + 1 | symbol    | count()  | avg(price)         | sum(amount)        | floor(avg(price * amount))  |
├───────┼───────────┼──────────┼────────────────────┼────────────────────┼─────────────────────────────┤
| 2     | ADA-USDC  | 1870557  | 0.8343108829616019 | 590365817.8445977  | 246.0                       |
| 2     | BTC-USDC  | 19332538 | 88675.13834078645  | 329416.58393461775 | 1487.0                      |
| 2     | ETH-USDC  | 20333012 | 2649.7562137641034 | 6977408.255760606  | 897.0                       |
| 2     | USDT-USDC | 4760916  | 1.0000365604643942 | 6996907779.650375  | 1469.0                      |
└───────┴───────────┴──────────┴────────────────────┴────────────────────┴─────────────────────────────┘

@RaphDal RaphDal changed the title feat(sql): use expression as column aliases feat(sql): breaking change 💥 - use expression as column aliases Jul 2, 2025
@RaphDal RaphDal changed the title feat(sql): breaking change 💥 - use expression as column aliases feat(sql): use expression as column aliases Jul 2, 2025
@bluestreak01
Copy link
Copy Markdown
Member

i get this :
image

@RaphDal
Copy link
Copy Markdown
Contributor Author

RaphDal commented Jul 3, 2025

i get this : image

Have you set cairo.sql.column.alias.expression.enabled=true in your server.conf?

@RaphDal RaphDal changed the title feat(sql): use expression as column aliases feat(sql): breaking change 💥 - use expression as column aliases Jul 4, 2025
@glasstiger
Copy link
Copy Markdown
Contributor

[PR Coverage check]

😍 pass : 124 / 133 (93.23%)

file detail

path covered line new line coverage
🔵 io/questdb/PropServerConfiguration.java 5 14 35.71%
🔵 io/questdb/std/Chars.java 8 8 100.00%
🔵 io/questdb/griffin/SqlParser.java 25 25 100.00%
🔵 io/questdb/cairo/DefaultCairoConfiguration.java 2 2 100.00%
🔵 io/questdb/griffin/model/QueryModel.java 1 1 100.00%
🔵 io/questdb/griffin/model/ExpressionNode.java 45 45 100.00%
🔵 io/questdb/PropertyKey.java 3 3 100.00%
🔵 io/questdb/griffin/OperatorExpression.java 1 1 100.00%
🔵 io/questdb/cairo/CairoConfigurationWrapper.java 2 2 100.00%
🔵 io/questdb/griffin/SqlUtil.java 32 32 100.00%

@bluestreak01 bluestreak01 merged commit 1960d4c into master Jul 4, 2025
34 checks passed
@bluestreak01 bluestreak01 deleted the raph_expression_alias branch July 4, 2025 17:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants