mirror of
https://github.com/GreptimeTeam/greptimedb.git
synced 2026-05-16 21:10:38 +00:00
* change dep Signed-off-by: Ruihang Xia <waynestxia@gmail.com> * feat: adapt to arrow's interval array * chore: fix compile errors in datatypes crate * chore: fix api crate compiler errors * chore: fix compiler errors in common-grpc * chore: fix common-datasource errors * chore: fix deprecated code in common-datasource * fix promql and physical plan related Signed-off-by: Ruihang Xia <waynestxia@gmail.com> * wip: upgrading network deps Signed-off-by: Ruihang Xia <waynestxia@gmail.com> * block on updating `sqlparser` * upgrade sqlparser Signed-off-by: Ruihang Xia <waynestxia@gmail.com> * adapt new df's trait requirements Signed-off-by: Ruihang Xia <waynestxia@gmail.com> * chore: fix compiler errors in mito2 * chore: fix common-function crate errors * chore: fix catalog errors * change import path Signed-off-by: Ruihang Xia <waynestxia@gmail.com> * chore: fix some errors in query crate * chore: fix some errors in query crate * aggr expr and some other tiny fixes Signed-off-by: Ruihang Xia <waynestxia@gmail.com> * chore: fix expr related errors in query crate * chore: fix query serializer and admin command * chore: fix grpc services * feat: axum serve * chore: fix http server * remove handle_error handler * refactor timeout layer * serve axum * chore: fix flow aggr functions * chore: fix flow * feat: fix errors in meta-srv * boxed() * use TokioIo * feat!: Remove script crate and python feature (#5321) * feat: exclude script crate * chore: simplify feature * feat: remove the script crate * chore: remove python feature and some comments * chore: fix warning * chore: fix servers tests compiler errors * feat: fix tests-integration errors * chore: fix unused * test: fix catalog test * chore: fix compiler errors for crates using common-meta testing feature is enabled when check with --workspace * test: use display for logical plan test * test: implement rewrite for ScanHintRule * fix: http server build panic * test: fix mito test * fix: sql parser type alias error * test: fix TestClient not listen * test: some flow tests * test(flow): more fix * fix: test_otlp_logs * test: fix promql test that using deprecated method fun() * fix: sql type replace supports Int8 ~ Int64, UInt8 ~ UInt64 * test: fix infer schema test case * test: fix tests related to plan display * chore: fix last flow test * test: fix function format related assertion * test: use larger port range for tests * fix: test_otlp_traces * fix: test_otlp_metrics * fix range query and dist plan Signed-off-by: Ruihang Xia <waynestxia@gmail.com> * fix: flow handle distinct use deprecated field * fix: can't pass Join plan expressions to LogicalPlan::with_new_exprs * test: fix deserialize test * test: reduce split key case num * tests: lower case aggr func name * test: fix some sqlness tests * tests: more sqlness fix * tests: fixed sqlness test * commit non-bug changes Signed-off-by: Ruihang Xia <waynestxia@gmail.com> * fix: make our udf correct * fix: implement empty methods of ContextProvider for DfContextProviderAdapter * test: update sqlness test result * chore: remove unused * fix: provide alias name for AggregateExprBuilder in range plan * test: update range query result * fix: implement missing ContextProvider methods for DfContextProviderAdapter * test: update timestamps, cte result * fix: supports empty projection in mito * test: update comment for cte test * fix: support projection for numbers * test: update test cases after projection fix * fix: fix range select first_value/last_value * fix: handle CAST and time index conflict * fix: handle order by correctly in range first_value/last_value * test: update sqlness result * test: update view test result * test: update decimal test wait for https://github.com/apache/datafusion/pull/14126 to fix this * feat: remove redundant physical optimization todo(ruihang): Check if we can remove this. * test: update sqlness test result * chore: range select default sort use nulls_first = false * test: update filter push down test result * test: comment deciaml test to avoid different panic message * test: update some distributed test result * test: update test for distributed count and filter push down * test: update subqueries test * fix: SessionState may overwrite our UDFs * chore: fix compiler errors after merging main * fix: fix elasticsearch and dashboard router panic * chore: fix common-functions tests * chore: update sqlness result * test: fix id keyword and update sqlness result * test: fix flow_null test * fix: enlarge thread size in debug mode to avoid overflow * chore: fix warnings in common-function * chore: fix warning in flow * chore: fix warnings in query crate * chore: remove unused warnings * chore: fix deprecated warnings for parquet * chore: fix deprecated warning in servers crate * style: fix clippy * test: enlarge mito cache tttl test ttl time * chore: fix typo * style: fmt toml * refactor: reimplement PartialOrd for RangeSelect * chore: remove script crate files introduced by merge * fix: return error if sql option is not kv * chore: do not use ..default::default() * chore: per review * chore: update error message in BuildAdminFunctionArgsSnafu Co-authored-by: jeremyhi <jiachun_feng@proton.me> * refactor: typed precision * update sqlness view case Signed-off-by: Ruihang Xia <waynestxia@gmail.com> * chore: flow per review * chore: add example in comment * chore: warn if parquet stats of timestamp is not INT64 * style: add a newline before derive to make the comment more clear * test: update sqlness result * fix: flow from substrait * chore: change update_range_context log to debug level * chore: move axum-extra axum-macros to workspace --------- Signed-off-by: Ruihang Xia <waynestxia@gmail.com> Co-authored-by: Ruihang Xia <waynestxia@gmail.com> Co-authored-by: luofucong <luofc@foxmail.com> Co-authored-by: discord9 <discord9@163.com> Co-authored-by: shuiyisong <xixing.sys@gmail.com> Co-authored-by: jeremyhi <jiachun_feng@proton.me>
271 lines
22 KiB
Plaintext
271 lines
22 KiB
Plaintext
CREATE TABLE host (
|
|
ts timestamp(3) time index,
|
|
host STRING PRIMARY KEY,
|
|
val BIGINT,
|
|
addon BIGINT,
|
|
);
|
|
|
|
Affected Rows: 0
|
|
|
|
INSERT INTO TABLE host VALUES
|
|
(0, 'host1', 0, 1),
|
|
(1000, 'host1', 1, 2),
|
|
(2000, 'host1', 2, 3),
|
|
(5000, 'host1', null, 4),
|
|
(6000, 'host1', null, 5),
|
|
(7000, 'host1', null, 6),
|
|
(10000, 'host1', null, 7),
|
|
(11000, 'host1', 4, 8),
|
|
(12000, 'host1', 5, 9),
|
|
(15000, 'host1', 6, 10),
|
|
(16000, 'host1', null, 11),
|
|
(17000, 'host1', 7, 12),
|
|
(20000, 'host1', 8, 13),
|
|
(21000, 'host1', 9, 14),
|
|
(22000, 'host1', null, 15),
|
|
(0, 'host2', 0, 16),
|
|
(1000, 'host2', 1, 17),
|
|
(2000, 'host2', 2, 18),
|
|
(5000, 'host2', null, 19),
|
|
(6000, 'host2', null, 20),
|
|
(7000, 'host2', null, 21),
|
|
(10000, 'host2', null, 22),
|
|
(11000, 'host2', 4, 23),
|
|
(12000, 'host2', 5, 24),
|
|
(15000, 'host2', 6, 25),
|
|
(16000, 'host2', null, 26),
|
|
(17000, 'host2', 7, 27),
|
|
(20000, 'host2', 8, 28),
|
|
(21000, 'host2', 9, 29),
|
|
(22000, 'host2', null, 30);
|
|
|
|
Affected Rows: 30
|
|
|
|
SELECT ts, host, first_value(val) RANGE '5s', last_value(val) RANGE '5s' FROM host ALIGN '5s' ORDER BY host, ts;
|
|
|
|
+---------------------+-------+--------------------------------+-------------------------------+
|
|
| ts | host | first_value(host.val) RANGE 5s | last_value(host.val) RANGE 5s |
|
|
+---------------------+-------+--------------------------------+-------------------------------+
|
|
| 1970-01-01T00:00:00 | host1 | 0 | 2 |
|
|
| 1970-01-01T00:00:05 | host1 | | |
|
|
| 1970-01-01T00:00:10 | host1 | | 5 |
|
|
| 1970-01-01T00:00:15 | host1 | 6 | 7 |
|
|
| 1970-01-01T00:00:20 | host1 | 8 | |
|
|
| 1970-01-01T00:00:00 | host2 | 0 | 2 |
|
|
| 1970-01-01T00:00:05 | host2 | | |
|
|
| 1970-01-01T00:00:10 | host2 | | 5 |
|
|
| 1970-01-01T00:00:15 | host2 | 6 | 7 |
|
|
| 1970-01-01T00:00:20 | host2 | 8 | |
|
|
+---------------------+-------+--------------------------------+-------------------------------+
|
|
|
|
SELECT ts, host, first_value(addon ORDER BY val DESC) RANGE '5s', last_value(addon ORDER BY val DESC) RANGE '5s' FROM host ALIGN '5s' ORDER BY host, ts;
|
|
|
|
+---------------------+-------+-----------------------------------------------------------------------+----------------------------------------------------------------------+
|
|
| ts | host | first_value(host.addon) ORDER BY [host.val DESC NULLS FIRST] RANGE 5s | last_value(host.addon) ORDER BY [host.val DESC NULLS FIRST] RANGE 5s |
|
|
+---------------------+-------+-----------------------------------------------------------------------+----------------------------------------------------------------------+
|
|
| 1970-01-01T00:00:00 | host1 | 3 | 1 |
|
|
| 1970-01-01T00:00:05 | host1 | 4 | 4 |
|
|
| 1970-01-01T00:00:10 | host1 | 7 | 8 |
|
|
| 1970-01-01T00:00:15 | host1 | 11 | 10 |
|
|
| 1970-01-01T00:00:20 | host1 | 15 | 13 |
|
|
| 1970-01-01T00:00:00 | host2 | 18 | 16 |
|
|
| 1970-01-01T00:00:05 | host2 | 19 | 19 |
|
|
| 1970-01-01T00:00:10 | host2 | 22 | 23 |
|
|
| 1970-01-01T00:00:15 | host2 | 26 | 25 |
|
|
| 1970-01-01T00:00:20 | host2 | 30 | 28 |
|
|
+---------------------+-------+-----------------------------------------------------------------------+----------------------------------------------------------------------+
|
|
|
|
SELECT ts, host, first_value(addon ORDER BY val DESC NULLS LAST) RANGE '5s', last_value(addon ORDER BY val DESC NULLS LAST) RANGE '5s' FROM host ALIGN '5s' ORDER BY host, ts;
|
|
|
|
+---------------------+-------+----------------------------------------------------------------------+---------------------------------------------------------------------+
|
|
| ts | host | first_value(host.addon) ORDER BY [host.val DESC NULLS LAST] RANGE 5s | last_value(host.addon) ORDER BY [host.val DESC NULLS LAST] RANGE 5s |
|
|
+---------------------+-------+----------------------------------------------------------------------+---------------------------------------------------------------------+
|
|
| 1970-01-01T00:00:00 | host1 | 3 | 1 |
|
|
| 1970-01-01T00:00:05 | host1 | 4 | 4 |
|
|
| 1970-01-01T00:00:10 | host1 | 9 | 7 |
|
|
| 1970-01-01T00:00:15 | host1 | 12 | 11 |
|
|
| 1970-01-01T00:00:20 | host1 | 14 | 15 |
|
|
| 1970-01-01T00:00:00 | host2 | 18 | 16 |
|
|
| 1970-01-01T00:00:05 | host2 | 19 | 19 |
|
|
| 1970-01-01T00:00:10 | host2 | 24 | 22 |
|
|
| 1970-01-01T00:00:15 | host2 | 27 | 26 |
|
|
| 1970-01-01T00:00:20 | host2 | 29 | 30 |
|
|
+---------------------+-------+----------------------------------------------------------------------+---------------------------------------------------------------------+
|
|
|
|
SELECT ts, host, first_value(addon ORDER BY val ASC) RANGE '5s', last_value(addon ORDER BY val ASC) RANGE '5s' FROM host ALIGN '5s' ORDER BY host, ts;
|
|
|
|
+---------------------+-------+---------------------------------------------------------------------+--------------------------------------------------------------------+
|
|
| ts | host | first_value(host.addon) ORDER BY [host.val ASC NULLS LAST] RANGE 5s | last_value(host.addon) ORDER BY [host.val ASC NULLS LAST] RANGE 5s |
|
|
+---------------------+-------+---------------------------------------------------------------------+--------------------------------------------------------------------+
|
|
| 1970-01-01T00:00:00 | host1 | 1 | 3 |
|
|
| 1970-01-01T00:00:05 | host1 | 4 | 4 |
|
|
| 1970-01-01T00:00:10 | host1 | 8 | 7 |
|
|
| 1970-01-01T00:00:15 | host1 | 10 | 11 |
|
|
| 1970-01-01T00:00:20 | host1 | 13 | 15 |
|
|
| 1970-01-01T00:00:00 | host2 | 16 | 18 |
|
|
| 1970-01-01T00:00:05 | host2 | 19 | 19 |
|
|
| 1970-01-01T00:00:10 | host2 | 23 | 22 |
|
|
| 1970-01-01T00:00:15 | host2 | 25 | 26 |
|
|
| 1970-01-01T00:00:20 | host2 | 28 | 30 |
|
|
+---------------------+-------+---------------------------------------------------------------------+--------------------------------------------------------------------+
|
|
|
|
SELECT ts, host, first_value(addon ORDER BY val ASC NULLS FIRST) RANGE '5s', last_value(addon ORDER BY val ASC NULLS FIRST) RANGE '5s' FROM host ALIGN '5s' ORDER BY host, ts;
|
|
|
|
+---------------------+-------+----------------------------------------------------------------------+---------------------------------------------------------------------+
|
|
| ts | host | first_value(host.addon) ORDER BY [host.val ASC NULLS FIRST] RANGE 5s | last_value(host.addon) ORDER BY [host.val ASC NULLS FIRST] RANGE 5s |
|
|
+---------------------+-------+----------------------------------------------------------------------+---------------------------------------------------------------------+
|
|
| 1970-01-01T00:00:00 | host1 | 1 | 3 |
|
|
| 1970-01-01T00:00:05 | host1 | 4 | 4 |
|
|
| 1970-01-01T00:00:10 | host1 | 7 | 9 |
|
|
| 1970-01-01T00:00:15 | host1 | 11 | 12 |
|
|
| 1970-01-01T00:00:20 | host1 | 15 | 14 |
|
|
| 1970-01-01T00:00:00 | host2 | 16 | 18 |
|
|
| 1970-01-01T00:00:05 | host2 | 19 | 19 |
|
|
| 1970-01-01T00:00:10 | host2 | 22 | 24 |
|
|
| 1970-01-01T00:00:15 | host2 | 26 | 27 |
|
|
| 1970-01-01T00:00:20 | host2 | 30 | 29 |
|
|
+---------------------+-------+----------------------------------------------------------------------+---------------------------------------------------------------------+
|
|
|
|
SELECT ts, host, first_value(addon ORDER BY val ASC, ts ASC) RANGE '5s', last_value(addon ORDER BY val ASC, ts ASC) RANGE '5s' FROM host ALIGN '5s' ORDER BY host, ts;
|
|
|
|
+---------------------+-------+---------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------+
|
|
| ts | host | first_value(host.addon) ORDER BY [host.val ASC NULLS LAST, host.ts ASC NULLS LAST] RANGE 5s | last_value(host.addon) ORDER BY [host.val ASC NULLS LAST, host.ts ASC NULLS LAST] RANGE 5s |
|
|
+---------------------+-------+---------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------+
|
|
| 1970-01-01T00:00:00 | host1 | 1 | 3 |
|
|
| 1970-01-01T00:00:05 | host1 | 4 | 6 |
|
|
| 1970-01-01T00:00:10 | host1 | 8 | 7 |
|
|
| 1970-01-01T00:00:15 | host1 | 10 | 11 |
|
|
| 1970-01-01T00:00:20 | host1 | 13 | 15 |
|
|
| 1970-01-01T00:00:00 | host2 | 16 | 18 |
|
|
| 1970-01-01T00:00:05 | host2 | 19 | 21 |
|
|
| 1970-01-01T00:00:10 | host2 | 23 | 22 |
|
|
| 1970-01-01T00:00:15 | host2 | 25 | 26 |
|
|
| 1970-01-01T00:00:20 | host2 | 28 | 30 |
|
|
+---------------------+-------+---------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------+
|
|
|
|
SELECT ts, host, count(val) RANGE '5s' FROM host ALIGN '5s' ORDER BY host, ts;
|
|
|
|
+---------------------+-------+--------------------------+
|
|
| ts | host | count(host.val) RANGE 5s |
|
|
+---------------------+-------+--------------------------+
|
|
| 1970-01-01T00:00:00 | host1 | 3 |
|
|
| 1970-01-01T00:00:05 | host1 | 0 |
|
|
| 1970-01-01T00:00:10 | host1 | 2 |
|
|
| 1970-01-01T00:00:15 | host1 | 2 |
|
|
| 1970-01-01T00:00:20 | host1 | 2 |
|
|
| 1970-01-01T00:00:00 | host2 | 3 |
|
|
| 1970-01-01T00:00:05 | host2 | 0 |
|
|
| 1970-01-01T00:00:10 | host2 | 2 |
|
|
| 1970-01-01T00:00:15 | host2 | 2 |
|
|
| 1970-01-01T00:00:20 | host2 | 2 |
|
|
+---------------------+-------+--------------------------+
|
|
|
|
SELECT ts, host, count(distinct val) RANGE '5s' FROM host ALIGN '5s' ORDER BY host, ts;
|
|
|
|
+---------------------+-------+-----------------------------------+
|
|
| ts | host | count(DISTINCT host.val) RANGE 5s |
|
|
+---------------------+-------+-----------------------------------+
|
|
| 1970-01-01T00:00:00 | host1 | 3 |
|
|
| 1970-01-01T00:00:05 | host1 | 0 |
|
|
| 1970-01-01T00:00:10 | host1 | 2 |
|
|
| 1970-01-01T00:00:15 | host1 | 2 |
|
|
| 1970-01-01T00:00:20 | host1 | 2 |
|
|
| 1970-01-01T00:00:00 | host2 | 3 |
|
|
| 1970-01-01T00:00:05 | host2 | 0 |
|
|
| 1970-01-01T00:00:10 | host2 | 2 |
|
|
| 1970-01-01T00:00:15 | host2 | 2 |
|
|
| 1970-01-01T00:00:20 | host2 | 2 |
|
|
+---------------------+-------+-----------------------------------+
|
|
|
|
SELECT ts, host, count(*) RANGE '5s' FROM host ALIGN '5s' ORDER BY host, ts;
|
|
|
|
+---------------------+-------+-------------------+
|
|
| ts | host | count(*) RANGE 5s |
|
|
+---------------------+-------+-------------------+
|
|
| 1970-01-01T00:00:00 | host1 | 3 |
|
|
| 1970-01-01T00:00:05 | host1 | 3 |
|
|
| 1970-01-01T00:00:10 | host1 | 3 |
|
|
| 1970-01-01T00:00:15 | host1 | 3 |
|
|
| 1970-01-01T00:00:20 | host1 | 3 |
|
|
| 1970-01-01T00:00:00 | host2 | 3 |
|
|
| 1970-01-01T00:00:05 | host2 | 3 |
|
|
| 1970-01-01T00:00:10 | host2 | 3 |
|
|
| 1970-01-01T00:00:15 | host2 | 3 |
|
|
| 1970-01-01T00:00:20 | host2 | 3 |
|
|
+---------------------+-------+-------------------+
|
|
|
|
SELECT ts, host, count(1) RANGE '5s' as abc FROM host ALIGN '5s' ORDER BY host, ts;
|
|
|
|
+---------------------+-------+-----+
|
|
| ts | host | abc |
|
|
+---------------------+-------+-----+
|
|
| 1970-01-01T00:00:00 | host1 | 3 |
|
|
| 1970-01-01T00:00:05 | host1 | 3 |
|
|
| 1970-01-01T00:00:10 | host1 | 3 |
|
|
| 1970-01-01T00:00:15 | host1 | 3 |
|
|
| 1970-01-01T00:00:20 | host1 | 3 |
|
|
| 1970-01-01T00:00:00 | host2 | 3 |
|
|
| 1970-01-01T00:00:05 | host2 | 3 |
|
|
| 1970-01-01T00:00:10 | host2 | 3 |
|
|
| 1970-01-01T00:00:15 | host2 | 3 |
|
|
| 1970-01-01T00:00:20 | host2 | 3 |
|
|
+---------------------+-------+-----+
|
|
|
|
SELECT ts, host, count(distinct *) RANGE '5s' FROM host ALIGN '5s' ORDER BY host, ts;
|
|
|
|
+---------------------+-------+----------------------------+
|
|
| ts | host | count(DISTINCT *) RANGE 5s |
|
|
+---------------------+-------+----------------------------+
|
|
| 1970-01-01T00:00:00 | host1 | 3 |
|
|
| 1970-01-01T00:00:05 | host1 | 3 |
|
|
| 1970-01-01T00:00:10 | host1 | 3 |
|
|
| 1970-01-01T00:00:15 | host1 | 3 |
|
|
| 1970-01-01T00:00:20 | host1 | 3 |
|
|
| 1970-01-01T00:00:00 | host2 | 3 |
|
|
| 1970-01-01T00:00:05 | host2 | 3 |
|
|
| 1970-01-01T00:00:10 | host2 | 3 |
|
|
| 1970-01-01T00:00:15 | host2 | 3 |
|
|
| 1970-01-01T00:00:20 | host2 | 3 |
|
|
+---------------------+-------+----------------------------+
|
|
|
|
-- Test error first_value/last_value
|
|
SELECT ts, host, first_value(val, val) RANGE '5s' FROM host ALIGN '5s' ORDER BY host, ts;
|
|
|
|
Error: 3000(PlanQuery), Failed to plan SQL: Error during planning: Error during planning: The function expected 1 arguments but received 2 No function matches the given name and argument types 'first_value(Int64, Int64)'. You might need to add explicit type casts.
|
|
Candidate functions:
|
|
first_value(Any)
|
|
|
|
DROP TABLE host;
|
|
|
|
Affected Rows: 0
|
|
|
|
-- Test first_value/last_value will execute sort
|
|
CREATE TABLE host (
|
|
ts timestamp(3) time index,
|
|
host STRING PRIMARY KEY,
|
|
val BIGINT,
|
|
addon BIGINT,
|
|
);
|
|
|
|
Affected Rows: 0
|
|
|
|
INSERT INTO TABLE host VALUES
|
|
(0, 'host1', 0, 3),
|
|
(1000, 'host1', 1, 2),
|
|
(2000, 'host1', 2, 1);
|
|
|
|
Affected Rows: 3
|
|
|
|
SELECT ts, first_value(val ORDER BY addon ASC) RANGE '5s', last_value(val ORDER BY addon ASC) RANGE '5s' FROM host ALIGN '5s';
|
|
|
|
+---------------------+---------------------------------------------------------------------+--------------------------------------------------------------------+
|
|
| ts | first_value(host.val) ORDER BY [host.addon ASC NULLS LAST] RANGE 5s | last_value(host.val) ORDER BY [host.addon ASC NULLS LAST] RANGE 5s |
|
|
+---------------------+---------------------------------------------------------------------+--------------------------------------------------------------------+
|
|
| 1970-01-01T00:00:00 | 2 | 0 |
|
|
+---------------------+---------------------------------------------------------------------+--------------------------------------------------------------------+
|
|
|
|
DROP TABLE host;
|
|
|
|
Affected Rows: 0
|
|
|