@Test
  public void testPhysicalNavigationFunction() {
    String[] expectedHeader1 = new String[] {"time", "price"};
    String[] retArray1 =
        new String[] {
          "2025-01-01T00:01:00.000Z,null,",
          "2025-01-01T00:02:00.000Z,10.0,",
          "2025-01-01T00:03:00.000Z,20.0,",
        };
    String[] retArray2 =
        new String[] {
          "2025-01-01T00:01:00.000Z,null,",
          "2025-01-01T00:02:00.000Z,null,",
          "2025-01-01T00:03:00.000Z,10.0,",
        };
    String[] retArray3 =
        new String[] {
          "2025-01-01T00:01:00.000Z,20.0,",
          "2025-01-01T00:02:00.000Z,30.0,",
          "2025-01-01T00:03:00.000Z,null,",
        };
    String[] retArray4 =
        new String[] {
          "2025-01-01T00:01:00.000Z,30.0,",
          "2025-01-01T00:02:00.000Z,null,",
          "2025-01-01T00:03:00.000Z,null,",
        };
    String[] retArray5 =
        new String[] {
          "30.0,",
        };
    String[] retArray6 =
        new String[] {
          "20.0,",
        };
    String[] retArray7 =
        new String[] {
          "40.0,",
        };
    String[] retArray8 =
        new String[] {
          "null,",
        };

    String sql1 =
        "SELECT m.time, m.price "
            + "FROM t2 "
            + "MATCH_RECOGNIZE ( "
            + "    MEASURES "
            + "        %s AS price "
            + "    ALL ROWS PER MATCH "
            + "    AFTER MATCH SKIP PAST LAST ROW "
            + "    PATTERN (A+) "
            + "    DEFINE "
            + "        A AS true "
            + ") AS m";
    // PREV(totalprice)
    tableResultSetEqualTest(
        format(sql1, "PREV(totalprice)"), expectedHeader1, retArray1, DATABASE_NAME);
    tableResultSetEqualTest(
        format(sql1, "PREV(totalprice, 1)"), expectedHeader1, retArray1, DATABASE_NAME);

    // PREV(totalprice, 2)
    tableResultSetEqualTest(
        format(sql1, "PREV(totalprice, 2)"), expectedHeader1, retArray2, DATABASE_NAME);

    // NEXT(totalprice)
    tableResultSetEqualTest(
        format(sql1, "NEXT(totalprice)"), expectedHeader1, retArray3, DATABASE_NAME);
    tableResultSetEqualTest(
        format(sql1, "NEXT(totalprice, 1)"), expectedHeader1, retArray3, DATABASE_NAME);

    // NEXT(totalprice, 2)
    tableResultSetEqualTest(
        format(sql1, "NEXT(totalprice, 2)"), expectedHeader1, retArray4, DATABASE_NAME);

    String[] expectedHeader2 = new String[] {"price"};
    String sql2 =
        "SELECT m.price "
            + "FROM t3 "
            + "MATCH_RECOGNIZE ( "
            + "    MEASURES "
            + "        %s AS price "
            + "    ONE ROW PER MATCH "
            + "    AFTER MATCH SKIP PAST LAST ROW "
            + "    PATTERN (A) "
            + "    DEFINE "
            + "        A AS A.totalprice = PREV(A.totalprice) "
            + ") AS m";
    // PREV(A.totalprice)
    tableResultSetEqualTest(
        format(sql2, "PREV(A.totalprice)"), expectedHeader2, retArray5, DATABASE_NAME);
    tableResultSetEqualTest(
        format(sql2, "PREV(A.totalprice, 1)"), expectedHeader2, retArray5, DATABASE_NAME);

    // PREV(A.totalprice, 2)
    tableResultSetEqualTest(
        format(sql2, "PREV(A.totalprice, 2)"), expectedHeader2, retArray6, DATABASE_NAME);

    // NEXT(A.totalprice)
    tableResultSetEqualTest(
        format(sql2, "NEXT(A.totalprice)"), expectedHeader2, retArray7, DATABASE_NAME);
    tableResultSetEqualTest(
        format(sql2, "NEXT(A.totalprice, 1)"), expectedHeader2, retArray7, DATABASE_NAME);

    // out of partition
    tableResultSetEqualTest(
        format(sql2, "PREV(A.totalprice, 4)"), expectedHeader2, retArray8, DATABASE_NAME);
    tableResultSetEqualTest(
        format(sql2, "NEXT(A.totalprice, 2)"), expectedHeader2, retArray8, 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