| 838 | } |
| 839 | |
| 840 | void Pipe::transform(const Transformer & transformer, bool check_ports) |
| 841 | { |
| 842 | if (output_ports.empty()) |
| 843 | throw Exception(ErrorCodes::LOGICAL_ERROR, "Cannot transform empty Pipe"); |
| 844 | |
| 845 | auto new_processors = transformer(output_ports); |
| 846 | |
| 847 | /// Create hash table with new processors. |
| 848 | UnorderedSetWithMemoryTracking<const IProcessor *> set; |
| 849 | for (const auto & processor : new_processors) |
| 850 | set.emplace(processor.get()); |
| 851 | |
| 852 | for (const auto & port : output_ports) |
| 853 | { |
| 854 | if (!check_ports) |
| 855 | break; |
| 856 | |
| 857 | if (!port->isConnected()) |
| 858 | throw Exception( |
| 859 | ErrorCodes::LOGICAL_ERROR, |
| 860 | "Transformation of Pipe is not valid because output port ({})", |
| 861 | port->getHeader().dumpStructure()); |
| 862 | |
| 863 | set.emplace(&port->getProcessor()); |
| 864 | } |
| 865 | |
| 866 | output_ports.clear(); |
| 867 | |
| 868 | for (const auto & processor : new_processors) |
| 869 | { |
| 870 | for (const auto & port : processor->getInputs()) |
| 871 | { |
| 872 | if (!check_ports) |
| 873 | break; |
| 874 | |
| 875 | if (!port.isConnected()) |
| 876 | throw Exception( |
| 877 | ErrorCodes::LOGICAL_ERROR, |
| 878 | "Transformation of Pipe is not valid because processor {} has not connected input port", |
| 879 | processor->getName()); |
| 880 | |
| 881 | const auto * connected_processor = &port.getOutputPort().getProcessor(); |
| 882 | if (check_ports && !set.contains(connected_processor)) |
| 883 | throw Exception( |
| 884 | ErrorCodes::LOGICAL_ERROR, |
| 885 | "Transformation of Pipe is not valid because processor {} has input port which is connected with unknown processor {}", |
| 886 | processor->getName(), |
| 887 | connected_processor->getName()); |
| 888 | } |
| 889 | |
| 890 | for (auto & port : processor->getOutputs()) |
| 891 | { |
| 892 | if (!port.isConnected()) |
| 893 | { |
| 894 | output_ports.push_back(&port); |
| 895 | continue; |
| 896 | } |
| 897 |
no test coverage detected