alink-IO操作
1.读取数据
包括文本,csv,mysql和kafka格式
可以从外部读入数据到alink中,在alink中数据保存在一个op中
Kafka011SourceStreamOp,MySqlSourceBatchOp,TextSourceBatchOp
package demo.srcdemo; import com.alibaba.alink.operator.stream.source.CsvSourceStreamOp; public class CSVDemo { public static void main(String[] args){ String filePath = "http://alink-dataset.cn-hangzhou.oss.aliyun-inc.com/csv/iris.csv"; CsvSourceStreamOp csvOp = new CsvSourceStreamOp() .setFilePath(filePath) .setSchemaStr("sepal_length double, sepal_width double, petal_length double, petal_width double, category string").setFieldDelimiter(","); csvOp.print(); } }
2.数据输出保存
包括保存本地,mysql
数据从一个op到一个数据源中。
CsvSinkBatchOp,Kafka011SinkStreamOp,TextSinkBatchOp
package demo.srcdemo; import com.alibaba.alink.operator.batch.sink.CsvSinkBatchOp; import com.alibaba.alink.operator.stream.source.CsvSourceStreamOp; public class CSVDemo { public static void main(String[] args){ String filePath = "http://alink-dataset.cn-hangzhou.oss.aliyun-inc.com/csv/iris.csv"; CsvSourceStreamOp csvOp = new CsvSourceStreamOp() .setFilePath(filePath) .setSchemaStr("sepal_length double, sepal_width double, petal_length double, petal_width double, category string").setFieldDelimiter(","); csvOp.print(); CsvSinkBatchOp sinkBatchOp = new CsvSinkBatchOp().setFilePath("./o.csv"); } }