【问题标题】:Why flink 1.7 CEP SQL(MATCH_RECOGNIZE) cant work为什么 flink 1.7 CEP SQL(MATCH_RECOGNIZE) 不能工作
【发布时间】:2019-01-25 12:56:31
【问题描述】:
Flink SQL> describe Ticker;
root
 |-- symbol: String
 |-- rowtime: Timestamp
 |-- price: Long


Flink SQL> SELECT *
> FROM Ticker
> MATCH_RECOGNIZE (
>     PARTITION BY symbol
>     ORDER BY rowtime
>     MEASURES
>         START_ROW.rowtime AS start_rowtime,
>         LAST(PRICE_DOWN.rowtime) AS bottom_rowtime,
>         LAST(PRICE_UP.rowtime) AS end_rowtime
>     ONE ROW PER MATCH
>     AFTER MATCH SKIP TO LAST PRICE_UP
>     PATTERN (START_ROW PRICE_DOWN+ PRICE_UP)
>     DEFINE
>         PRICE_DOWN AS
>             (LAST(PRICE_DOWN.price, 1) IS NULL AND PRICE_DOWN.price < START_ROW.price) OR
>                 PRICE_DOWN.price < LAST(PRICE_DOWN.price, 1),
>         PRICE_UP AS
>             PRICE_UP.price > LAST(PRICE_DOWN.price, 1)
>     ) MR;
[ERROR] Could not execute SQL statement. Reason:
org.apache.flink.table.api.ValidationException: You must specify either rowtime or proctime for order by as the first one.

页面https://ci.apache.org/projects/flink/flink-docs-release-1.7/dev/table/streaming/match_recognize.html

我的环境如下:

SQLClient 的 env yaml:

tables:
  - name: Ticker
    type: source-table
    update-mode: append
    connector:
      type: filesystem
      path: "/home/leisore/flink/flink-1.7.1/table.csv"
    format:
      type: csv
      fields:
        - name: symbol
          type: STRING
        - name: rowtime
          type: TIMESTAMP
        - name: price
          type: LONG
      line-delimiter: "\n"
      comment-prefix: "#"
    schema:
        - name: symbol
          type: STRING
        - name: rowtime
          type: TIMESTAMP
        - name: price
          type: LONG

table.csv

ACME,2019-01-1,12
ACME,2019-01-2,17
ACME,2019-01-3,19
ACME,2019-01-4,21
ACME,2019-01-5,25
ACME,2019-01-6,12
ACME,2019-01-7,15
ACME,2019-01-8,20
ACME,2019-01-9,24
ACME,2019-01-10,25
ACME,2019-01-11,19
ACME,2019-01-12,15
ACME,2019-01-13,25
ACME,2019-01-14,25
ACME,2019-01-15,14
ACME,2019-01-16,12
ACME,2019-01-17,14
ACME,2019-01-18,24
ACME,2019-01-19,23
ACME,2019-01-20,22
Run SQLClient:
============================
./sql-client.sh embedded -e ../sqlenv.yaml 
>>Flink SQL> SELECT *
> FROM Ticker
> MATCH_RECOGNIZE (
>     PARTITION BY symbol
>     ORDER BY rowtime
>     MEASURES
>         START_ROW.rowtime AS start_rowtime,
>         LAST(PRICE_DOWN.rowtime) AS bottom_rowtime,
>         LAST(PRICE_UP.rowtime) AS end_rowtime
>     ONE ROW PER MATCH
>     AFTER MATCH SKIP TO LAST PRICE_UP
>     PATTERN (START_ROW PRICE_DOWN+ PRICE_UP)
>     DEFINE
>         PRICE_DOWN AS
>             (LAST(PRICE_DOWN.price, 1) IS NULL AND PRICE_DOWN.price < START_ROW.price) OR
>                 PRICE_DOWN.price < LAST(PRICE_DOWN.price, 1),
>         PRICE_UP AS
>             PRICE_UP.price > LAST(PRICE_DOWN.price, 1)
>     ) MR;
[ERROR] Could not execute SQL statement. Reason:
org.apache.flink.table.api.ValidationException: You must specify either rowtime or proctime for order by as the first one.

总是输出: [错误] 无法执行 SQL 语句。原因: org.apache.flink.table.api.ValidationException: 您必须将 order by 的 rowtime 或 proctime 指定为第一个。

【问题讨论】:

    标签: apache-flink


    【解决方案1】:

    因为必须在time-attribute 字段中指定异常消息的主要顺序。您可以在 example 中查看如何将字段转换为时间属性。

    重要的是:

      - name: rowTime
        type: TIMESTAMP
        rowtime:
          timestamps:
            type: "from-field"
            from: "rideTime"
          watermarks:
            type: "periodic-bounded"
            delay: "60000"
    

    【讨论】:

    • CsvAppendTableSourceFactory 似乎不支持时间属性字段的规范。您知道不使用 Kafka 或自定义源即可使其工作的方法吗?
    • 是的,大卫·安德森是对的。 CsvAppendTableSourceFactory 不支持时间属性字段。添加rowtime->timestamps时出现如下错误:原因:匹配工厂'org.apache.flink.table.sources.CsvAppendTableSourceFactory'不支持'schema.#.rowtime.timestamps.from'。
    • 啊,不知道。我想你将不得不在DataStream API 中手动分配时间戳和水印,或者正如 David 通过一些支持时间属性的自定义或其他来源所说的那样。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-01-01
    • 1970-01-01
    • 2011-07-27
    • 1970-01-01
    • 1970-01-01
    • 2022-08-19
    相关资源
    最近更新 更多