Files
greptimedb/tests/cases/standalone/common/tql/join.result
dennis zhuang 57d84b9de5 feat: supports value aliasing in TQL (#7041)
* feat: supports value aliasing in TQL

Signed-off-by: Dennis Zhuang <killme2008@gmail.com>

* fix: invalid checking

Signed-off-by: Dennis Zhuang <killme2008@gmail.com>

* chore: remove invalid checking

Signed-off-by: Dennis Zhuang <killme2008@gmail.com>

* test: add explain test

Signed-off-by: Dennis Zhuang <killme2008@gmail.com>

* chore: improve parser

Signed-off-by: Dennis Zhuang <killme2008@gmail.com>

* test: add explain TQL-CTE

Signed-off-by: Dennis Zhuang <killme2008@gmail.com>

---------

Signed-off-by: Dennis Zhuang <killme2008@gmail.com>
2025-10-11 02:49:09 +00:00

109 lines
5.9 KiB
Plaintext

create table completion(
ts timestamp time index,
model string primary key,
val double
);
Affected Rows: 0
insert into completion values
(0, 'model-a', 10),
(5000, 'model-b', 20),
(10000, 'model-a', 30);
Affected Rows: 3
create table prompt(
ts timestamp time index,
model string primary key,
val double
);
Affected Rows: 0
insert into prompt values
(0, 'model-a', 100),
(5000, 'model-b', 200),
(10000, 'model-a', 300);
Affected Rows: 3
-- SQLNESS SORT_RESULT 3 1
tql eval(0, 10, '5s') sum(completion * 0.0015 / 1000) + sum(prompt / 1000 * 0.0015);
+---------------------+-----------------------------------------------------------------------------------------------------------+
| ts | completion.sum(val * Float64(0.0015) / Float64(1000)) + prompt.sum(val / Float64(1000) * Float64(0.0015)) |
+---------------------+-----------------------------------------------------------------------------------------------------------+
| 1970-01-01T00:00:00 | 0.000165 |
| 1970-01-01T00:00:05 | 0.000495 |
| 1970-01-01T00:00:10 | 0.000825 |
+---------------------+-----------------------------------------------------------------------------------------------------------+
-- SQLNESS SORT_RESULT 3 1
tql eval(0, 10, '5s') sum(completion * 0.0015 / 1000) + sum(prompt * 0.0015 / 1000);
+---------------------+-----------------------------------------------------------------------------------------------------------+
| ts | completion.sum(val * Float64(0.0015) / Float64(1000)) + prompt.sum(val * Float64(0.0015) / Float64(1000)) |
+---------------------+-----------------------------------------------------------------------------------------------------------+
| 1970-01-01T00:00:00 | 0.000165 |
| 1970-01-01T00:00:05 | 0.000495 |
| 1970-01-01T00:00:10 | 0.000825 |
+---------------------+-----------------------------------------------------------------------------------------------------------+
-- SQLNESS SORT_RESULT 3 1
tql eval(0, 10, '5s') sum(completion * 0.0015 / 1000) by (model) + sum(prompt * 0.0015 / 1000) by (model);
+---------+---------------------+-----------------------------------------------------------------------------------------------------------+
| model | ts | completion.sum(val * Float64(0.0015) / Float64(1000)) + prompt.sum(val * Float64(0.0015) / Float64(1000)) |
+---------+---------------------+-----------------------------------------------------------------------------------------------------------+
| model-a | 1970-01-01T00:00:00 | 0.000165 |
| model-a | 1970-01-01T00:00:05 | 0.000165 |
| model-a | 1970-01-01T00:00:10 | 0.000495 |
| model-b | 1970-01-01T00:00:05 | 0.00033 |
| model-b | 1970-01-01T00:00:10 | 0.00033 |
+---------+---------------------+-----------------------------------------------------------------------------------------------------------+
-- SQLNESS SORT_RESULT 3 1
tql eval(0, 10, '5s') sum(completion * 0.0015 / 1000) by (model) + sum(prompt * 0.0015 / 1000) by (model) AS result;
+----------+---------+---------------------+
| result | model | ts |
+----------+---------+---------------------+
| 0.000165 | model-a | 1970-01-01T00:00:00 |
| 0.000165 | model-a | 1970-01-01T00:00:05 |
| 0.00033 | model-b | 1970-01-01T00:00:05 |
| 0.00033 | model-b | 1970-01-01T00:00:10 |
| 0.000495 | model-a | 1970-01-01T00:00:10 |
+----------+---------+---------------------+
-- SQLNESS SORT_RESULT 3 1
tql eval(0, 10, '5s') sum(completion / 1000) + max(completion / 1000);
+---------------------+-------------------------------------------------------------+
| ts | lhs.sum(val / Float64(1000)) + rhs.max(val / Float64(1000)) |
+---------------------+-------------------------------------------------------------+
| 1970-01-01T00:00:00 | 0.02 |
| 1970-01-01T00:00:05 | 0.05 |
| 1970-01-01T00:00:10 | 0.08 |
+---------------------+-------------------------------------------------------------+
-- SQLNESS SORT_RESULT 3 1
tql eval(0, 10, '5s') sum(completion / 1000) + sum(completion / 1000);
+---------------------+-------------------------------------------------------------+
| ts | lhs.sum(val / Float64(1000)) + rhs.sum(val / Float64(1000)) |
+---------------------+-------------------------------------------------------------+
| 1970-01-01T00:00:00 | 0.02 |
| 1970-01-01T00:00:05 | 0.06 |
| 1970-01-01T00:00:10 | 0.1 |
+---------------------+-------------------------------------------------------------+
drop table completion;
Affected Rows: 0
drop table prompt;
Affected Rows: 0