@Override
  public Result apply(TableFunctionNode node, Captures captures, Context context) {
    if (node.getChildren().isEmpty()) {
      return Result.ofPlanNode(
          new TableFunctionProcessorNode(
              node.getPlanNodeId(),
              node.getName(),
              node.getProperOutputs(),
              Optional.empty(),
              Optional.empty(),
              ImmutableList.of(),
              Optional.empty(),
              false,
              node.getTableFunctionHandle(),
              false));
    } else if (node.getChildren().size() == 1) {
      // Single source does not require pre-processing.
      // If the source has row semantics, its specification is empty.
      // If the source has set semantics, its specification is present, even if there is no
      // partitioning or ordering specified.
      // This property can be used later to choose optimal distribution.
      TableFunctionNode.TableArgumentProperties sourceProperties =
          getOnlyElement(node.getTableArgumentProperties());
      AtomicReference<PlanNode> child = new AtomicReference<>(getOnlyElement(node.getChildren()));

      // generate sort node
      sourceProperties
          .getDataOrganizationSpecification()
          .ifPresent(
              dataOrganizationSpecification -> {
                List<Symbol> sortSymbols = new ArrayList<>();
                Map<Symbol, SortOrder> sortOrderings = new HashMap<>();
                for (Symbol symbol : dataOrganizationSpecification.getPartitionBy()) {
                  sortSymbols.add(symbol);
                  sortOrderings.put(symbol, ASC_NULLS_LAST);
                }
                int sortKeyOffset = sortSymbols.size();
                dataOrganizationSpecification
                    .getOrderingScheme()
                    .ifPresent(
                        orderingScheme -> {
                          for (Symbol symbol : orderingScheme.getOrderBy()) {
                            if (!sortOrderings.containsKey(symbol)) {
                              sortSymbols.add(symbol);
                              sortOrderings.put(symbol, orderingScheme.getOrdering(symbol));
                            }
                          }
                        });
                child.set(
                    new GroupNode(
                        context.getIdAllocator().genPlanNodeId(),
                        child.get(),
                        new OrderingScheme(sortSymbols, sortOrderings),
                        sortKeyOffset));
              });
      return Result.ofPlanNode(
          new TableFunctionProcessorNode(
              node.getPlanNodeId(),
              node.getName(),
              node.getProperOutputs(),
              Optional.of(child.get()),
              Optional.ofNullable(sourceProperties.getPassThroughSpecification()),
              sourceProperties.getRequiredColumns(),
              sourceProperties.getDataOrganizationSpecification(),
              sourceProperties.isRowSemantics(),
              node.getTableFunctionHandle(),
              sourceProperties.isRequireRecordSnapshot()));
    } else {
      // we don't support multiple source now.
      throw new IllegalArgumentException("table function does not support multiple source now.");
    }
  }
This rule prepares cartesian product of partitions from all inputs of table function.

<p>It rewrites TableFunctionNode with potentially many sources into a TableFunctionProcessorNode.
The new node has one source being a combination of the original sources.
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/planner/iterative/rule/ImplementTableFunctionSource.java