mirror of
https://github.com/GreptimeTeam/greptimedb.git
synced 2026-05-28 19:00:39 +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>
369 lines
20 KiB
Plaintext
369 lines
20 KiB
Plaintext
-- Test `time()` and related functions.
|
|
-- Some cases are part of promql/testdata/functions.test, "Test time-related functions" section
|
|
-- And others are from compliance test
|
|
-- time() with itself or scalar
|
|
tql eval (3000, 3000, '1s') time();
|
|
|
|
+---------------------+----------------------+
|
|
| time | time / Float64(1000) |
|
|
+---------------------+----------------------+
|
|
| 1970-01-01T00:50:00 | 3000.0 |
|
|
+---------------------+----------------------+
|
|
|
|
tql eval (0, 0, '1s') time();
|
|
|
|
+---------------------+----------------------+
|
|
| time | time / Float64(1000) |
|
|
+---------------------+----------------------+
|
|
| 1970-01-01T00:00:00 | 0.0 |
|
|
+---------------------+----------------------+
|
|
|
|
tql eval (0.001, 1, '1s') time();
|
|
|
|
+-------------------------+----------------------+
|
|
| time | time / Float64(1000) |
|
|
+-------------------------+----------------------+
|
|
| 1970-01-01T00:00:00.001 | 0.001 |
|
|
+-------------------------+----------------------+
|
|
|
|
tql eval (0, 0, '1s') time() + 1;
|
|
|
|
+---------------------+-------+
|
|
| time | value |
|
|
+---------------------+-------+
|
|
| 1970-01-01T00:00:00 | 1.0 |
|
|
+---------------------+-------+
|
|
|
|
tql eval (0, 0, '1s') 1 + time();
|
|
|
|
+---------------------+-------+
|
|
| time | value |
|
|
+---------------------+-------+
|
|
| 1970-01-01T00:00:00 | 1.0 |
|
|
+---------------------+-------+
|
|
|
|
-- expect error: parse error: comparisons between scalars must use BOOL modifier
|
|
tql eval (0, 0, '1s') time() < 1;
|
|
|
|
Error: 2000(InvalidSyntax), comparisons between scalars must use BOOL modifier
|
|
|
|
tql eval (0, 0, '1s') time() < bool 1;
|
|
|
|
+---------------------+-------+
|
|
| time | value |
|
|
+---------------------+-------+
|
|
| 1970-01-01T00:00:00 | 1.0 |
|
|
+---------------------+-------+
|
|
|
|
tql eval (0, 0, '1s') time() > bool 1;
|
|
|
|
+---------------------+-------+
|
|
| time | value |
|
|
+---------------------+-------+
|
|
| 1970-01-01T00:00:00 | 0.0 |
|
|
+---------------------+-------+
|
|
|
|
tql eval (1000, 1000, '1s') time() + time();
|
|
|
|
+---------------------+--------+
|
|
| time | value |
|
|
+---------------------+--------+
|
|
| 1970-01-01T00:16:40 | 2000.0 |
|
|
+---------------------+--------+
|
|
|
|
-- expect error: parse error: comparisons between scalars must use BOOL modifier
|
|
tql eval (1000, 1000, '1s') time() == time();
|
|
|
|
Error: 2000(InvalidSyntax), comparisons between scalars must use BOOL modifier
|
|
|
|
tql eval (1000, 1000, '1s') time() == bool time();
|
|
|
|
+---------------------+-------+
|
|
| time | value |
|
|
+---------------------+-------+
|
|
| 1970-01-01T00:16:40 | 1.0 |
|
|
+---------------------+-------+
|
|
|
|
tql eval (1000, 1000, '1s') time() != bool time();
|
|
|
|
+---------------------+-------+
|
|
| time | value |
|
|
+---------------------+-------+
|
|
| 1970-01-01T00:16:40 | 0.0 |
|
|
+---------------------+-------+
|
|
|
|
-- time() with table
|
|
create table metrics (ts timestamp time index, val double);
|
|
|
|
Affected Rows: 0
|
|
|
|
insert into metrics values (0, 0), (1000, 1), (2000, 2), (3000, 3);
|
|
|
|
Affected Rows: 4
|
|
|
|
tql eval (1, 2, '1s') time() + metrics;
|
|
|
|
+---------------------+--------------------------+
|
|
| ts | ts / Float64(1000) + val |
|
|
+---------------------+--------------------------+
|
|
| 1970-01-01T00:00:01 | 2.0 |
|
|
| 1970-01-01T00:00:02 | 4.0 |
|
|
+---------------------+--------------------------+
|
|
|
|
tql eval (1, 2, '1s') time() == metrics;
|
|
|
|
+---------------------+-----+
|
|
| ts | val |
|
|
+---------------------+-----+
|
|
| 1970-01-01T00:00:01 | 1.0 |
|
|
| 1970-01-01T00:00:02 | 2.0 |
|
|
+---------------------+-----+
|
|
|
|
tql eval (1, 2, '1s') time() == bool metrics;
|
|
|
|
+---------------------+--------------------------+
|
|
| ts | ts / Float64(1000) = val |
|
|
+---------------------+--------------------------+
|
|
| 1970-01-01T00:00:01 | 1.0 |
|
|
| 1970-01-01T00:00:02 | 1.0 |
|
|
+---------------------+--------------------------+
|
|
|
|
tql eval (1, 2, '1s') metrics + time();
|
|
|
|
+---------------------+--------------------------+
|
|
| ts | val + ts / Float64(1000) |
|
|
+---------------------+--------------------------+
|
|
| 1970-01-01T00:00:01 | 2.0 |
|
|
| 1970-01-01T00:00:02 | 4.0 |
|
|
+---------------------+--------------------------+
|
|
|
|
tql eval (1, 2, '1s') metrics == time();
|
|
|
|
+---------------------+-----+
|
|
| ts | val |
|
|
+---------------------+-----+
|
|
| 1970-01-01T00:00:01 | 1.0 |
|
|
| 1970-01-01T00:00:02 | 2.0 |
|
|
+---------------------+-----+
|
|
|
|
tql eval (1, 2, '1s') metrics == bool time();
|
|
|
|
+---------------------+--------------------------+
|
|
| ts | val = ts / Float64(1000) |
|
|
+---------------------+--------------------------+
|
|
| 1970-01-01T00:00:01 | 1.0 |
|
|
| 1970-01-01T00:00:02 | 1.0 |
|
|
+---------------------+--------------------------+
|
|
|
|
-- other time-related functions
|
|
tql eval (1, 2, '1s') hour();
|
|
|
|
+---------------------+------------------------------+
|
|
| time | date_part(Utf8("hour"),time) |
|
|
+---------------------+------------------------------+
|
|
| 1970-01-01T00:00:01 | 0 |
|
|
| 1970-01-01T00:00:02 | 0 |
|
|
+---------------------+------------------------------+
|
|
|
|
tql eval (1, 2, '1s') hour(metrics);
|
|
|
|
+---------------------+----------------------------+
|
|
| ts | date_part(Utf8("hour"),ts) |
|
|
+---------------------+----------------------------+
|
|
| 1970-01-01T00:00:01 | 0 |
|
|
| 1970-01-01T00:00:02 | 0 |
|
|
+---------------------+----------------------------+
|
|
|
|
-- 2023-12-01T06:43:43Z
|
|
tql eval (1701413023, 1701413023, '1s') hour();
|
|
|
|
+---------------------+------------------------------+
|
|
| time | date_part(Utf8("hour"),time) |
|
|
+---------------------+------------------------------+
|
|
| 2023-12-01T06:43:43 | 6 |
|
|
+---------------------+------------------------------+
|
|
|
|
tql eval (1701413023, 1701413023, '1s') hour(metrics);
|
|
|
|
++
|
|
++
|
|
|
|
tql eval (1701413023, 1701413023, '1s') minute();
|
|
|
|
+---------------------+--------------------------------+
|
|
| time | date_part(Utf8("minute"),time) |
|
|
+---------------------+--------------------------------+
|
|
| 2023-12-01T06:43:43 | 43 |
|
|
+---------------------+--------------------------------+
|
|
|
|
tql eval (1701413023, 1701413023, '1s') month();
|
|
|
|
+---------------------+-------------------------------+
|
|
| time | date_part(Utf8("month"),time) |
|
|
+---------------------+-------------------------------+
|
|
| 2023-12-01T06:43:43 | 12 |
|
|
+---------------------+-------------------------------+
|
|
|
|
tql eval (1701413023, 1701413023, '1s') year();
|
|
|
|
+---------------------+------------------------------+
|
|
| time | date_part(Utf8("year"),time) |
|
|
+---------------------+------------------------------+
|
|
| 2023-12-01T06:43:43 | 2023 |
|
|
+---------------------+------------------------------+
|
|
|
|
tql eval (1701413023, 1701413023, '1s') day_of_month();
|
|
|
|
+---------------------+-----------------------------+
|
|
| time | date_part(Utf8("day"),time) |
|
|
+---------------------+-----------------------------+
|
|
| 2023-12-01T06:43:43 | 1 |
|
|
+---------------------+-----------------------------+
|
|
|
|
tql eval (1701413023, 1701413023, '1s') day_of_week();
|
|
|
|
+---------------------+-----------------------------+
|
|
| time | date_part(Utf8("dow"),time) |
|
|
+---------------------+-----------------------------+
|
|
| 2023-12-01T06:43:43 | 5 |
|
|
+---------------------+-----------------------------+
|
|
|
|
tql eval (1701413023, 1701413023, '1s') day_of_year();
|
|
|
|
+---------------------+-----------------------------+
|
|
| time | date_part(Utf8("doy"),time) |
|
|
+---------------------+-----------------------------+
|
|
| 2023-12-01T06:43:43 | 335 |
|
|
+---------------------+-----------------------------+
|
|
|
|
-- 2024-01-01T06:43:43Z leap year
|
|
tql eval (1704091423, 1704091423, '1s') day_of_year();
|
|
|
|
+---------------------+-----------------------------+
|
|
| time | date_part(Utf8("doy"),time) |
|
|
+---------------------+-----------------------------+
|
|
| 2024-01-01T06:43:43 | 1 |
|
|
+---------------------+-----------------------------+
|
|
|
|
-- 2023-01-01T06:43:43Z
|
|
tql eval (1672555423, 1672555423, '1s') days_in_month();
|
|
|
|
+---------------------+--------------------------------------------------------------------------------------------------------------------------------------------------+
|
|
| time | date_part(Utf8("day"),date_trunc(Utf8("month"),time) + IntervalYearMonth("1") - IntervalDayTime("IntervalDayTime { days: 1, milliseconds: 0 }")) |
|
|
+---------------------+--------------------------------------------------------------------------------------------------------------------------------------------------+
|
|
| 2023-01-01T06:43:43 | 31 |
|
|
+---------------------+--------------------------------------------------------------------------------------------------------------------------------------------------+
|
|
|
|
-- 2023-02-01T06:43:43Z
|
|
tql eval (1675233823, 1675233823, '1s') days_in_month();
|
|
|
|
+---------------------+--------------------------------------------------------------------------------------------------------------------------------------------------+
|
|
| time | date_part(Utf8("day"),date_trunc(Utf8("month"),time) + IntervalYearMonth("1") - IntervalDayTime("IntervalDayTime { days: 1, milliseconds: 0 }")) |
|
|
+---------------------+--------------------------------------------------------------------------------------------------------------------------------------------------+
|
|
| 2023-02-01T06:43:43 | 28 |
|
|
+---------------------+--------------------------------------------------------------------------------------------------------------------------------------------------+
|
|
|
|
-- 2024-02-01T06:43:43Z leap year
|
|
tql eval (1706769823, 1706769823, '1s') days_in_month();
|
|
|
|
+---------------------+--------------------------------------------------------------------------------------------------------------------------------------------------+
|
|
| time | date_part(Utf8("day"),date_trunc(Utf8("month"),time) + IntervalYearMonth("1") - IntervalDayTime("IntervalDayTime { days: 1, milliseconds: 0 }")) |
|
|
+---------------------+--------------------------------------------------------------------------------------------------------------------------------------------------+
|
|
| 2024-02-01T06:43:43 | 29 |
|
|
+---------------------+--------------------------------------------------------------------------------------------------------------------------------------------------+
|
|
|
|
-- 2023-03-01T06:43:43Z
|
|
tql eval (1677653023, 1677653023, '1s') days_in_month();
|
|
|
|
+---------------------+--------------------------------------------------------------------------------------------------------------------------------------------------+
|
|
| time | date_part(Utf8("day"),date_trunc(Utf8("month"),time) + IntervalYearMonth("1") - IntervalDayTime("IntervalDayTime { days: 1, milliseconds: 0 }")) |
|
|
+---------------------+--------------------------------------------------------------------------------------------------------------------------------------------------+
|
|
| 2023-03-01T06:43:43 | 31 |
|
|
+---------------------+--------------------------------------------------------------------------------------------------------------------------------------------------+
|
|
|
|
-- 2023-04-01T06:43:43Z
|
|
tql eval (1680331423, 1680331423, '1s') days_in_month();
|
|
|
|
+---------------------+--------------------------------------------------------------------------------------------------------------------------------------------------+
|
|
| time | date_part(Utf8("day"),date_trunc(Utf8("month"),time) + IntervalYearMonth("1") - IntervalDayTime("IntervalDayTime { days: 1, milliseconds: 0 }")) |
|
|
+---------------------+--------------------------------------------------------------------------------------------------------------------------------------------------+
|
|
| 2023-04-01T06:43:43 | 30 |
|
|
+---------------------+--------------------------------------------------------------------------------------------------------------------------------------------------+
|
|
|
|
-- 2023-05-01T06:43:43Z
|
|
tql eval (1682923423, 1682923423, '1s') days_in_month();
|
|
|
|
+---------------------+--------------------------------------------------------------------------------------------------------------------------------------------------+
|
|
| time | date_part(Utf8("day"),date_trunc(Utf8("month"),time) + IntervalYearMonth("1") - IntervalDayTime("IntervalDayTime { days: 1, milliseconds: 0 }")) |
|
|
+---------------------+--------------------------------------------------------------------------------------------------------------------------------------------------+
|
|
| 2023-05-01T06:43:43 | 31 |
|
|
+---------------------+--------------------------------------------------------------------------------------------------------------------------------------------------+
|
|
|
|
-- 2023-06-01T06:43:43Z
|
|
tql eval (1685601823, 1685601823, '1s') days_in_month();
|
|
|
|
+---------------------+--------------------------------------------------------------------------------------------------------------------------------------------------+
|
|
| time | date_part(Utf8("day"),date_trunc(Utf8("month"),time) + IntervalYearMonth("1") - IntervalDayTime("IntervalDayTime { days: 1, milliseconds: 0 }")) |
|
|
+---------------------+--------------------------------------------------------------------------------------------------------------------------------------------------+
|
|
| 2023-06-01T06:43:43 | 30 |
|
|
+---------------------+--------------------------------------------------------------------------------------------------------------------------------------------------+
|
|
|
|
-- 2023-07-01T06:43:43Z
|
|
tql eval (1688193823, 1688193823, '1s') days_in_month();
|
|
|
|
+---------------------+--------------------------------------------------------------------------------------------------------------------------------------------------+
|
|
| time | date_part(Utf8("day"),date_trunc(Utf8("month"),time) + IntervalYearMonth("1") - IntervalDayTime("IntervalDayTime { days: 1, milliseconds: 0 }")) |
|
|
+---------------------+--------------------------------------------------------------------------------------------------------------------------------------------------+
|
|
| 2023-07-01T06:43:43 | 31 |
|
|
+---------------------+--------------------------------------------------------------------------------------------------------------------------------------------------+
|
|
|
|
-- 2023-08-01T06:43:43Z
|
|
tql eval (1690872223, 1690872223, '1s') days_in_month();
|
|
|
|
+---------------------+--------------------------------------------------------------------------------------------------------------------------------------------------+
|
|
| time | date_part(Utf8("day"),date_trunc(Utf8("month"),time) + IntervalYearMonth("1") - IntervalDayTime("IntervalDayTime { days: 1, milliseconds: 0 }")) |
|
|
+---------------------+--------------------------------------------------------------------------------------------------------------------------------------------------+
|
|
| 2023-08-01T06:43:43 | 31 |
|
|
+---------------------+--------------------------------------------------------------------------------------------------------------------------------------------------+
|
|
|
|
-- 2023-09-01T06:43:43Z
|
|
tql eval (1693550623, 1693550623, '1s') days_in_month();
|
|
|
|
+---------------------+--------------------------------------------------------------------------------------------------------------------------------------------------+
|
|
| time | date_part(Utf8("day"),date_trunc(Utf8("month"),time) + IntervalYearMonth("1") - IntervalDayTime("IntervalDayTime { days: 1, milliseconds: 0 }")) |
|
|
+---------------------+--------------------------------------------------------------------------------------------------------------------------------------------------+
|
|
| 2023-09-01T06:43:43 | 30 |
|
|
+---------------------+--------------------------------------------------------------------------------------------------------------------------------------------------+
|
|
|
|
-- 2023-10-01T06:43:43Z
|
|
tql eval (1696142623, 1696142623, '1s') days_in_month();
|
|
|
|
+---------------------+--------------------------------------------------------------------------------------------------------------------------------------------------+
|
|
| time | date_part(Utf8("day"),date_trunc(Utf8("month"),time) + IntervalYearMonth("1") - IntervalDayTime("IntervalDayTime { days: 1, milliseconds: 0 }")) |
|
|
+---------------------+--------------------------------------------------------------------------------------------------------------------------------------------------+
|
|
| 2023-10-01T06:43:43 | 31 |
|
|
+---------------------+--------------------------------------------------------------------------------------------------------------------------------------------------+
|
|
|
|
-- 2023-11-01T06:43:43Z
|
|
tql eval (1698821023, 1698821023, '1s') days_in_month();
|
|
|
|
+---------------------+--------------------------------------------------------------------------------------------------------------------------------------------------+
|
|
| time | date_part(Utf8("day"),date_trunc(Utf8("month"),time) + IntervalYearMonth("1") - IntervalDayTime("IntervalDayTime { days: 1, milliseconds: 0 }")) |
|
|
+---------------------+--------------------------------------------------------------------------------------------------------------------------------------------------+
|
|
| 2023-11-01T06:43:43 | 30 |
|
|
+---------------------+--------------------------------------------------------------------------------------------------------------------------------------------------+
|
|
|
|
-- 2023-12-01T06:43:43Z
|
|
tql eval (1701413023, 1701413023, '1s') days_in_month();
|
|
|
|
+---------------------+--------------------------------------------------------------------------------------------------------------------------------------------------+
|
|
| time | date_part(Utf8("day"),date_trunc(Utf8("month"),time) + IntervalYearMonth("1") - IntervalDayTime("IntervalDayTime { days: 1, milliseconds: 0 }")) |
|
|
+---------------------+--------------------------------------------------------------------------------------------------------------------------------------------------+
|
|
| 2023-12-01T06:43:43 | 31 |
|
|
+---------------------+--------------------------------------------------------------------------------------------------------------------------------------------------+
|
|
|
|
drop table metrics;
|
|
|
|
Affected Rows: 0
|
|
|