@Override
  public PlanNode visitCountDevices(
      CountDevicesStatement countDevicesStatement, MPPQueryContext context) {
    LogicalPlanBuilder planBuilder = new LogicalPlanBuilder(analysis, context);

    if (countDevicesStatement.hasTimeCondition()) {
      planBuilder = planBuilder.planDeviceRegionScan(analysis.getDevicePathToContextMap(), true);
      return planBuilder.getRoot();
    }

    return planBuilder
        .planDevicesCountSource(
            countDevicesStatement.getPathPattern(),
            countDevicesStatement.isPrefixPath(),
            countDevicesStatement.getAuthorityScope())
        .planCountMerge()
        .getRoot();
  }
This visitor is used to generate a logical plan for the statement and returns the {@link
PlanNode}.
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/planner/LogicalPlanVisitor.java