Skip to content

Commit

Permalink
Checking in samples of fast-avro code gen, to ease future reviews.
Browse files Browse the repository at this point in the history
The goal of this change is to have the output of the fast-avro code gen
under version control, so that it can be diffed easily during pull
requests, and so that historical changes are easier to track. Given the
complexity of analyzing  meta-code changes, the hope is that this will
allow a more streamlined and robust workflow.

In order to facilitate this, the main code is changed as such:

- The algorithm for naming the generated classes has been tweaked, so
  that it's more easily recognizable. In particular, collection types
  now specify the type of their element in the class name, e.g.
  - Array_of_record
  - Array_of_LONG
  - Map_of_UNION
- The package name for generated classes is also tweaked, such that it
  includes the Avro version in it, e.g.
  - com/linkedin/avro/fastserde/generated/deserialization/AVRO_1_4
  - com/linkedin/avro/fastserde/generated/serialization/AVRO_1_8

Furthermore, the build and tests are more significantly altered:

- A new src directory called codegen is created. It is confgured as a
  source set in the build with proper dependencies, in order to make
  the generated code easy to navigate in the IDE.
- FastGenericDeserializerGeneratorTest and FGSerializerGeneratorTest
  are modified as such:
  - Instead of using a temporary directory for generated serde classes,
    they now write to the new codegen directory.
  - The names of all top level record schemas is changed to include the
    class and function name, in order to facilitate the identification
    of which serde class maps to which test. This is figured out
    automatically via a new utility function in FastSerdeTestsSupport.
- FastGenericDeserializerGeneratorTest now includes 4 new primitive
  array tests which were previously untested: boolean, double, int and
  long.
- The avro-fastserde build now deletes the content of the codegen
  directory before running, to ensure that if test schemas change,
  older serde classes that aren't used anymore will get purged. At the
  end of the build, .class files are also deleted.
  • Loading branch information
FelixGV committed Jun 4, 2020
1 parent 6c3fa71 commit f56befd
Show file tree
Hide file tree
Showing 113 changed files with 10,747 additions and 113 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ build/

#temp artifacts
avro_tools/
generated/
avro-fastserde/src/test/java/com/linkedin/avro/fastserde/generated/
*.class

#IDEA artifacts
out/
Expand Down
20 changes: 19 additions & 1 deletion avro-fastserde/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ jmh {
}
}

sourceSets {
codegen
}

