更新时间:2023-11-16 GMT+08:00
分享

IoTDB UDF样例代码

功能简介

该样例代码介绍如何实现一个简单的IoTDB自定义函数(UDF)。详细信息可以参考UDF样例程序与操作章节。

代码样例

package com.huawei.bigdata.iotdb;
import org.apache.iotdb.udf.api.UDTF;
import org.apache.iotdb.udf.api.access.Row;
import org.apache.iotdb.udf.api.collector.PointCollector;
import org.apache.iotdb.udf.api.customizer.config.UDTFConfigurations;
import org.apache.iotdb.udf.api.customizer.parameter.UDFParameters;
import org.apache.iotdb.udf.api.customizer.strategy.RowByRowAccessStrategy;
import org.apache.iotdb.udf.api.type.Type;
import java.io.IOException;

public class UDTFExample implements UDTF {
    @Override    
     public void beforeStart(UDFParameters parameters, UDTFConfigurations configurations) {        
       configurations.setAccessStrategy(new RowByRowAccessStrategy()).setOutputDataType(Type.INT32);    
    }

    @Override    
    public void transform(Row row, PointCollector collector) throws IOException {        
      collector.putInt(row.getTime(), -row.getInt(0));    
    }
}
分享:

    相关文档

    相关产品