Package org.apache.beam.sdk.coders
Class RowCoderGenerator
java.lang.Object
org.apache.beam.sdk.coders.RowCoderGenerator
A utility for automatically generating a
Coder
for Row
objects corresponding to a
specific schema. The resulting coder is loaded into the default ClassLoader and returned.
When generate(Schema)
is called, a new subclass of
Coder<Row> is generated for the specified schema. This class is generated using low-level
bytecode generation, and hardcodes encodings for all fields of the Schema. Empirically, this is
30-40% faster than a coder that introspects the schema.
The generated class corresponds to the following Java class:
class SchemaRowCoder extendsCoder<Row> {
// Generated array containing a coder for each field in the Schema.
private static final Coder[] FIELD_CODERS;
// Generated method to return the schema this class corresponds to. Used during code
// generation.
private static getSchema() {
return schema;
}
@Override
public void encode(T value, OutputStream outStream) {
// Delegate to a method that evaluates each coder in the static array.
encodeDelegate(FIELD_CODERS, value, outStream);
}
@Override
public abstract T decode(InputStream inStream) {
// Delegate to a method that evaluates each coder in the static array.
return decodeDelegate(FIELD_CODERS, inStream);
}
}
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
RowCoderGenerator
public RowCoderGenerator()
-
-
Method Details
-
overrideEncodingPositions
-
generate
-