Java 类名:com.alibaba.alink.operator.batch.sink.CsvSinkBatchOp
Python 类名:CsvSinkBatchOp

功能介绍

写CSV文件。支持写到本地、hdfs。

参数说明

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

| 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 = CsvSourceBatchOp()\
  4. .setFilePath(filePath)\
  5. .setSchemaStr(schema)\
  6. .setFieldDelimiter(",")
  7. csvSink = CsvSinkBatchOp()\
  8. .setFilePath('~/csv_test.txt')
  9. csvSource.link(csvSink)
  10. BatchOperator.execute()

Java 代码

  1. import com.alibaba.alink.operator.batch.BatchOperator;
  2. import com.alibaba.alink.operator.batch.sink.CsvSinkBatchOp;
  3. import com.alibaba.alink.operator.batch.source.CsvSourceBatchOp;
  4. import org.junit.Test;
  5. public class CsvSinkBatchOpTest {
  6. @Test
  7. public void testCsvSinkBatchOp() 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. CsvSourceBatchOp csvSource = new CsvSourceBatchOp()
  12. .setFilePath(filePath)
  13. .setSchemaStr(schema)
  14. .setFieldDelimiter(",");
  15. CsvSinkBatchOp csvSink = new CsvSinkBatchOp()
  16. .setFilePath("~/csv_test.txt");
  17. csvSource.link(csvSink);
  18. BatchOperator.execute();
  19. }
  20. }