[
https://issues.apache.org/jira/browse/IOTDB-751?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17181980#comment-17181980
]
Steve Yurong Su commented on IOTDB-751:
---------------------------------------
h1. *function design*
# UDF allows users to programmatically access the original query data, allows
users to transform, filter or extend the data, and control the final output of
the function. Users can call UDF in a way similar to calling IoTDB's built-in
aggregate functions. Here is an example:
select abs(s0) from root.sg1.d0, root.sg1.d1;
The UDF query above will return 2 columns of results, each column may
have multiple rows of data, and each value is the result of the absolute value
of the original data value.
# UDF distinguishes UDAF and UDTF according to the number of rows output by
the function. The output result of UDAF must be one row without a timestamp;
while the output result of UDTF can be 0 row, 1 row, or multiple rows, and each
row must have a timestamp.
# A UDAF can output only one column of data and can receive only one column of
time series as its input.
# A UDTF can only output one column of data, but it can receive multiple time
series as its input raw data. A possible UDTF use case is as follows:
select add(s0, s1), sub(s0, s1) from root.sg1.d0, root.sg1.d1 where
s2 > 0;
The UDTF query above will return 4 columns of results.
# All UDFs can receive key-value pairs as their input attributes in the
parameter list. Key-value pairs can only appear after the suffixPath part of
the parameter list. The key and value of each key-value pair are strings quoted
by single or double quotes. The user programming interface provides a type
conversion tool for parsing key-value pairs. The following is a possible usage
scenario:
select hifi(s0, "operator"="m4") from root.sg1.d0;
The above example performs high-fidelity sampling on the s0 sequence
(different from the built-in downsampling method of IoTDB), and uses m4 as the
sampling operator (the user can choose other downsampling operators).
# Allow UDTFs and ordinary time series to appear in the select clause at the
same time, and allow UDAFs and built-in aggregation functions to appear in the
select clause. Examples:
select s0, s1, udtf(s0, s1) from root.sg1.d0; selecr max(s0),
min(s0), udaf(s0) from root.sg1.d0;
# A UDF is defined by a Java class. The system uses Java reflection technology
to load UDF into the system. Each query corresponds to a UDF instance.
# The user can specify the access method of the original data when programming.
Users can use 3 types of column (DataPoint) iterators to access the
original time series for each column:
* DataPointIterator: Provides the ability to access full time series data
point by point
* DataPointBatchIterator: Provides the ability to access full time series data
in batches (with a fixed number of data points / a fixed time interval)
* OverallDataPointIterator: Provides the ability to randomly access (similar
to the way to access List through index) full time series data
For UDFs that allow multi-column time series input, users can also
specify several columns of time series to be merged into rows according to time
alignment, and use row iterators for iterative access. Row iterators are
similar to column iterators, and 3 types of iterators are also provided:
* RowRecordIterator
* RowRecordBatchIterator
* OverallRowRecordIterator
# Users (or administrators) can load, unload, and display UDF instances
through SQL statements:
CREATE [temporary] FUNCTION function_name AS class_name;
DROP [temporary] FUNCTION function_name;
SHOW [temporary] FUNCTIONS;
Among them, the UDF with the temporary keyword will not be
automatically registered and started the next time IoTDB is started.
> Support UDF
> -----------
>
> Key: IOTDB-751
> URL: https://issues.apache.org/jira/browse/IOTDB-751
> Project: Apache IoTDB
> Issue Type: New Feature
> Components: Core/Engine
> Reporter: Jialin Qiao
> Priority: Major
>
> For example, select abs(s1) from root
> select s1+s2 from root
--
This message was sent by Atlassian Jira
(v8.3.4#803005)