feat: interval& None value for prev&`next (#252)

* test: for builtin functions

* test: expect fail for `datetime()`

* feat: add `interval()` fn(WIP)

* feat: `interval()` fn in builtin(UNTEST)

* refactor: move `py_vec_obj_to_array` to util.rs

* style: fmt

* test: simple `interval()` cases

* test: `interval()` with `last()`&`first()`

* doc: `ts` param of `interval()`

* log: common_telemetry for logging in script crate

* doc: corrsponding test fn for each .ron file

* feat: change to`mpsc` for schedule_job

* test: schedule_job

* dep: rm rustpython dep in common-function

* refactor: mv `schedule_job` into `Script` trait

* test: change to use `interval` to sample datapoint

* feat: add gen_none_array for generate None Array

* feat: impl Missing value for `prev`&`next`

* test: `sum(prev(values))`

* doc: add comment for why not support Float16 in `prev()`

* feat: add `interval` in py side mock module

* style: cargo fmt

* refactor: according to comments

* refactor: extract `apply_interval_function`

* style: cargo fmt

* refactor: remove `schedule()`

* style: cargo fmt
This commit is contained in:
discord9
2022-09-14 10:48:27 +08:00
committed by GitHub
parent ec99eb0cd0
commit 20dcaa6897
18 changed files with 918 additions and 146 deletions

View File

@@ -1,6 +1,6 @@
// This is the file for UDF&UDAF binding from datafusion,
// including most test for those function(except ApproxMedian which datafusion didn't implement)
// check src/scalars/py_udf_module/test.rs for more information
// check src/script/builtins/test.rs::run_builtin_fn_testcases() for more information
[
// math expressions
TestCase(
@@ -670,7 +670,10 @@ pow(values, pows)"#,
script: r#"
from greptime import *
pow(values, 1)"#,
expect: Err("TypeError: Can't cast operand of type `int` into `vector`.")
expect: Ok((
value: FloatVec([ 1.0, 2.0, 3.0]),
ty: Float64
))
),
TestCase(
input: {
@@ -781,4 +784,145 @@ from greptime import *
sin(num)"#,
expect: Err("Can't cast object of type str into vector or scalar")
),
TestCase(
input: {},
script: r#"
from greptime import *
datetime("7d")"#,
expect: Ok((
ty: Int64,
value: Int(604800)
))
),
TestCase(
input: {},
script: r#"
from greptime import *
datetime("7dd")"#,
expect: Err("Unknown time unit")
),
TestCase(
input: {},
script: r#"
from greptime import *
datetime("d7")"#,
expect: Err("Python Runtime error, error:")
),
TestCase(
input: {
"values": Var(
ty: Float64,
value: FloatVec([1.0, 2.0, 3.0])
),
"ts": Var(
ty: Int64,
value: IntVec([0, 9, 20])
),
},
script: r#"
from greptime import *
interval(ts, values, 10, lambda x:sum(x))"#,
expect: Ok((
ty: Float64,
value: FloatVec([3.0, 3.0])
))
),
TestCase(
input: {
"values": Var(
ty: Float64,
value: FloatVec([1.0, 2.0, 3.0, 4.0])
),
"ts": Var(
ty: Int64,
value: IntVec([0, 9, 19, 20])
),
},
script: r#"
from greptime import *
interval(ts, values, 10, lambda x:last(x))"#,
expect: Ok((
ty: Float64,
value: FloatVec([2.0, 4.0])
))
),
TestCase(
input: {
"values": Var(
ty: Float64,
value: FloatVec([1.0, 2.0, 3.0, 4.0])
),
"ts": Var(
ty: Int64,
value: IntVec([0, 9, 19, 20])
),
},
script: r#"
from greptime import *
interval(ts, values, 10, lambda x:first(x))"#,
expect: Ok((
ty: Float64,
value: FloatVec([1.0, 3.0])
))
),
TestCase(
input: {
"values": Var(
ty: Float64,
value: FloatVec([])
)
},
script: r#"
from greptime import *
prev(values)"#,
expect: Ok((
ty: Float64,
value: FloatVec([1.0])
))
),
TestCase(
input: {
"values": Var(
ty: Float64,
value: FloatVec([1.0, 2.0, 3.0])
)
},
script: r#"
from greptime import *
prev(values)"#,
expect: Ok((
ty: Float64,
value: FloatVecWithNull([None, Some(1.0), Some(2.0)])
))
),
TestCase(
input: {
"values": Var(
ty: Float64,
value: FloatVec([1.0, 2.0, 3.0])
)
},
script: r#"
from greptime import *
next(values)"#,
expect: Ok((
ty: Float64,
value: FloatVecWithNull([Some(2.0), Some(3.0), None])
))
),
TestCase(
input: {
"values": Var(
ty: Float64,
value: FloatVec([1.0, 2.0, 3.0])
)
},
script: r#"
from greptime import *
sum(prev(values))"#,
expect: Ok((
ty: Float64,
value: Float(3.0)
))
)
]