public static PartialPath getDatabasePathByLevel(PartialPath path, int level)
      throws MetadataException {
    String[] nodeNames = path.getNodes();
    if (nodeNames.length <= level) {
      throw new IllegalPathException(
          path.getFullPath(), "it is no longer than default sg level: " + level);
    }
    if (!nodeNames[0].equals(IoTDBConstant.PATH_ROOT)) {
      throw new IllegalPathException(
          path.getFullPath(), "it does not start with " + IoTDBConstant.PATH_ROOT);
    }
    String[] storageGroupNodes = new String[level + 1];
    System.arraycopy(nodeNames, 0, storageGroupNodes, 0, level + 1);
    return new PartialPath(storageGroupNodes);
  }
Get database path when creating schema automatically is enabled

<p>e.g., path = root.a.b.c and level = 1, return root.a

@param path path
@param level level
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/schemaengine/schemaregion/utils/MetaUtils.java