@Test
  public void testPatternQuantifier() {
    String[] expectedHeader = new String[] {"time", "match", "price", "label"};
    String[] retArray1 =
        new String[] {
          "2025-01-01T00:01:00.000Z,1,null,null,",
          "2025-01-01T00:02:00.000Z,2,80.0,B,",
          "2025-01-01T00:03:00.000Z,2,70.0,B,",
          "2025-01-01T00:04:00.000Z,2,70.0,B,",
        };
    String[] retArray2 =
        new String[] {
          "2025-01-01T00:01:00.000Z,1,null,null,",
          "2025-01-01T00:02:00.000Z,2,null,null,",
          "2025-01-01T00:03:00.000Z,3,null,null,",
          "2025-01-01T00:04:00.000Z,4,null,null,",
        };
    String[] retArray3 =
        new String[] {
          "2025-01-01T00:02:00.000Z,1,80.0,B,",
          "2025-01-01T00:03:00.000Z,1,70.0,B,",
          "2025-01-01T00:04:00.000Z,1,70.0,B,",
        };
    String[] retArray4 =
        new String[] {
          "2025-01-01T00:02:00.000Z,1,80.0,B,",
          "2025-01-01T00:03:00.000Z,2,70.0,B,",
          "2025-01-01T00:04:00.000Z,3,70.0,B,",
        };
    String[] retArray5 =
        new String[] {
          "2025-01-01T00:01:00.000Z,1,null,null,",
          "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,B,",
        };
    String[] retArray6 =
        new String[] {
          "2025-01-01T00:02:00.000Z,1,80.0,B,", "2025-01-01T00:03:00.000Z,1,70.0,B,",
        };

    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
            + "    DEFINE "
            + "        B AS B.totalprice <= PREV(B.totalprice) "
            + ") AS m";

    tableResultSetEqualTest(format(sql, "PATTERN (B*)"), expectedHeader, retArray1, DATABASE_NAME);

    tableResultSetEqualTest(format(sql, "PATTERN (B*?)"), expectedHeader, retArray2, DATABASE_NAME);

    tableResultSetEqualTest(format(sql, "PATTERN (B+)"), expectedHeader, retArray3, DATABASE_NAME);

    tableResultSetEqualTest(format(sql, "PATTERN (B+?)"), expectedHeader, retArray4, DATABASE_NAME);

    tableResultSetEqualTest(format(sql, "PATTERN (B?)"), expectedHeader, retArray5, DATABASE_NAME);

    tableResultSetEqualTest(format(sql, "PATTERN (B??)"), expectedHeader, retArray2, DATABASE_NAME);

    tableResultSetEqualTest(
        format(sql, "PATTERN (B{,})"), expectedHeader, retArray1, DATABASE_NAME);

    tableResultSetEqualTest(
        format(sql, "PATTERN (B{,}?)"), expectedHeader, retArray2, DATABASE_NAME);

    tableResultSetEqualTest(
        format(sql, "PATTERN (B{1,})"), expectedHeader, retArray3, DATABASE_NAME);

    tableResultSetEqualTest(
        format(sql, "PATTERN (B{1,}?)"), expectedHeader, retArray4, DATABASE_NAME);

    tableResultSetEqualTest(
        format(sql, "PATTERN (B{2,})"), expectedHeader, retArray3, DATABASE_NAME);

    tableResultSetEqualTest(
        format(sql, "PATTERN (B{2,}?)"), expectedHeader, retArray6, DATABASE_NAME);

    tableResultSetEqualTest(
        format(sql, "PATTERN (B{5,})"), expectedHeader, new String[] {}, DATABASE_NAME);

    tableResultSetEqualTest(
        format(sql, "PATTERN (B{5,}?)"), expectedHeader, new String[] {}, DATABASE_NAME);

    tableResultSetEqualTest(
        format(sql, "PATTERN (B{,1})"), expectedHeader, retArray5, DATABASE_NAME);

    tableResultSetEqualTest(
        format(sql, "PATTERN (B{,1}?)"), expectedHeader, retArray2, DATABASE_NAME);

    tableResultSetEqualTest(
        format(sql, "PATTERN (B{1,1})"), expectedHeader, retArray4, DATABASE_NAME);

    tableResultSetEqualTest(
        format(sql, "PATTERN (B{1,1}?)"), expectedHeader, retArray4, DATABASE_NAME);

    tableResultSetEqualTest(
        format(sql, "PATTERN (B{1})"), expectedHeader, retArray4, DATABASE_NAME);

    tableResultSetEqualTest(
        format(sql, "PATTERN (B{1}?)"), expectedHeader, retArray4, 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