/** * Sets a schema on this PCollection. * * <p>Can only be called on a {@link PCollection}. */ @Experimental(Kind.SCHEMAS) public PCollection<T> setRowSchema(Schema schema) { return setSchema( schema, (SerializableFunction<T, Row>) SerializableFunctions.<Row>identity(), (SerializableFunction<Row, T>) SerializableFunctions.<Row>identity()); }
.setSchema( outputSchemaCoder.getSchema(), outputSchemaCoder.getToRowFunction(),
.setSchema( CalciteUtils.toSchema(getRowType()), SerializableFunctions.identity(),
/** Query has all the input fields, so no projection is added. */ @Test public void testSupportsAggregationWithoutProjection() throws Exception { pipeline.enableAbandonedNodeEnforcement(false); Schema schema = Schema.builder().addInt32Field("f_intGroupingKey").addInt32Field("f_intValue").build(); PCollection<Row> inputRows = pipeline .apply( Create.of( TestUtils.rowsBuilderOf(schema) .addRows( 0, 1, 0, 2, 1, 3, 2, 4, 2, 5) .getRows())) .setSchema(schema, SerializableFunctions.identity(), SerializableFunctions.identity()); String sql = "SELECT SUM(f_intValue) FROM PCOLLECTION GROUP BY f_intGroupingKey"; PCollection<Row> result = inputRows.apply("sql", SqlTransform.query(sql)); PAssert.that(result).containsInAnyOrder(rowsWithSingleIntField("sum", Arrays.asList(3, 3, 9))); pipeline.run(); }
@Override public PCollection<OutputT> expand(PCollection<? extends InputT> input) { SchemaRegistry schemaRegistry = input.getPipeline().getSchemaRegistry(); CoderRegistry registry = input.getPipeline().getCoderRegistry(); finishSpecifyingStateSpecs(fn, registry, input.getCoder()); TupleTag<OutputT> mainOutput = new TupleTag<>(MAIN_OUTPUT_TAG); PCollection<OutputT> res = input.apply(withOutputTags(mainOutput, TupleTagList.empty())).get(mainOutput); try { res.setSchema( schemaRegistry.getSchema(getFn().getOutputTypeDescriptor()), schemaRegistry.getToRowFunction(getFn().getOutputTypeDescriptor()), schemaRegistry.getFromRowFunction(getFn().getOutputTypeDescriptor())); } catch (NoSuchSchemaException e) { try { res.setCoder( registry.getCoder( getFn().getOutputTypeDescriptor(), getFn().getInputTypeDescriptor(), ((PCollection<InputT>) input).getCoder())); } catch (CannotProvideCoderException e2) { // Ignore and leave coder unset. } } return res; }
.setSchema( schema2, o -> Row.withSchema(schema2).addValues(o.stringField, o.integerField).build(),