Java 类名:com.alibaba.alink.operator.stream.sink.TsvSinkStreamOp
Python 类名:TsvSinkStreamOp
本组件将输入数据写出到Tsv文件,Tsv文件以tab为分隔符。
名称 | 中文名称 | 描述 | 类型 | 是否必须? | 取值范围 | 默认值 |
---|---|---|---|---|---|---|
filePath | 文件路径 | 文件路径 | String | ✓ | ||
numFiles | 文件数目 | 文件数目 | Integer | 1 | ||
overwriteSink | 是否覆写已有数据 | 是否覆写已有数据 | Boolean | false |
** 以下代码仅用于示意,可能需要修改部分代码或者配置环境后才能正常运行!**
df = pd.DataFrame([ ["0L", "1L", 0.6], ["2L", "2L", 0.8], ["2L", "4L", 0.6], ["3L", "1L", 0.6], ["3L", "2L", 0.3], ["3L", "4L", 0.4] ]) source = StreamOperator.fromDataframe(df, schemaStr='uid string, iid string, label double') filepath = "/tmp/abc.tsv" tsvSink = TsvSinkStreamOp()\ .setFilePath(filepath)\ .setOverwriteSink(True) source.link(tsvSink) StreamOperator.execute() tsvSource = TsvSourceStreamOp().setFilePath(filepath).setSchemaStr("f string"); tsvSource.print() StreamOperator.execute()
** 以下代码仅用于示意,可能需要修改部分代码或者配置环境后才能正常运行!**
import org.apache.flink.types.Row; import com.alibaba.alink.operator.stream.StreamOperator; import com.alibaba.alink.operator.stream.sink.TsvSinkStreamOp; import com.alibaba.alink.operator.stream.source.MemSourceStreamOp; import com.alibaba.alink.operator.stream.source.TsvSourceStreamOp; import org.junit.Test; import java.util.Arrays; import java.util.List; public class TsvSinkStreamOpTest { @Test public void testTsvSinkStreamOp() throws Exception { List <Row> df = Arrays.asList( Row.of("0L", "1L", 0.6), Row.of("2L", "2L", 0.8), Row.of("2L", "4L", 0.6), Row.of("3L", "1L", 0.6), Row.of("3L", "2L", 0.3), Row.of("3L", "4L", 0.4) ); StreamOperator <?> source = new MemSourceStreamOp(df, "uid string, iid string, label double"); String filepath = "/tmp/abc.tsv"; StreamOperator <?> tsvSink = new TsvSinkStreamOp() .setFilePath(filepath) .setOverwriteSink(true); source.link(tsvSink); StreamOperator.execute(); StreamOperator <?> tsvSource = new TsvSourceStreamOp().setFilePath(filepath).setSchemaStr("f string"); tsvSource.print(); StreamOperator.execute(); } }