@Override
  public Analysis visitDeleteData(
      DeleteDataStatement deleteDataStatement, MPPQueryContext context) {
    context.setQueryType(QueryType.WRITE);
    Analysis analysis = new Analysis();
    analysis.setRealStatement(deleteDataStatement);

    PathPatternTree patternTree = new PathPatternTree();
    deleteDataStatement.getPathList().forEach(patternTree::appendPathPattern);

    ISchemaTree schemaTree = schemaFetcher.fetchSchema(patternTree, true, context);
    Set<IDeviceID> deduplicatedDeviceIDs = new HashSet<>();

    if (schemaTree.hasLogicalViewMeasurement()) {
      updateSchemaTreeByViews(analysis, schemaTree, context);

      Set<MeasurementPath> deletePatternSet = new HashSet<>(deleteDataStatement.getPathList());
      IMeasurementSchema measurementSchema;
      LogicalViewSchema logicalViewSchema;
      PartialPath sourcePathOfAliasSeries;
      for (MeasurementPath measurementPath :
          schemaTree.searchMeasurementPaths(ALL_MATCH_PATTERN).left) {
        measurementSchema = measurementPath.getMeasurementSchema();
        if (measurementSchema.isLogicalView()) {
          logicalViewSchema = (LogicalViewSchema) measurementSchema;
          if (logicalViewSchema.isWritable()) {
            sourcePathOfAliasSeries = logicalViewSchema.getSourcePathIfWritable();
            // if the source path can be matched by any of the deletion pattern, do not add it
            boolean pathMatched = false;
            for (MeasurementPath deletionPattern : deleteDataStatement.getPathList()) {
              if (deletionPattern.matchFullPath(sourcePathOfAliasSeries)) {
                pathMatched = true;
                break;
              }
            }
            if (pathMatched) {
              continue;
            }

            deletePatternSet.add(new MeasurementPath(sourcePathOfAliasSeries.getNodes()));
            deduplicatedDeviceIDs.add(sourcePathOfAliasSeries.getIDeviceID());
          }
          deletePatternSet.remove(measurementPath);
        } else {
          deduplicatedDeviceIDs.add(measurementPath.getIDeviceID());
        }
      }
      deleteDataStatement.setPathList(new ArrayList<>(deletePatternSet));
    } else {
      for (PartialPath devicePattern : patternTree.getAllDevicePaths()) {
        schemaTree
            .getMatchedDevices(devicePattern)
            .forEach(
                deviceSchemaInfo ->
                    deduplicatedDeviceIDs.add(
                        deviceSchemaInfo.getDevicePath().getIDeviceIDAsFullDevice()));
      }
    }
    analysis.setSchemaTree(schemaTree);

    Map<String, List<DataPartitionQueryParam>> sgNameToQueryParamsMap = new HashMap<>();

    deduplicatedDeviceIDs.forEach(
        deviceID -> {
          DataPartitionQueryParam queryParam = new DataPartitionQueryParam();
          queryParam.setDeviceID(deviceID);
          sgNameToQueryParamsMap
              .computeIfAbsent(schemaTree.getBelongedDatabase(deviceID), key -> new ArrayList<>())
              .add(queryParam);
        });

    DataPartition dataPartition = partitionFetcher.getDataPartition(sgNameToQueryParamsMap);
    analysis.setDataPartitionInfo(dataPartition);
    analysis.setFinishQueryAfterAnalyze(dataPartition.isEmpty());

    return analysis;
  }
Since we fetch raw time series schema without template(The template sequence will be treated
as a normal node, not a device+templateId. This means that all nodes are what we need.). We
can use ALL_MATCH_PATTERN to get result.
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/analyze/AnalyzeVisitor.java