@Test
  public void UDAFGroupByLevelSLimitTest() throws Exception {
    String[] expected = new String[] {"5,4", "4,6", "3"};
    try (Connection connection = EnvFactory.getEnv().getConnection();
        Statement statement = connection.createStatement()) {

      int cnt = 0;
      try (ResultSet resultSet =
          statement.executeQuery(
              "SELECT count_udaf(temperature), count_udaf(status) "
                  + "FROM root.*.* "
                  + "GROUP BY LEVEL=1 "
                  + "SLIMIT 2")) {
        while (resultSet.next()) {
          String actual =
              resultSet.getString(countUDAF("root.sg1.*.temperature"))
                  + ","
                  + resultSet.getString(countUDAF("root.sg2.*.temperature"));
          Assert.assertEquals(expected[cnt], actual);
          cnt++;
        }
      }

      try (ResultSet resultSet =
          statement.executeQuery(
              "SELECT count_udaf(temperature), count_udaf(status) "
                  + "FROM root.*.* "
                  + "GROUP BY LEVEL=1 "
                  + "SLIMIT 2 SOFFSET 1")) {
        while (resultSet.next()) {
          String actual =
              resultSet.getString(countUDAF("root.sg2.*.temperature"))
                  + ","
                  + resultSet.getString(countUDAF("root.sg1.*.status"));
          Assert.assertEquals(expected[cnt], actual);
          cnt++;
        }
      }

      try (ResultSet resultSet =
          statement.executeQuery(
              "SELECT count_udaf(temperature), count_udaf(status) "
                  + "FROM root.*.* "
                  + "GROUP BY level=1,2 "
                  + "slimit 1 soffset 4")) {
        while (resultSet.next()) {
          String actual = resultSet.getString(countUDAF("root.sg1.d1.status"));
          Assert.assertEquals(expected[cnt], actual);
          cnt++;
        }
      }
    }
  }
[root.sg.d1.temperature, root.sg.d2.temperature] with level = 2

<p>Result is [root.*.d1.temperature, root.*.d2.temperature]
integration-test/src/test/java/org/apache/iotdb/db/it/udaf/IoTDBUDAFGroupByLevelIT.java