lf-edge / ekuiper

Lightweight data stream processing engine for IoT edge
https://ekuiper.org
Apache License 2.0
1.46k stars 411 forks source link

Binary type support #641

Closed jinfahua closed 3 years ago

jinfahua commented 3 years ago

Kuiper Binary Support

bytea type

Datatype bytea is a sequence of bytes, aka. byte array. The impelmentation is []byte in golang.

Stream/Source

binary format

Add new format binary in stream definition:

create stream demo(image bytea) with (FORMAT="binary", source="images/")

Validate for this format:

  1. Only one column and the column type must be bytea.
  2. For schemaless mode, the column name will default to self.

Soure node decode binary format

Each source needs to check format type and do decoding accordingly.

Soure node decode json format with binary field

Image Processing Function

Validates the argument col's type, must be bytea

Function Example Description
resize resize(col:bytea, width:bigint, height:bigint) Resize the image to width * height
compress compress(col:bytea, format:string) Convert and compress the image to other types

Sink

jinfahua commented 3 years ago

Image Sink

Image sink is used for saving pictures into specified folders.

Compile & deploy plugin

# cd $kuiper_src
# go build --buildmode=plugin -o plugins/sinks/Image.so plugins/sinks/image.go
# cp plugins/sinks/Image.so $kuiper_install/plugins/sinks

Reboot Kuiper to activate plugin.

Properties

Name Optional Description
path N Path for saving pictures, such as /tmp
maxAge N Expired time for picture files. Default value is 72 hours, which means that the images files can be saved by 3 days.

Sample

Below demo describes saving picture into /tmp folder every 5 seconds, and delete images files that are expired after 72hrs.

{
  "sql": "SELECT * from demo",
  "actions": [
    {
      "image": {
        "path": "/tmp",
        "maxAge":72
      }
    }
  ]
}
EMQmyd commented 3 years ago

下面示例演示接收图片并将图片保存到文件夹 /tmp 中,同时将保存时长超过72小时的图片删除。 { "sql": "SELECT * from demo", "actions": [ { "image": { "path": "/tmp", "format": "png", "filePrefix":"image" "maxage":72 } } ] }

EMQmyd commented 3 years ago
属性名称 是否可选 说明
path 保存结果的文件夹路径,例如 /tmp
format 文件格式,支持 jpeg 和 png。
maxAge 最长文件存储时间(小时)。默认值为72,这表示图片最多保存3天。
filePrefix 图片文件名前缀,默认为 image,文件格式样例为 image_2020-12-12_11-15-23-345.png
ngjaying commented 3 years ago

This was supported in 1.1.0 so closed.