upstream/piflow-bundle/src/main/scala/cn/piflow/bundle/json/JsonSave.scala
1package cn.piflow.bundle.json
2
3import cn.piflow._
4import cn.piflow.conf._
5import cn.piflow.conf.bean.PropertyDescriptor
6import cn.piflow.conf.util.{ImageUtil, MapUtil}
7import org.apache.spark.sql.SaveMode
8
9import scala.beans.BeanProperty
10
11class JsonSave extends ConfigurableStop{
12
13 val authorEmail: String = "xjzhu@cnic.cn"
14 val description: String = "Save data into json file"
15 val inportList: List[String] = List(Port.DefaultPort)
16 val outportList: List[String] = List(Port.DefaultPort)
17
18 var jsonSavePath: String = _
19
20 def perform(in: JobInputStream, out: JobOutputStream, pec: JobContext): Unit = {
21
22 val jsonDF = in.read()
23 jsonDF.write.format("json").mode(SaveMode.Overwrite).save(jsonSavePath)
24 }
25
26 def initialize(ctx: ProcessContext): Unit = {
27
28 }
29
30 override def setProperties(map: Map[String, Any]): Unit = {
31 jsonSavePath = MapUtil.get(map,"jsonSavePath").asInstanceOf[String]
32 }
33
34 override def getPropertyDescriptor(): List[PropertyDescriptor] = {
35 var descriptor : List[PropertyDescriptor] = List()
36 val jsonSavePath = new PropertyDescriptor()
37 .name("jsonSavePath")
38 .displayName("JsonSavePath")
39 .description("The save path of the json file")
40 .defaultValue("")
41 .required(true)
42 .example("/test/test.json")
43
44 descriptor = jsonSavePath :: descriptor
45 descriptor
46 }
47
48 override def getIcon(): Array[Byte] = {
49 ImageUtil.getImage("icon/json/JsonSave.png")
50 }
51
52 override def getGroup(): List[String] = {
53 List(StopGroup.JsonGroup)
54 }
55
56
57}