Skip to content

Commit

Permalink
new helper module, full avro 1.4-1.9 support (#22)
Browse files Browse the repository at this point in the history
* new helper module, full avro 1.4-1.9 support

this commit includes the following:
- new helper module build has a sub-module per major version of avro which
  compiles natively vs the target avro version. this eliminates the need
  for reflection in _most_ use cases. cases involving optional avro-compiler
  jar still rely on reflection
- helper code now implemented across all major avro versions from 1.4 to
  1.9 inclusive
- code generation support has been extended to cover above avro versions
- tests are now performed with multiple classpaths, including variants
  with and without the avro-compiler jar (on avro 1.5+)

Signed-off-by: Radai Rosenblatt <[email protected]>
  • Loading branch information
radai-rosenblatt authored Feb 20, 2020
1 parent abbe76f commit 3365e27
Show file tree
Hide file tree
Showing 199 changed files with 10,014 additions and 249 deletions.
11 changes: 7 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Avro-Util
[![Build Status](https://travis-ci.org/linkedin/avro-util.svg?branch=master)](https://travis-ci.org/linkedin/avro-util)
[![Download](https://api.bintray.com/packages/linkedin/maven/avro-util/images/download.svg)](https://bintray.com/linkedin/maven/avro-util/_latestVersion)

A collection of utilitiesto allow java projects to better work with avro.
A collection of utilities and libraries to allow java projects to better work with avro.

### Background ###

Expand All @@ -21,7 +21,7 @@ performance.

The following modules are available in this project.

## avro-migration-helper ##
## helper ##

This module provides utility functions which, when coded against, ensure
compatibility with every Avro supported version. This is achieved by offering
Expand Down Expand Up @@ -50,10 +50,13 @@ LinkedIn.

### Supported versions of Avro ###

The helper module supports avro 1.4 - 1.9 inclusive. for fastserde support:

| Version | Serialization | Deserialization | Fast Serialization | Fast Deserialization |
| -------- | ------------- | --------------- | ------------------ | -------------------- |
| Avro 1.4 | Yes | Yes | Yes | Yes |
| Avro 1.5 | ??? | ??? | No | No |
| Avro 1.6 | ??? | ??? | No | No |
| Avro 1.5 | Yes | Yes | No | No |
| Avro 1.6 | Yes | Yes | No | No |
| Avro 1.7 | Yes | Yes | Yes | Yes |
| Avro 1.8 | Yes | Yes | Yes | Yes |
| Avro 1.9 | Yes | Yes | ??? | ??? |
15 changes: 15 additions & 0 deletions avro-codegen/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
Avro Codegen
=========

This module contains utility classes for generating java classes out of avro schema (*.avsc) files

Major features include:

* the ability to reuse ("import") schemas defined in either other *.avsc files in the same
code generation scope of schemas defined by classes on the classpath when generating code,
allowing for schema reuse inside and between large projects
* the ability to generate java code for specific records that is runtime-compatible with a
wide range of avro versions, allowing to reuse the same libraries of schemas between
projects that use different versions of avro

instructions and examples TBD
1 change: 1 addition & 0 deletions avro-codegen/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

plugins {
id "java-library"
id "checkstyle"
}

dependencies {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
/*
* Copyright 2018 LinkedIn Corp.
* Licensed under the BSD 2-Clause License (the "License").
* See License in the project root for license information.
*/

package com.linkedin.avro.codegen;

class ClassifiedIssue {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
/*
* Copyright 2018 LinkedIn Corp.
* Licensed under the BSD 2-Clause License (the "License").
* See License in the project root for license information.
*/

package com.linkedin.avro.codegen;

import java.util.Map;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,21 @@
import com.linkedin.avro.compatibility.AvroVersion;
import com.linkedin.avro.compatibility.SchemaParseResult;
import com.linkedin.avro.util.TemplateUtil;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.StringJoiner;
import org.apache.avro.Schema;
import org.apache.avro.SchemaParseException;
import org.apache.avro.specific.FixedSize;
Expand All @@ -23,11 +38,9 @@
import org.apache.tools.ant.DirectoryScanner;
import org.apache.tools.ant.types.selectors.SelectorUtils;

import java.io.*;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.nio.charset.StandardCharsets;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
/*
* Copyright 2018 LinkedIn Corp.
* Licensed under the BSD 2-Clause License (the "License").
* See License in the project root for license information.
*/

package com.linkedin.avro.codegen;

import org.apache.avro.SchemaParseException;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
/*
* Copyright 2018 LinkedIn Corp.
* Licensed under the BSD 2-Clause License (the "License").
* See License in the project root for license information.
*/

package com.linkedin.avro.codegen;

enum IssueType {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
/*
* Copyright 2018 LinkedIn Corp.
* Licensed under the BSD 2-Clause License (the "License").
* See License in the project root for license information.
*/

package com.linkedin.avro.codegen;

import org.apache.avro.Schema;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
/*
* Copyright 2018 LinkedIn Corp.
* Licensed under the BSD 2-Clause License (the "License").
* See License in the project root for license information.
*/

package com.linkedin.avro.codegen;

enum SchemaSource {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,21 @@

import com.linkedin.avro.codegen.testutil.CompilerHelper;
import com.linkedin.avro.compatibility.AvroGeneratedSourceCode;
import java.io.File;
import java.lang.reflect.Method;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.Locale;
import net.openhft.compiler.CompilerUtils;
import org.apache.avro.specific.SpecificFixed;
import org.apache.avro.specific.SpecificRecord;
import org.testng.Assert;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;

import java.io.File;
import java.lang.reflect.Method;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.*;

public class CodeGeneratorTest {
private File sourceRoot;
private Path outputRoot;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,34 @@

package com.linkedin.avro.codegen.testutil;

import org.apache.commons.io.IOUtils;
import org.testng.Assert;

import javax.tools.*;
import java.io.*;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.OutputStream;
import java.net.URI;
import java.nio.charset.StandardCharsets;
import java.nio.file.*;
import java.nio.file.FileVisitResult;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.SimpleFileVisitor;
import java.nio.file.attribute.BasicFileAttributes;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import javax.tools.Diagnostic;
import javax.tools.DiagnosticListener;
import javax.tools.FileObject;
import javax.tools.ForwardingJavaFileManager;
import javax.tools.JavaCompiler;
import javax.tools.JavaFileManager;
import javax.tools.JavaFileObject;
import javax.tools.SimpleJavaFileObject;
import javax.tools.StandardJavaFileManager;
import javax.tools.ToolProvider;
import org.apache.commons.io.IOUtils;
import org.testng.Assert;

/**
* utility class for dealing with the java compiler in unit tests
Expand Down
12 changes: 12 additions & 0 deletions avro-fastserde/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
avro-fastserde
=========

This is a fork of https://github.com/RTBHOUSE/avro-fastserde

Notable features include:

* The code has been altered to support multiple major versions of avro at runtime (by using
the helper module)
* various performance improvements to array fields?

instructions and examples TBD
1 change: 1 addition & 0 deletions avro-migration-helper/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

plugins {
id "java-library"
id "checkstyle"
}

configurations {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,14 @@
import org.apache.avro.generic.GenericData;
import org.apache.avro.generic.GenericRecord;
import org.apache.avro.generic.IndexedRecord;
import org.apache.avro.io.*;
import org.apache.avro.io.Avro14Adapter;
import org.apache.avro.io.Avro17Adapter;
import org.apache.avro.io.AvroAdapter;
import org.apache.avro.io.BinaryDecoder;
import org.apache.avro.io.BinaryEncoder;
import org.apache.avro.io.Encoder;
import org.apache.avro.io.JsonDecoder;
import org.apache.avro.io.JsonEncoder;
import org.apache.avro.specific.SpecificDatumReader;
import org.apache.avro.specific.SpecificRecord;
import org.codehaus.jackson.JsonGenerator;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ static ValueType fromLiteral(String literal) {
Integer.parseInt(literal);
return INT;
} catch (NumberFormatException ignored) {

//empty
}
throw new IllegalStateException("unhandled: " + literal);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,26 @@
import com.linkedin.avro.compatibility.AvroGeneratedSourceCode;
import com.linkedin.avro.compatibility.AvroVersion;
import com.linkedin.avro.compatibility.SchemaNormalization;
import com.linkedin.avro.compatibility.SchemaParseResult;
import com.linkedin.avro.util.TemplateUtil;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.util.*;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.WeakHashMap;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import com.linkedin.avro.compatibility.SchemaParseResult;
import com.linkedin.avro.util.TemplateUtil;
import org.apache.avro.Avro14SchemaAccessHelper;
import org.apache.avro.AvroRuntimeException;
import org.apache.avro.Schema;
import org.apache.avro.Avro14SchemaAccessHelper;
import org.apache.avro.generic.GenericData;
import org.apache.avro.generic.GenericDatumReader;
import org.apache.avro.io.avro18.Avro18BufferedBinaryEncoder;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,21 @@
import com.linkedin.avro.compatibility.AvroCompatibilityHelper;
import com.linkedin.avro.compatibility.AvroGeneratedSourceCode;
import com.linkedin.avro.compatibility.AvroVersion;
import com.linkedin.avro.compatibility.SchemaParseResult;
import java.io.OutputStream;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import com.linkedin.avro.compatibility.SchemaParseResult;
import org.apache.avro.Schema;
import org.apache.avro.generic.GenericData;
import org.apache.avro.specific.SpecificData;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,27 @@
/*
* Copyright 2020 LinkedIn Corp.
* Licensed under the BSD 2-Clause License (the "License").
* See License in the project root for license information.
*/

/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.avro.io.avro18;


Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,27 @@
/*
* Copyright 2020 LinkedIn Corp.
* Licensed under the BSD 2-Clause License (the "License").
* See License in the project root for license information.
*/

/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.avro.io.avro18;

import java.io.IOException;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
/*
* Copyright 2020 LinkedIn Corp.
* Licensed under the BSD 2-Clause License (the "License").
* See License in the project root for license information.
*/

package org.apache.avro.io.avro18;

/**
Expand Down
Loading

0 comments on commit 3365e27

Please sign in to comment.