@Test
  public void testRowPattern() {
    String[] expectedHeader = new String[] {"time", "match", "price", "label"};
    String[] retArray1 =
        new String[] {
          "2025-01-01T00:01:00.000Z,1,90.0,A,",
        };
    String[] retArray2 =
        new String[] {
          "2025-01-01T00:04:00.000Z,1,70.0,A,",
        };
    String[] retArray3 =
        new String[] {
          "2025-01-01T00:02:00.000Z,1,80.0,A,",
          "2025-01-01T00:03:00.000Z,1,70.0,B,",
          "2025-01-01T00:04:00.000Z,1,70.0,C,",
        };
    String[] retArray4 =
        new String[] {
          "2025-01-01T00:01:00.000Z,1,90.0,A,",
          "2025-01-01T00:02:00.000Z,2,80.0,B,",
          "2025-01-01T00:03:00.000Z,3,70.0,B,",
          "2025-01-01T00:04:00.000Z,4,70.0,C,",
        };
    String[] retArray5 =
        new String[] {
          "2025-01-01T00:02:00.000Z,1,80.0,B,", "2025-01-01T00:03:00.000Z,1,70.0,C,",
        };

    String sql =
        "SELECT m.time, m.match, m.price, m.label "
            + "FROM t1 "
            + "MATCH_RECOGNIZE ( "
            + "    MEASURES "
            + "        MATCH_NUMBER() AS match, "
            + "        RUNNING RPR_LAST(totalprice) AS price,  "
            + "        CLASSIFIER() AS label "
            + "    ALL ROWS PER MATCH "
            + "    AFTER MATCH SKIP PAST LAST ROW "
            + "    %s " // PATTERN and DEFINE
            + ") AS m";

    // anchor pattern: partition start
    tableResultSetEqualTest(
        format(sql, "PATTERN (^A) " + "DEFINE A AS true "),
        expectedHeader,
        retArray1,
        DATABASE_NAME);

    tableResultSetEqualTest(
        format(sql, "PATTERN (A^) " + "DEFINE A AS true "),
        expectedHeader,
        new String[] {},
        DATABASE_NAME);

    tableResultSetEqualTest(
        format(sql, "PATTERN (^A^) " + "DEFINE A AS true "),
        expectedHeader,
        new String[] {},
        DATABASE_NAME);

    // anchor pattern: partition end
    tableResultSetEqualTest(
        format(sql, "PATTERN (A$) " + "DEFINE A AS true "),
        expectedHeader,
        retArray2,
        DATABASE_NAME);

    tableResultSetEqualTest(
        format(sql, "PATTERN ($A) " + "DEFINE A AS true "),
        expectedHeader,
        new String[] {},
        DATABASE_NAME);

    tableResultSetEqualTest(
        format(sql, "PATTERN ($A$) " + "DEFINE A AS true "),
        expectedHeader,
        new String[] {},
        DATABASE_NAME);

    // pattern concatenation
    tableResultSetEqualTest(
        format(
            sql,
            "PATTERN (A B C) "
                + "DEFINE "
                + "    B AS B.totalprice < PREV (B.totalprice), "
                + "    C AS C.totalprice = PREV (C.totalprice)"),
        expectedHeader,
        retArray3,
        DATABASE_NAME);

    // pattern alternation
    tableResultSetEqualTest(
        format(
            sql,
            "PATTERN (B | C | A) "
                + "DEFINE "
                + "    B AS B.totalprice < PREV (B.totalprice), "
                + "    C AS C.totalprice <= PREV (C.totalprice)"),
        expectedHeader,
        retArray4,
        DATABASE_NAME);

    // pattern permutation
    tableResultSetEqualTest(
        format(
            sql,
            "PATTERN (PERMUTE(B, C)) "
                + "DEFINE "
                + "    B AS B.totalprice < PREV (B.totalprice), "
                + "    C AS C.totalprice < PREV (C.totalprice)"),
        expectedHeader,
        retArray5,
        DATABASE_NAME);

    // grouped pattern
    tableResultSetEqualTest(
        format(
            sql,
            "PATTERN (((A) (B (C)))) "
                + "DEFINE "
                + "    B AS B.totalprice < PREV (B.totalprice), "
                + "    C AS C.totalprice = PREV (C.totalprice)"),
        expectedHeader,
        retArray3,
        DATABASE_NAME);
  }
Search range: all devices whose department is 'DEP_1', each device's data is grouped
separately, and the time range is between 2025-01-01T00:00:00 and 2025-01-01T01:00:00.

<p>Event analysis: Whenever the altitude exceeds 500 and then drops below 500, it is marked as
an event.
integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/IoTDBPatternRecognitionIT.java