Skip to content

Commit

Permalink
"avro.java.string" support in union type for fast serializer (#70)
Browse files Browse the repository at this point in the history
* "avro.java.string" support in union type for fast serializer

* Code gen for #70
  • Loading branch information
gaojieliu authored Jul 1, 2020
1 parent 997b4fd commit 1d09b6f
Show file tree
Hide file tree
Showing 12 changed files with 429 additions and 43 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@

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

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

public class FastStringableTest_javaStringPropertyInsideUnionTest_GenericDeserializer_6238557830396401576_6238557830396401576
implements FastDeserializer<IndexedRecord>
{

private final Schema readerSchema;
private final Schema favorite_number0;
private final Schema favorite_color0;

public FastStringableTest_javaStringPropertyInsideUnionTest_GenericDeserializer_6238557830396401576_6238557830396401576(Schema readerSchema) {
this.readerSchema = readerSchema;
this.favorite_number0 = readerSchema.getField("favorite_number").schema();
this.favorite_color0 = readerSchema.getField("favorite_color").schema();
}

public IndexedRecord deserialize(IndexedRecord reuse, Decoder decoder)
throws IOException
{
return deserializeFastStringableTest_javaStringPropertyInsideUnionTest0((reuse), (decoder));
}

public IndexedRecord deserializeFastStringableTest_javaStringPropertyInsideUnionTest0(Object reuse, Decoder decoder)
throws IOException
{
IndexedRecord FastStringableTest_javaStringPropertyInsideUnionTest;
if ((((reuse)!= null)&&((reuse) instanceof IndexedRecord))&&(((IndexedRecord)(reuse)).getSchema() == readerSchema)) {
FastStringableTest_javaStringPropertyInsideUnionTest = ((IndexedRecord)(reuse));
} else {
FastStringableTest_javaStringPropertyInsideUnionTest = new org.apache.avro.generic.GenericData.Record(readerSchema);
}
if (FastStringableTest_javaStringPropertyInsideUnionTest.get(0) instanceof Utf8) {
FastStringableTest_javaStringPropertyInsideUnionTest.put(0, (decoder).readString(((Utf8) FastStringableTest_javaStringPropertyInsideUnionTest.get(0))));
} else {
FastStringableTest_javaStringPropertyInsideUnionTest.put(0, (decoder).readString(null));
}
int unionIndex0 = (decoder.readIndex());
if (unionIndex0 == 0) {
decoder.readNull();
}
if (unionIndex0 == 1) {
FastStringableTest_javaStringPropertyInsideUnionTest.put(1, (decoder.readInt()));
}
int unionIndex1 = (decoder.readIndex());
if (unionIndex1 == 0) {
decoder.readNull();
}
if (unionIndex1 == 1) {
if (FastStringableTest_javaStringPropertyInsideUnionTest.get(2) instanceof Utf8) {
FastStringableTest_javaStringPropertyInsideUnionTest.put(2, (decoder).readString(((Utf8) FastStringableTest_javaStringPropertyInsideUnionTest.get(2))));
} else {
FastStringableTest_javaStringPropertyInsideUnionTest.put(2, (decoder).readString(null));
}
}
return FastStringableTest_javaStringPropertyInsideUnionTest;
}

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

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

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

public class FastStringableTest_javaStringPropertyInsideUnionTest_GenericDeserializer_4476580127917956418_4476580127917956418
implements FastDeserializer<IndexedRecord>
{

private final Schema readerSchema;
private final Schema favorite_number0;
private final Schema favorite_color0;

public FastStringableTest_javaStringPropertyInsideUnionTest_GenericDeserializer_4476580127917956418_4476580127917956418(Schema readerSchema) {
this.readerSchema = readerSchema;
this.favorite_number0 = readerSchema.getField("favorite_number").schema();
this.favorite_color0 = readerSchema.getField("favorite_color").schema();
}

public IndexedRecord deserialize(IndexedRecord reuse, Decoder decoder)
throws IOException
{
return deserializeFastStringableTest_javaStringPropertyInsideUnionTest0((reuse), (decoder));
}

public IndexedRecord deserializeFastStringableTest_javaStringPropertyInsideUnionTest0(Object reuse, Decoder decoder)
throws IOException
{
IndexedRecord FastStringableTest_javaStringPropertyInsideUnionTest;
if ((((reuse)!= null)&&((reuse) instanceof IndexedRecord))&&(((IndexedRecord)(reuse)).getSchema() == readerSchema)) {
FastStringableTest_javaStringPropertyInsideUnionTest = ((IndexedRecord)(reuse));
} else {
FastStringableTest_javaStringPropertyInsideUnionTest = new org.apache.avro.generic.GenericData.Record(readerSchema);
}
FastStringableTest_javaStringPropertyInsideUnionTest.put(0, (decoder).readString());
int unionIndex0 = (decoder.readIndex());
if (unionIndex0 == 0) {
decoder.readNull();
}
if (unionIndex0 == 1) {
FastStringableTest_javaStringPropertyInsideUnionTest.put(1, (decoder.readInt()));
}
int unionIndex1 = (decoder.readIndex());
if (unionIndex1 == 0) {
decoder.readNull();
}
if (unionIndex1 == 1) {
FastStringableTest_javaStringPropertyInsideUnionTest.put(2, (decoder).readString());
}
return FastStringableTest_javaStringPropertyInsideUnionTest;
}

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

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

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

public class FastStringableTest_javaStringPropertyInsideUnionTest_GenericDeserializer_4476580127917956418_4476580127917956418
implements FastDeserializer<IndexedRecord>
{

private final Schema readerSchema;
private final Schema favorite_number0;
private final Schema favorite_color0;

public FastStringableTest_javaStringPropertyInsideUnionTest_GenericDeserializer_4476580127917956418_4476580127917956418(Schema readerSchema) {
this.readerSchema = readerSchema;
this.favorite_number0 = readerSchema.getField("favorite_number").schema();
this.favorite_color0 = readerSchema.getField("favorite_color").schema();
}

public IndexedRecord deserialize(IndexedRecord reuse, Decoder decoder)
throws IOException
{
return deserializeFastStringableTest_javaStringPropertyInsideUnionTest0((reuse), (decoder));
}

public IndexedRecord deserializeFastStringableTest_javaStringPropertyInsideUnionTest0(Object reuse, Decoder decoder)
throws IOException
{
IndexedRecord FastStringableTest_javaStringPropertyInsideUnionTest;
if ((((reuse)!= null)&&((reuse) instanceof IndexedRecord))&&(((IndexedRecord)(reuse)).getSchema() == readerSchema)) {
FastStringableTest_javaStringPropertyInsideUnionTest = ((IndexedRecord)(reuse));
} else {
FastStringableTest_javaStringPropertyInsideUnionTest = new org.apache.avro.generic.GenericData.Record(readerSchema);
}
FastStringableTest_javaStringPropertyInsideUnionTest.put(0, (decoder).readString());
int unionIndex0 = (decoder.readIndex());
if (unionIndex0 == 0) {
decoder.readNull();
}
if (unionIndex0 == 1) {
FastStringableTest_javaStringPropertyInsideUnionTest.put(1, (decoder.readInt()));
}
int unionIndex1 = (decoder.readIndex());
if (unionIndex1 == 0) {
decoder.readNull();
}
if (unionIndex1 == 1) {
FastStringableTest_javaStringPropertyInsideUnionTest.put(2, (decoder).readString());
}
return FastStringableTest_javaStringPropertyInsideUnionTest;
}

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

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

import java.io.IOException;
import com.linkedin.avro.fastserde.FastSerializer;
import org.apache.avro.generic.IndexedRecord;
import org.apache.avro.io.Encoder;
import org.apache.avro.util.Utf8;

public class FastStringableTest_javaStringPropertyInsideUnionTest_GenericSerializer_6238557830396401576
implements FastSerializer<IndexedRecord>
{


public void serialize(IndexedRecord data, Encoder encoder)
throws IOException
{
serializeFastStringableTest_javaStringPropertyInsideUnionTest0(data, (encoder));
}

@SuppressWarnings("unchecked")
public void serializeFastStringableTest_javaStringPropertyInsideUnionTest0(IndexedRecord data, Encoder encoder)
throws IOException
{
if (data.get(0) instanceof Utf8) {
(encoder).writeString(((Utf8) data.get(0)));
} else {
(encoder).writeString(data.get(0).toString());
}
Integer favorite_number0 = ((Integer) data.get(1));
if (favorite_number0 == null) {
(encoder).writeIndex(0);
(encoder).writeNull();
} else {
if (favorite_number0 instanceof Integer) {
(encoder).writeIndex(1);
(encoder).writeInt(((Integer) favorite_number0));
}
}
CharSequence favorite_color0 = ((CharSequence) data.get(2));
if (favorite_color0 == null) {
(encoder).writeIndex(0);
(encoder).writeNull();
} else {
if (favorite_color0 instanceof CharSequence) {
(encoder).writeIndex(1);
if (favorite_color0 instanceof Utf8) {
(encoder).writeString(((Utf8) favorite_color0));
} else {
(encoder).writeString(favorite_color0 .toString());
}
}
}
}

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

package com.linkedin.avro.fastserde.generated.serialization.AVRO_1_7;

import java.io.IOException;
import com.linkedin.avro.fastserde.FastSerializer;
import org.apache.avro.generic.IndexedRecord;
import org.apache.avro.io.Encoder;
import org.apache.avro.util.Utf8;

public class FastStringableTest_javaStringPropertyInsideUnionTest_GenericSerializer_4476580127917956418
implements FastSerializer<IndexedRecord>
{


public void serialize(IndexedRecord data, Encoder encoder)
throws IOException
{
serializeFastStringableTest_javaStringPropertyInsideUnionTest0(data, (encoder));
}

@SuppressWarnings("unchecked")
public void serializeFastStringableTest_javaStringPropertyInsideUnionTest0(IndexedRecord data, Encoder encoder)
throws IOException
{
if (data.get(0) instanceof Utf8) {
(encoder).writeString(((Utf8) data.get(0)));
} else {
(encoder).writeString(data.get(0).toString());
}
Integer favorite_number0 = ((Integer) data.get(1));
if (favorite_number0 == null) {
(encoder).writeIndex(0);
(encoder).writeNull();
} else {
if (favorite_number0 instanceof Integer) {
(encoder).writeIndex(1);
(encoder).writeInt(((Integer) favorite_number0));
}
}
CharSequence favorite_color0 = ((CharSequence) data.get(2));
if (favorite_color0 == null) {
(encoder).writeIndex(0);
(encoder).writeNull();
} else {
if (favorite_color0 instanceof CharSequence) {
(encoder).writeIndex(1);
if (favorite_color0 instanceof Utf8) {
(encoder).writeString(((Utf8) favorite_color0));
} else {
(encoder).writeString(favorite_color0 .toString());
}
}
}
}

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

package com.linkedin.avro.fastserde.generated.serialization.AVRO_1_8;

import java.io.IOException;
import com.linkedin.avro.fastserde.FastSerializer;
import org.apache.avro.generic.IndexedRecord;
import org.apache.avro.io.Encoder;
import org.apache.avro.util.Utf8;

public class FastStringableTest_javaStringPropertyInsideUnionTest_GenericSerializer_4476580127917956418
implements FastSerializer<IndexedRecord>
{


public void serialize(IndexedRecord data, Encoder encoder)
throws IOException
{
serializeFastStringableTest_javaStringPropertyInsideUnionTest0(data, (encoder));
}

@SuppressWarnings("unchecked")
public void serializeFastStringableTest_javaStringPropertyInsideUnionTest0(IndexedRecord data, Encoder encoder)
throws IOException
{
if (data.get(0) instanceof Utf8) {
(encoder).writeString(((Utf8) data.get(0)));
} else {
(encoder).writeString(data.get(0).toString());
}
Integer favorite_number0 = ((Integer) data.get(1));
if (favorite_number0 == null) {
(encoder).writeIndex(0);
(encoder).writeNull();
} else {
if (favorite_number0 instanceof Integer) {
(encoder).writeIndex(1);
(encoder).writeInt(((Integer) favorite_number0));
}
}
CharSequence favorite_color0 = ((CharSequence) data.get(2));
if (favorite_color0 == null) {
(encoder).writeIndex(0);
(encoder).writeNull();
} else {
if (favorite_color0 instanceof CharSequence) {
(encoder).writeIndex(1);
if (favorite_color0 instanceof Utf8) {
(encoder).writeString(((Utf8) favorite_color0));
} else {
(encoder).writeString(favorite_color0 .toString());
}
}
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public abstract class FastDeserializerGeneratorBase<T> extends FastSerdeBase {

FastDeserializerGeneratorBase(boolean useGenericTypes, Schema writer, Schema reader, File destination, ClassLoader classLoader,
String compileClassPath) {
super("deserialization", useGenericTypes, Utf8.class, destination, classLoader, compileClassPath);
super("deserialization", useGenericTypes, Utf8.class, destination, classLoader, compileClassPath, false);
this.writer = writer;
this.reader = reader;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ public abstract class FastSerdeBase {
protected JDefinedClass generatedClass;

public FastSerdeBase(String description, boolean useGenericTypes, Class defaultStringClass, File destination, ClassLoader classLoader,
String compileClassPath) {
String compileClassPath, boolean isForSerializer) {
this.useGenericTypes = useGenericTypes;
this.schemaAssistant = new SchemaAssistant(codeModel, useGenericTypes, defaultStringClass);
this.schemaAssistant = new SchemaAssistant(codeModel, useGenericTypes, defaultStringClass, isForSerializer);
this.destination = destination;
this.classLoader = classLoader;
this.compileClassPath = (null == compileClassPath ? "" : compileClassPath);
Expand Down Expand Up @@ -129,11 +129,11 @@ protected Class compileClass(final String className, Set<String> knownUsedFullyQ
*/
compileResult = compiler.run(null, null, null, "-cp", compileClassPathForCurrentFile, filePath, "-XDuseUnsharedTable");
} catch (Exception e) {
throw new FastSerdeGeneratorException("Unable to compile:" + className, e);
throw new FastSerdeGeneratorException("Unable to compile:" + className + " from source file: " + filePath, e);
}

if (compileResult != 0) {
throw new FastSerdeGeneratorException("Unable to compile:" + className);
throw new FastSerdeGeneratorException("Unable to compile:" + className + " from source file: " + filePath);
}

return classLoader.loadClass(generatedPackageName + "." + className);
Expand Down
Loading

0 comments on commit 1d09b6f

Please sign in to comment.