rdblue commented on a change in pull request #828:
URL: https://github.com/apache/iceberg/pull/828#discussion_r434842209
##########
File path: spark/src/test/java/org/apache/iceberg/spark/data/RandomData.java
##########
@@ -442,4 +474,226 @@ private static BigInteger randomUnscaled(int precision,
Random random) {
return new BigInteger(sb.toString());
}
+
+ private static class DictionaryEncodedDataGenerator extends
RandomDataGenerator {
+
+ private DictionaryEncodedDataGenerator(Schema schema, long seed) {
+ super(schema, seed);
+ }
+
+ @Override
+ public Object primitive(Type.PrimitiveType primitive) {
+ Object result = generateDictionaryEncodablePrimitive(primitive, random);
+ return super.getPrimitive(primitive, result);
+ }
+
+ @SuppressWarnings("checkstyle:CyclomaticComplexity")
+ private static Object
generateDictionaryEncodablePrimitive(Type.PrimitiveType primitive, Random
random) {
+ // 3 choices
+ int choice = random.nextInt(3);
+ switch (primitive.typeId()) {
+ case BOOLEAN:
+ return true; // doesn't really matter for booleans since they are
not dictionary encoded
+
+ case INTEGER:
+ switch (choice) {
+ case 0:
+ return 0;
+ case 1:
+ return 1;
+ case 2:
+ return 2;
+ }
+
+ case LONG:
+ switch (choice) {
+ case 0:
+ return 0L;
+ case 1:
+ return 1L;
+ case 2:
+ return 2L;
+ }
+
+ case FLOAT:
+ switch (choice) {
+ case 0:
+ return 0.0f;
+ case 1:
+ return 1.0f;
+ case 2:
+ return 2.0f;
+ }
+
+ case DOUBLE:
+ switch (choice) {
+ case 0:
+ return 0.0d;
+ case 1:
+ return 1.0d;
+ case 2:
+ return 2.0d;
+ }
+
+ case DATE:
+ switch (choice) {
+ case 0:
+ return 0;
+ case 1:
+ return 1;
+ case 2:
+ return 2;
+ }
+
+ case TIME:
+ switch (choice) {
+ case 0:
+ return 0L;
+ case 1:
+ return 1L;
+ case 2:
+ return 2L;
+ }
+
+ case TIMESTAMP:
+ switch (choice) {
+ case 0:
+ return 0L;
+ case 1:
+ return 1L;
+ case 2:
+ return 2L;
+ }
+
+ case STRING:
+ switch (choice) {
+ case 0:
+ return UTF8String.fromString("0");
+ case 1:
+ return UTF8String.fromString("1");
+ case 2:
+ return UTF8String.fromString("2");
+ }
+
+ case FIXED:
+ byte[] fixed = new byte[((Types.FixedType) primitive).length()];
+ switch (choice) {
+ case 0:
+ fixed[0] = 0;
Review comment:
Can we use `Arrays.fill` instead of leaving some bytes uninitialized?
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]