Search in sources :

Example 1 with CsvSinkStreamOp

use of com.alibaba.alink.operator.stream.sink.CsvSinkStreamOp in project Alink by alibaba.

the class CsvSourceSinkTest method testStreamCsvSinkAndSource.

@Category(DbTest.class)
@Test
public void testStreamCsvSinkAndSource() throws Exception {
    String filePath = path + "file2.csv";
    String[] columnNames = new String[] { "id", "content" };
    StreamOperator data = new MemSourceStreamOp(rows, columnNames);
    CsvSinkStreamOp sink = new CsvSinkStreamOp().setFilePath(filePath).setOverwriteSink(true);
    data.link(sink);
    StreamOperator.execute();
    List<String> lines = Files.readAllLines(Paths.get(filePath));
    lines.forEach(line -> {
        int pos = line.indexOf(',');
        String key = line.substring(0, pos);
        Assert.assertEquals(line, actual.get(key));
    });
    StreamOperator source = new CsvSourceStreamOp().setFilePath(filePath).setSchemaStr("id bigint, content string");
    source.print();
    StreamOperator.execute();
}
Also used : MemSourceStreamOp(com.alibaba.alink.operator.stream.source.MemSourceStreamOp) CsvSinkStreamOp(com.alibaba.alink.operator.stream.sink.CsvSinkStreamOp) StreamOperator(com.alibaba.alink.operator.stream.StreamOperator) CsvSourceStreamOp(com.alibaba.alink.operator.stream.source.CsvSourceStreamOp) Category(org.junit.experimental.categories.Category) Test(org.junit.Test) DbTest(com.alibaba.alink.testutil.categories.DbTest)

Example 2 with CsvSinkStreamOp

use of com.alibaba.alink.operator.stream.sink.CsvSinkStreamOp in project Alink by alibaba.

the class Chap03 method c_2_1_2.

static void c_2_1_2() throws Exception {
    HadoopFileSystem hdfs = new HadoopFileSystem(HADOOP_VERSION, HDFS_URI);
    OssFileSystem oss = new OssFileSystem(OSS_VERSION, OSS_END_POINT, OSS_BUCKET_NAME, OSS_ACCESS_ID, OSS_ACCESS_KEY);
    FilePath[] filePaths = new FilePath[] { new FilePath(LOCAL_DIR + "iris.csv"), new FilePath(HDFS_URI + "user/yangxu/alink/data/temp/iris.csv", hdfs), new FilePath(OSS_PREFIX_URI + "alink/data/temp/iris.csv", oss) };
    for (FilePath filePath : filePaths) {
        new CsvSourceBatchOp().setFilePath(IRIS_HTTP_URL).setSchemaStr(IRIS_SCHEMA_STR).link(new CsvSinkBatchOp().setFilePath(filePath).setOverwriteSink(true));
        BatchOperator.execute();
        System.out.println(new CsvSourceBatchOp().setFilePath(filePath).setSchemaStr(IRIS_SCHEMA_STR).count());
    }
    for (FilePath filePath : filePaths) {
        new CsvSourceStreamOp().setFilePath(IRIS_HTTP_URL).setSchemaStr(IRIS_SCHEMA_STR).link(new CsvSinkStreamOp().setFilePath(filePath).setOverwriteSink(true));
        StreamOperator.execute();
        new CsvSourceStreamOp().setFilePath(filePath).setSchemaStr(IRIS_SCHEMA_STR).filter("sepal_length < 4.5").print();
        StreamOperator.execute();
    }
}
Also used : FilePath(com.alibaba.alink.common.io.filesystem.FilePath) CsvSinkBatchOp(com.alibaba.alink.operator.batch.sink.CsvSinkBatchOp) CsvSinkStreamOp(com.alibaba.alink.operator.stream.sink.CsvSinkStreamOp) HadoopFileSystem(com.alibaba.alink.common.io.filesystem.HadoopFileSystem) CsvSourceStreamOp(com.alibaba.alink.operator.stream.source.CsvSourceStreamOp) OssFileSystem(com.alibaba.alink.common.io.filesystem.OssFileSystem) CsvSourceBatchOp(com.alibaba.alink.operator.batch.source.CsvSourceBatchOp)

Aggregations

CsvSinkStreamOp (com.alibaba.alink.operator.stream.sink.CsvSinkStreamOp)2 CsvSourceStreamOp (com.alibaba.alink.operator.stream.source.CsvSourceStreamOp)2 FilePath (com.alibaba.alink.common.io.filesystem.FilePath)1 HadoopFileSystem (com.alibaba.alink.common.io.filesystem.HadoopFileSystem)1 OssFileSystem (com.alibaba.alink.common.io.filesystem.OssFileSystem)1 CsvSinkBatchOp (com.alibaba.alink.operator.batch.sink.CsvSinkBatchOp)1 CsvSourceBatchOp (com.alibaba.alink.operator.batch.source.CsvSourceBatchOp)1 StreamOperator (com.alibaba.alink.operator.stream.StreamOperator)1 MemSourceStreamOp (com.alibaba.alink.operator.stream.source.MemSourceStreamOp)1 DbTest (com.alibaba.alink.testutil.categories.DbTest)1 Test (org.junit.Test)1 Category (org.junit.experimental.categories.Category)1