@Override public Coder<Row> getAccumulatorCoder(CoderRegistry registry, Coder<Row> inputCoder) throws CannotProvideCoderException { return SchemaCoder.of(EMPTY_SCHEMA); }
/** 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 a {@link SchemaCoder} for the specified class. If no schema is registered for this * class, then throws {@link NoSuchSchemaException}. */ public static <T> SchemaCoder<T> of( Schema schema, SerializableFunction<T, Row> toRowFunction, SerializableFunction<Row, T> fromRowFunction) { return new SchemaCoder<>(schema, toRowFunction, fromRowFunction); }
SchemaCoder.of( input.getSchema(), SerializableFunctions.identity(), try { outputSchemaCoder = SchemaCoder.of( registry.getSchema(outputTypeDescriptor), registry.getToRowFunction(outputTypeDescriptor), if (!outputSchemaCoder.getSchema().assignableToIgnoreNullable(input.getSchema())) { throw new RuntimeException( "Cannot convert between types that don't have equivalent schemas." + input.getSchema() + " output schema: " + outputSchemaCoder.getSchema()); outputSchemaCoder.getSchema(), outputSchemaCoder.getToRowFunction(), outputSchemaCoder.getFromRowFunction());
@Override public void outputWithTimestamp(Row output, Instant timestamp) { outputReceiver.outputWithTimestamp(schemaCoder.getFromRowFunction().apply(output), timestamp); } }
/** 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(); }
@ProcessElement public void processElement(@Element Row row, OutputReceiver<OutputT> o) { o.output(outputSchemaCoder.getFromRowFunction().apply(row)); } }))
@Override public Coder<Row> getDefaultOutputCoder(CoderRegistry registry, Coder<Row> inputCoder) { return SchemaCoder.of(EMPTY_SCHEMA); } }
fieldAccessDescriptor.resolve(((SchemaCoder<?>) inputCoder).getSchema());
@Override public void output(Row output) { outputReceiver.output(schemaCoder.getFromRowFunction().apply(output)); }
/** Returns a {@link SchemaCoder} for {@link Row} classes. */ public static SchemaCoder<Row> of(Schema schema) { return new SchemaCoder<>( schema, SerializableFunctions.identity(), SerializableFunctions.identity()); }
/** * Returns a {@link Create.TimestampedValues} PTransform like this one that uses the given * {@code Schema} to represent objects. */ @Experimental(Kind.SCHEMAS) public TimestampedValues<T> withSchema( Schema schema, SerializableFunction<T, Row> toRowFunction, SerializableFunction<Row, T> fromRowFunction) { return withCoder(SchemaCoder.of(schema, toRowFunction, fromRowFunction)); }
fieldAccessDescriptor = fieldAccessDescriptor.resolve(schemaCoder.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(); }
public static <T> Builder<T> create( Schema schema, SerializableFunction<T, Row> toRowFunction, SerializableFunction<Row, T> fromRowFunction) { return create(SchemaCoder.of(schema, toRowFunction, fromRowFunction)); }
/** * Returns a {@link Create.Values} PTransform like this one that uses the given {@code Schema} * to represent objects. */ @Experimental(Kind.SCHEMAS) public Values<T> withSchema( Schema schema, SerializableFunction<T, Row> toRowFunction, SerializableFunction<Row, T> fromRowFunction) { return withCoder(SchemaCoder.of(schema, toRowFunction, fromRowFunction)); }
/** Sets a {@link Schema} on this {@link PCollection}. */ @Experimental(Kind.SCHEMAS) public PCollection<T> setSchema( Schema schema, SerializableFunction<T, Row> toRowFunction, SerializableFunction<Row, T> fromRowFunction) { return setCoder(SchemaCoder.of(schema, toRowFunction, fromRowFunction)); }
private static <T> PCollection<KV<Row, Row>> extractKey( PCollection<T> pCollection, Schema schema, Schema keySchema, FieldAccessDescriptor keyFields, String tag) { return pCollection .apply( "extractKey" + tag, ParDo.of( new DoFn<T, KV<Row, Row>>() { @ProcessElement public void process(@Element Row row, OutputReceiver<KV<Row, Row>> o) { o.output(KV.of(Select.selectRow(row, keyFields, schema, keySchema), row)); } })) .setCoder(KvCoder.of(SchemaCoder.of(keySchema), SchemaCoder.of(schema))); } }
public Coder<Row> rowCoder() { return SchemaCoder.of( tableWithRows.table.getSchema(), SerializableFunctions.identity(), SerializableFunctions.identity()); }
@Override public Coder<Row> getDefaultOutputCoder(CoderRegistry registry, Coder<T> inputCoder) { return SchemaCoder.of( getOutputSchema(), SerializableFunctions.identity(), SerializableFunctions.identity()); }