dependencies {
compile project(":helper:helper")

Expand Down Expand Up @@ -83,6 +87,11 @@ dependencies {
avro18 ("org.apache.avro:avro-compiler:1.8.2") {
exclude group: "org.slf4j"
}

codegenCompile ("org.apache.avro:avro-compiler:1.8.2") {
exclude group: "org.slf4j"
}
codegenCompile project(":avro-fastserde")
}

compileJmhJava {
Expand Down Expand Up @@ -120,7 +129,16 @@ test {
testLogging.showStandardStreams = true
}

build.dependsOn testAvro14, testAvro17, testAvro18
task cleanGeneratedClassFiles(type: Delete) {
delete fileTree(dir: 'src/codegen', include: '**/*.class')
}

task cleanAllGeneratedFiles(type: Delete) {
delete fileTree(dir: 'src/codegen', include: '**/*.java')
}

build.dependsOn cleanAllGeneratedFiles, testAvro14, testAvro17, testAvro18
build.finalizedBy cleanGeneratedClassFiles

task generateAvroClasses14(type:Exec) {
commandLine "./regenerate_avro.sh"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@

package com.linkedin.avro.fastserde.generated.deserialization.AVRO_1_4;

import java.io.IOException;
import java.util.List;
import com.linkedin.avro.fastserde.FastDeserializer;
import org.apache.avro.Schema;
import org.apache.avro.generic.GenericArray;
import org.apache.avro.io.Decoder;

public class Array_of_BOOLEAN_GenericDeserializer_5988037297456147388_5988037297456147388
implements FastDeserializer<List<Boolean>>
{

private final Schema readerSchema;

public Array_of_BOOLEAN_GenericDeserializer_5988037297456147388_5988037297456147388(Schema readerSchema) {
this.readerSchema = readerSchema;
}

public List<Boolean> deserialize(List<Boolean> reuse, Decoder decoder)
throws IOException
{
List<Boolean> array738 = null;
long chunkLen739 = (decoder.readArrayStart());
if (chunkLen739 > 0) {
List<Boolean> arrayReuse740 = null;
if ((reuse) instanceof List) {
arrayReuse740 = ((List)(reuse));
}
if (arrayReuse740 != (null)) {
arrayReuse740 .clear();
array738 = arrayReuse740;
} else {
array738 = new org.apache.avro.generic.GenericData.Array<Boolean>(((int) chunkLen739), readerSchema);
}
do {
for (int counter741 = 0; (counter741 <chunkLen739); counter741 ++) {
Object arrayArrayElementReuseVar742 = null;
if ((reuse) instanceof GenericArray) {
arrayArrayElementReuseVar742 = ((GenericArray)(reuse)).peek();
}
array738 .add((decoder.readBoolean()));
}
chunkLen739 = (decoder.arrayNext());
} while (chunkLen739 > 0);
} else {
array738 = new org.apache.avro.generic.GenericData.Array<Boolean>(0, readerSchema);
}
return array738;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@

package com.linkedin.avro.fastserde.generated.deserialization.AVRO_1_4;

import java.io.IOException;
import java.util.List;
import com.linkedin.avro.fastserde.FastDeserializer;
import org.apache.avro.Schema;
import org.apache.avro.generic.GenericArray;
import org.apache.avro.io.Decoder;

public class Array_of_DOUBLE_GenericDeserializer_6064316435611861740_6064316435611861740
implements FastDeserializer<List<Double>>
{

private final Schema readerSchema;

public Array_of_DOUBLE_GenericDeserializer_6064316435611861740_6064316435611861740(Schema readerSchema) {
this.readerSchema = readerSchema;
}

public List<Double> deserialize(List<Double> reuse, Decoder decoder)
throws IOException
{
List<Double> array743 = null;
long chunkLen744 = (decoder.readArrayStart());
if (chunkLen744 > 0) {
List<Double> arrayReuse745 = null;
if ((reuse) instanceof List) {
arrayReuse745 = ((List)(reuse));
}
if (arrayReuse745 != (null)) {
arrayReuse745 .clear();
array743 = arrayReuse745;
} else {
array743 = new org.apache.avro.generic.GenericData.Array<Double>(((int) chunkLen744), readerSchema);
}
do {
for (int counter746 = 0; (counter746 <chunkLen744); counter746 ++) {
Object arrayArrayElementReuseVar747 = null;
if ((reuse) instanceof GenericArray) {
arrayArrayElementReuseVar747 = ((GenericArray)(reuse)).peek();
}
array743 .add((decoder.readDouble()));
}
chunkLen744 = (decoder.arrayNext());
} while (chunkLen744 > 0);
} else {
array743 = new org.apache.avro.generic.GenericData.Array<Double>(0, readerSchema);
}
return array743;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@

package com.linkedin.avro.fastserde.generated.deserialization.AVRO_1_4;

import java.io.IOException;
import java.util.List;
import com.linkedin.avro.fastserde.ByteBufferBackedPrimitiveFloatList;
import com.linkedin.avro.fastserde.FastDeserializer;
import org.apache.avro.Schema;
import org.apache.avro.io.Decoder;

public class Array_of_FLOAT_GenericDeserializer_7282396011446356583_7282396011446356583
implements FastDeserializer<List<Float>>
{

private final Schema readerSchema;

public Array_of_FLOAT_GenericDeserializer_7282396011446356583_7282396011446356583(Schema readerSchema) {
this.readerSchema = readerSchema;
}

public List<Float> deserialize(List<Float> reuse, Decoder decoder)
throws IOException
{
List<Float> array748 = null;
array748 = ((List<Float> ) ByteBufferBackedPrimitiveFloatList.readPrimitiveFloatArray((reuse), (decoder)));
return array748;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@

package com.linkedin.avro.fastserde.generated.deserialization.AVRO_1_4;

import java.io.IOException;
import java.util.List;
import com.linkedin.avro.fastserde.FastDeserializer;
import org.apache.avro.Schema;
import org.apache.avro.generic.GenericArray;
import org.apache.avro.io.Decoder;

public class Array_of_INT_GenericDeserializer_3343716480540445685_3343716480540445685
implements FastDeserializer<List<Integer>>
{

private final Schema readerSchema;

public Array_of_INT_GenericDeserializer_3343716480540445685_3343716480540445685(Schema readerSchema) {
this.readerSchema = readerSchema;
}

public List<Integer> deserialize(List<Integer> reuse, Decoder decoder)
throws IOException
{
List<Integer> array749 = null;
long chunkLen750 = (decoder.readArrayStart());
if (chunkLen750 > 0) {
List<Integer> arrayReuse751 = null;
if ((reuse) instanceof List) {
arrayReuse751 = ((List)(reuse));
}
if (arrayReuse751 != (null)) {
arrayReuse751 .clear();
array749 = arrayReuse751;
} else {
array749 = new org.apache.avro.generic.GenericData.Array<Integer>(((int) chunkLen750), readerSchema);
}
do {
for (int counter752 = 0; (counter752 <chunkLen750); counter752 ++) {
Object arrayArrayElementReuseVar753 = null;
if ((reuse) instanceof GenericArray) {
arrayArrayElementReuseVar753 = ((GenericArray)(reuse)).peek();
}
array749 .add((decoder.readInt()));
}
chunkLen750 = (decoder.arrayNext());
} while (chunkLen750 > 0);
} else {
array749 = new org.apache.avro.generic.GenericData.Array<Integer>(0, readerSchema);
}
return array749;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@

package com.linkedin.avro.fastserde.generated.deserialization.AVRO_1_4;

import java.io.IOException;
import java.util.List;
import com.linkedin.avro.fastserde.FastDeserializer;
import org.apache.avro.Schema;
import org.apache.avro.generic.GenericArray;
import org.apache.avro.io.Decoder;

public class Array_of_LONG_GenericDeserializer_2055015354772118358_2055015354772118358
implements FastDeserializer<List<Long>>
{

private final Schema readerSchema;

public Array_of_LONG_GenericDeserializer_2055015354772118358_2055015354772118358(Schema readerSchema) {
this.readerSchema = readerSchema;
}

public List<Long> deserialize(List<Long> reuse, Decoder decoder)
throws IOException
{
List<Long> array754 = null;
long chunkLen755 = (decoder.readArrayStart());
if (chunkLen755 > 0) {
List<Long> arrayReuse756 = null;
if ((reuse) instanceof List) {
arrayReuse756 = ((List)(reuse));
}
if (arrayReuse756 != (null)) {
arrayReuse756 .clear();
array754 = arrayReuse756;
} else {
array754 = new org.apache.avro.generic.GenericData.Array<Long>(((int) chunkLen755), readerSchema);
}
do {
for (int counter757 = 0; (counter757 <chunkLen755); counter757 ++) {
Object arrayArrayElementReuseVar758 = null;
if ((reuse) instanceof GenericArray) {
arrayArrayElementReuseVar758 = ((GenericArray)(reuse)).peek();
}
array754 .add((decoder.readLong()));
}
chunkLen755 = (decoder.arrayNext());
} while (chunkLen755 > 0);
} else {
array754 = new org.apache.avro.generic.GenericData.Array<Long>(0, readerSchema);
}
return array754;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@

package com.linkedin.avro.fastserde.generated.deserialization.AVRO_1_4;

import java.io.IOException;
import java.util.List;
import com.linkedin.avro.fastserde.FastDeserializer;
import org.apache.avro.Schema;
import org.apache.avro.generic.GenericArray;
import org.apache.avro.generic.IndexedRecord;
import org.apache.avro.io.Decoder;
import org.apache.avro.util.Utf8;

public class Array_of_UNION_GenericDeserializer_585074122056792963_585074122056792963
implements FastDeserializer<List<IndexedRecord>>
{

private final Schema readerSchema;
private final Schema arrayArrayElemSchema772;
private final Schema arrayElemOptionSchema775;
private final Schema field777;

public Array_of_UNION_GenericDeserializer_585074122056792963_585074122056792963(Schema readerSchema) {
this.readerSchema = readerSchema;
this.arrayArrayElemSchema772 = readerSchema.getElementType();
this.arrayElemOptionSchema775 = arrayArrayElemSchema772 .getTypes().get(1);
this.field777 = arrayElemOptionSchema775 .getField("field").schema();
}

public List<IndexedRecord> deserialize(List<IndexedRecord> reuse, Decoder decoder)
throws IOException
{
List<IndexedRecord> array768 = null;
long chunkLen769 = (decoder.readArrayStart());
if (chunkLen769 > 0) {
List<IndexedRecord> arrayReuse770 = null;
if ((reuse) instanceof List) {
arrayReuse770 = ((List)(reuse));
}
if (arrayReuse770 != (null)) {
arrayReuse770 .clear();
array768 = arrayReuse770;
} else {
array768 = new org.apache.avro.generic.GenericData.Array<IndexedRecord>(((int) chunkLen769), readerSchema);
}
do {
for (int counter771 = 0; (counter771 <chunkLen769); counter771 ++) {
Object arrayArrayElementReuseVar773 = null;
if ((reuse) instanceof GenericArray) {
arrayArrayElementReuseVar773 = ((GenericArray)(reuse)).peek();
}
int unionIndex774 = (decoder.readIndex());
if (unionIndex774 == 0) {
decoder.readNull();
}
if (unionIndex774 == 1) {
array768 .add(deserializerecord776(arrayArrayElementReuseVar773, (decoder)));
}
}
chunkLen769 = (decoder.arrayNext());
} while (chunkLen769 > 0);
} else {
array768 = new org.apache.avro.generic.GenericData.Array<IndexedRecord>(0, readerSchema);
}
return array768;
}

public IndexedRecord deserializerecord776(Object reuse, Decoder decoder)
throws IOException
{
IndexedRecord record;
if ((((reuse)!= null)&&((reuse) instanceof IndexedRecord))&&(((IndexedRecord)(reuse)).getSchema() == arrayElemOptionSchema775)) {
record = ((IndexedRecord)(reuse));
} else {
record = new org.apache.avro.generic.GenericData.Record(arrayElemOptionSchema775);
}
int unionIndex778 = (decoder.readIndex());
if (unionIndex778 == 0) {
decoder.readNull();
}
if (unionIndex778 == 1) {
if (record.get(0) instanceof Utf8) {
record.put(0, (decoder).readString(((Utf8) record.get(0))));
} else {
record.put(0, (decoder).readString(null));
}
}
return record;
}

}
Loading

0 comments on commit f56befd

Please sign in to comment.