public BeamPCollectionTable(PCollection<InputT> upstream) { super(upstream.getSchema()); if (!upstream.hasSchema()) { throw new RuntimeException("SQL can only run over PCollections that have schemas."); } this.upstream = upstream; }
/** Returns the attached schema's toRowFunction. */ @Experimental(Kind.SCHEMAS) public SerializableFunction<T, Row> getToRowFunction() { if (!hasSchema()) { throw new IllegalStateException("Cannot call getToRowFunction when there is no schema"); } return ((SchemaCoder<T>) getCoder()).getToRowFunction(); }
/** Returns the attached schema. */ @Experimental(Kind.SCHEMAS) public Schema getSchema() { if (!hasSchema()) { throw new IllegalStateException("Cannot call getSchema when there is no schema"); } return ((SchemaCoder) getCoder()).getSchema(); }
/** Returns the attached schema's fromRowFunction. */ @Experimental(Kind.SCHEMAS) public SerializableFunction<Row, T> getFromRowFunction() { if (!hasSchema()) { throw new IllegalStateException("Cannot call getFromRowFunction when there is no schema"); } return ((SchemaCoder<T>) getCoder()).getFromRowFunction(); }
@Override @SuppressWarnings("unchecked") public PCollection<OutputT> expand(PCollection<InputT> input) { if (!input.hasSchema()) { throw new RuntimeException("Convert requires a schema on the input.");
@Test @Category({ValidatesRunner.class, UsesSchema.class}) public void testSchemasPassedThrough() { List<InferredPojo> pojoList = Lists.newArrayList( new InferredPojo("a", 1), new InferredPojo("b", 2), new InferredPojo("c", 3)); PCollection<InferredPojo> out = pipeline.apply(Create.of(pojoList)).apply(Filter.by(e -> true)); assertTrue(out.hasSchema()); pipeline.run(); } }