|
2 | 2 |
|
3 | 3 | import org.apache.beam.sdk.Pipeline; |
4 | 4 | import org.apache.beam.sdk.schemas.Schema; |
5 | | -import org.apache.beam.sdk.values.PBegin; |
6 | | -import org.apache.beam.sdk.values.PCollectionRowTuple; |
7 | | -import org.apache.beam.sdk.values.POutput; |
| 5 | +import org.apache.beam.sdk.values.*; |
8 | 6 | import org.ohnlp.backbone.api.Extract; |
9 | 7 | import org.ohnlp.backbone.api.Load; |
10 | 8 | import org.ohnlp.backbone.api.components.*; |
| 9 | +import org.ohnlp.backbone.api.exceptions.ComponentInitializationException; |
11 | 10 | import org.ohnlp.backbone.core.PipelineBuilder; |
12 | 11 | import org.ohnlp.backbone.core.config.BackbonePipelineComponentConfiguration; |
13 | 12 |
|
@@ -122,6 +121,31 @@ private Set<PipelineBuilder.InitializedPipelineComponent> runNextBatchOrDefer( |
122 | 121 | initSchema = true; |
123 | 122 | } |
124 | 123 | } |
| 124 | + // Check schema for required columns if any |
| 125 | + if (component.getComponent() instanceof HasInputs) { |
| 126 | + Map<String, PCollection<Row>> inputs = inputToNextStep.get().getAll(); |
| 127 | + inputs.forEach((tag, coll) -> { |
| 128 | + Schema s = ((HasInputs) component.getComponent()).getRequiredColumns(tag); |
| 129 | + if (s != null) { |
| 130 | + // Has required columns |
| 131 | + Schema inputSchema = coll.getSchema(); |
| 132 | + List<String> requiredButMissing = new ArrayList<>(); |
| 133 | + for (Schema.Field f : s.getFields()) { |
| 134 | + if (!inputSchema.hasField(f.getName())) { |
| 135 | + // TODO do type checking |
| 136 | + requiredButMissing.add(f.getName()); |
| 137 | + } |
| 138 | + } |
| 139 | + if (!requiredButMissing.isEmpty()) { |
| 140 | + throw new IllegalArgumentException(component.getComponentID() |
| 141 | + + " requires the following fields that are missing from the supplied input: " + |
| 142 | + "[" + String.join(",", requiredButMissing) + "]. Available Fields: [" + |
| 143 | + String.join(",", inputSchema.getFieldNames()) + "]"); |
| 144 | + } |
| 145 | + |
| 146 | + } |
| 147 | + }); |
| 148 | + } |
125 | 149 | if (component.getComponent() instanceof TransformComponent) { |
126 | 150 | if (initSchema) { |
127 | 151 | nextSchema = ((TransformComponent) component.getComponent()).calculateOutputSchema(inputSchemas); |
|
0 commit comments