簡體   English   中英

如何定義具有行時間屬性的 apache flink 表

[英]How to define an apache flink table with row time attribute

我有 json 行作為我的數據,我想從中創建一個表。

StreamTableEnvironment fsTableEnv = StreamTableEnvironment.create(streamExecutionEnvironment, fsSettings);
String allEventsTable = "allEventsTable";
        fsTableEnv.connect(new Kafka()
                            .version("0.11")
                            .topic("events")
                            .property("bootstrap.servers", "localhost:9092")
                            .property("group.id", "dummyquery").startFromLatest())
                .withSchema(new Schema()
                    .field("rule_id", Types.INT)
                    .field("sourceAddress", Types.STRING)
                    .field("deviceProduct", Types.STRING)
                    .field("destHost", Types.STRING)
                    .field("extra", Types.STRING)
                    .field("rowtime", Types.SQL_TIMESTAMP)
                        .rowtime(new Rowtime().timestampsFromField("rowtime").watermarksPeriodicBounded(2000))

                )
                .withFormat(new Json().failOnMissingField(false).deriveSchema())
                .inAppendMode()
                .registerTableSource(allEventsTable);

         Table result = fsTableEnv.sqlQuery("select * from allEventsTable where sourceAddress='12345431'");

        DataStream alert = fsTableEnv.toAppendStream(result, Row.class);
        alert.print();

但是,在運行作業時出現錯誤

Exception in thread "main" org.apache.flink.table.api.ValidationException: Field 'rowtime' could not be resolved by the field mapping.
    at org.apache.flink.table.sources.TableSourceValidation.resolveField(TableSourceValidation.java:245)
    at org.apache.flink.table.sources.TableSourceValidation.lambda$validateTimestampExtractorArguments$6(TableSourceValidation.java:202)
    at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193)
    at java.util.Spliterators$ArraySpliterator.forEachRemaining(Spliterators.java:948)
    at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:481)
    at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:471)
    at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:545)
    at java.util.stream.AbstractPipeline.evaluateToArrayNode(AbstractPipeline.java:260)
    at java.util.stream.ReferencePipeline.toArray(ReferencePipeline.java:438)

附言。 我正在使用 flink 1.9

我放入 kafka 主題事件的 json 數據就像

{"rule_id":"", "rowtime":"2020-07-23 13:10:13","sourceAddress":"12345433","deviceProduct":"234r5t", "destHost":"876543", "extra":"dummy"}

恐怕這是一個錯誤。 我創建了https://issues.apache.org/jira/browse/FLINK-15801來跟蹤它。

如果您更改行時間定義中的字段名稱之一,您應該能夠解決這個問題。 更改邏輯字段的名稱:

.field("timeAttribute", Types.SQL_TIMESTAMP)
    .rowtime(new Rowtime().timestampsFromField("rowtime").watermarksPeriodicBounded(2000))

或物理起源領域:

.field("rowtime", Types.SQL_TIMESTAMP)
    .rowtime(new Rowtime().timestampsFromField("timestamp").watermarksPeriodicBounded(2000))

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM