Skip to content

Commit

Permalink
Avro codegen : Split builder constructor and build() if #fields > 50 (#…
Browse files Browse the repository at this point in the history
…525)

* Avro codegen : Split builder constructor if #fields > 50

* Fixed typo in javadoc

* Avro codegen : Add javadoc to Builder constructor if split

* Add compile Unit test for 2000 field record

* Codegen : split Builder.build() if number of fields > 50

* Added comments

* style update

* common blockSize for splitting methods

* fixed typo

* private modifier for Chunk methods

* Updated unit test to validate chunk methods in main class
  • Loading branch information
li-ukumar authored Dec 4, 2023
1 parent 39547a2 commit 656164b
Show file tree
Hide file tree
Showing 5 changed files with 10,271 additions and 118 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.lang.reflect.Parameter;
import java.util.ArrayList;
import java.util.Arrays;
Expand Down Expand Up @@ -1829,6 +1830,30 @@ public void testNewBuilder() throws Exception {
compareIndexedRecords(instance, builder.build());
}

@DataProvider
public static Object[][] testPrivateModifierOnChunkMethodProvider() {
return new Object[][]{{vs14.ThousandField.class}, {vs19.ThousandField.class}};
}

@Test(dataProvider = "testPrivateModifierOnChunkMethodProvider")
public <T extends IndexedRecord> void testPrivateModifierOnChunkMethod(Class<T> clazz) {

// All chunk methods in builder
List<Method> chunkMethodNames = Arrays.stream(Arrays.stream(clazz.getClasses())
.filter(internalClazz -> internalClazz.getName().equals(clazz.getName() + "$Builder"))
.collect(Collectors.toList())
.get(0)
.getDeclaredMethods()).filter(method -> method.getName().contains("Chunk")).collect(Collectors.toList());

// chunk methods from main class
chunkMethodNames.addAll(Arrays.stream(clazz.getDeclaredMethods())
.filter(method -> method.getName().contains("Chunk"))
.collect(Collectors.toList()));

Assert.assertFalse(chunkMethodNames.isEmpty());
chunkMethodNames.forEach(method -> Assert.assertTrue(Modifier.isPrivate(method.getModifiers())));
}

@BeforeClass
public void setup() {
System.setProperty("org.apache.avro.specific.use_custom_coders", "true");
Expand Down
3 changes: 3 additions & 0 deletions avro-codegen/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ plugins {
id "checkstyle"
id "jacoco"
}
test {
maxHeapSize='1g'
}

dependencies {
api project(":parser")
Expand Down
Loading

0 comments on commit 656164b

Please sign in to comment.