0

我正在使用 flink 1.11 并尝试使用 match_recognize 的嵌套查询,如下所示:

select * from events where id = (SELECT * FROM events MATCH_RECOGNIZE (PARTITION BY org_id ORDER BY proctime MEASURES A.id AS startId ONE ROW PER MATCH PATTERN (A C* B) DEFINE A AS A.tag = 'tag1', C AS C.tag <> 'tag2', B AS B.tag = 'tag2'));

我收到一个错误:org.apache.calcite.sql.validate.SqlValidatorException: Table 'A' not found

这不支持吗?如果不是还有什么选择?

4

1 回答 1

1

通过这样做,我能够得到一些工作:

Table events = tableEnv.fromDataStream(input,
    $("sensorId"),
    $("ts").rowtime(),
    $("kwh"));

tableEnv.createTemporaryView("events", events);

Table matches = tableEnv.sqlQuery(
                "SELECT id " +
                    "FROM events " +
                    "MATCH_RECOGNIZE ( " +
                        "PARTITION BY sensorId " +
                        "ORDER BY ts " +
                        "MEASURES " +
                            "this_step.sensorId AS id " +
                        "AFTER MATCH SKIP TO NEXT ROW " +
                        "PATTERN (this_step next_step) " +
                        "DEFINE " +
                            "this_step AS TRUE, " +
                            "next_step AS TRUE " +
                    ")"
        );

tableEnv.createTemporaryView("mmm", matches);

Table results = tableEnv.sqlQuery(
    "SELECT * FROM events WHERE events.sensorId IN (select * from mmm)");

tableEnv
    .toAppendStream(results, Row.class)
    .print();

出于某种原因,如果不定义视图,我就无法让它工作。我不断收到方解石错误。

我猜你是想避免在 MATCH_RECOGNIZE 的 MEASURES 子句中枚举 A 中的所有列。您可能想要比较生成的执行计划,看看是否有任何显着差异。

于 2021-05-12T08:56:52.380 回答