【问题标题】:Flink CsvTableSource StreamingFlink CsvTableSource 流式处理
【发布时间】:2017-08-01 19:33:28
【问题描述】:

我想流式传输 csv 文件并使用 flink 执行 sql 操作。但是我写的代码只读了一次就停止了。它不流式传输。提前致谢,

StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();

StreamTableEnvironment tableEnv = StreamTableEnvironment.getTableEnvironment(env);

CsvTableSource csvtable = CsvTableSource.builder()
    .path("D:/employee.csv")
    .ignoreFirstLine()
    .fieldDelimiter(",")
    .field("id", Types.INT())
    .field("name", Types.STRING())
    .field("designation", Types.STRING())
    .field("age", Types.INT())
    .field("location", Types.STRING())
    .build();

tableEnv.registerTableSource("employee", csvtable);

Table table = tableEnv.scan("employee").where("name='jay'").select("id,name,location");
//Table table1 = tableEnv.scan("employee").where("age > 23").select("id,name,age,location");

DataStream<Row> stream = tableEnv.toAppendStream(table, Row.class);

//DataStream<Row> stream1 = tableEnv.toAppendStream(table1, Row.class);

stream.print();
//stream1.print();

env.execute();

【问题讨论】:

    标签: apache-flink flink-streaming


    【解决方案1】:

    CsvTableSource 基于 FileInputFormat,它逐行读取和解析引用的文件。结果行被转发到流式查询中。所以CsvTableSource 是流式传输的,因为行被连续读取和转发。但是,CsvTableSource 在文件末尾终止。因此,它会发出一个有界流。

    我假设您期望的行为是CsvTableSource 读取文件直到其结束,然后等待追加写入文件。 但是,这不是CsvTableSource 的工作方式。为此,您需要实现自定义 TableSource

    【讨论】:

    • 感谢@Fabian Hueske 提供的信息
    猜你喜欢
    • 2017-02-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-04-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多