| 74 | class PivotLongerNode : public ExecNode, public TracedNode { |
| 75 | public: |
| 76 | static Result<std::shared_ptr<Schema>> MakeOutputSchema( |
| 77 | const PivotLongerNodeOptions& options, |
| 78 | const std::shared_ptr<Schema>& input_schema) { |
| 79 | // Some of this is pure validation and not strictly needed to create the output schema |
| 80 | // but it's simpler to just do all validation here than to try and split between this |
| 81 | // method and PivotLongerNode::Make |
| 82 | if (options.row_templates.empty()) { |
| 83 | return Status::Invalid("There must be at least one row template"); |
| 84 | } |
| 85 | if (options.feature_field_names.empty() || options.measurement_field_names.empty()) { |
| 86 | return Status::Invalid( |
| 87 | "There must be at least one feature column and one measurement column and they " |
| 88 | "must " |
| 89 | "have names"); |
| 90 | } |
| 91 | |
| 92 | std::vector<std::shared_ptr<DataType>> feature_types( |
| 93 | options.feature_field_names.size()); |
| 94 | for (const auto& row_template : options.row_templates) { |
| 95 | if (row_template.feature_values.size() != options.feature_field_names.size()) { |
| 96 | return Status::Invalid("There were names given for ", |
| 97 | options.feature_field_names.size(), |
| 98 | " feature columns but one of the row templates only had ", |
| 99 | row_template.feature_values.size(), " feature values"); |
| 100 | } |
| 101 | if (row_template.measurement_values.size() != |
| 102 | options.measurement_field_names.size()) { |
| 103 | return Status::Invalid( |
| 104 | "There were names given for ", options.measurement_field_names.size(), |
| 105 | " measurement columns but one of the row templates only had ", |
| 106 | row_template.measurement_values.size(), " field references"); |
| 107 | } |
| 108 | |
| 109 | for (std::size_t i = 0; i < row_template.feature_values.size(); i++) { |
| 110 | if (!row_template.feature_values[i]) { |
| 111 | return Status::Invalid("Feature value at column ", |
| 112 | options.feature_field_names[i], " must not be null"); |
| 113 | } |
| 114 | if (feature_types[i]) { |
| 115 | if (!feature_types[i]->Equals(row_template.feature_values[i]->type)) { |
| 116 | return Status::TypeError( |
| 117 | "Mixed feature types at column ", options.feature_field_names[i], |
| 118 | ". Some row templates had the type ", feature_types[i]->ToString(), |
| 119 | " but later row templates had the type ", |
| 120 | row_template.feature_values[i]->type->ToString(), |
| 121 | ". All row templates must have same type for each feature " |
| 122 | "column."); |
| 123 | } |
| 124 | } else { |
| 125 | feature_types[i] = row_template.feature_values[i]->type; |
| 126 | } |
| 127 | } |
| 128 | } |
| 129 | |
| 130 | std::vector<std::shared_ptr<Field>> fields(input_schema->fields()); |
| 131 | for (std::size_t i = 0; i < options.feature_field_names.size(); i++) { |
| 132 | fields.push_back( |
| 133 | field(options.feature_field_names[i], std::move(feature_types[i]))); |
nothing calls this directly
no test coverage detected