Java 类名:com.alibaba.alink.operator.stream.sink.CsvSinkStreamOp
Python 类名:CsvSinkStreamOp

功能介绍

写CSV文件

参数说明

| 名称 | 中文名称 | 描述 | 类型 | 是否必须? | 取值范围 | 默认值 | | —- | —- | —- | —- | —- | —- | —- |

| filePath | 文件路径 | 文件路径 | String | ✓ | | |

| fieldDelimiter | 字段分隔符 | 字段分隔符 | String | | | “,” |

| numFiles | 文件数目 | 文件数目 | Integer | | | 1 |

| overwriteSink | 是否覆写已有数据 | 是否覆写已有数据 | Boolean | | | false |

| quoteChar | 引号字符 | 引号字符 | Character | | | “”” |

| rowDelimiter | 行分隔符 | 行分隔符 | String | | | “\n” |

代码示例

Python 代码

  1. filePath = 'https://alink-test-data.oss-cn-hangzhou.aliyuncs.com/iris.csv'
  2. schema = 'sepal_length double, sepal_width double, petal_length double, petal_width double, category string'
  3. csvSource = CsvSourceStreamOp()\
  4. .setFilePath(filePath)\
  5. .setSchemaStr(schema)\
  6. .setFieldDelimiter(",")
  7. csvSink = CsvSinkStreamOp()\
  8. .setFilePath('~/csv_test_s.txt')
  9. csvSource.link(csvSink)
  10. StreamOperator.execute()

Java 代码

  1. import com.alibaba.alink.operator.stream.StreamOperator;
  2. import com.alibaba.alink.operator.stream.sink.CsvSinkStreamOp;
  3. import com.alibaba.alink.operator.stream.source.CsvSourceStreamOp;
  4. import org.junit.Test;
  5. public class CsvSinkStreamOpTest {
  6. @Test
  7. public void testCsvSinkStreamOp() throws Exception {
  8. String filePath = "https://alink-test-data.oss-cn-hangzhou.aliyuncs.com/iris.csv";
  9. String schema
  10. = "sepal_length double, sepal_width double, petal_length double, petal_width double, category string";
  11. CsvSourceStreamOp csvSource = new CsvSourceStreamOp()
  12. .setFilePath(filePath)
  13. .setSchemaStr(schema)
  14. .setFieldDelimiter(",");
  15. CsvSinkStreamOp csvSink = new CsvSinkStreamOp()
  16. .setFilePath("~/csv_test_s.txt");
  17. csvSource.link(csvSink);
  18. StreamOperator.execute();
  19. }
  20. }