From 87994979076e69e61a46b74b7541b72fd5473d7a Mon Sep 17 00:00:00 2001 From: yuzelin Date: Sat, 3 Aug 2024 17:05:10 +0800 Subject: [PATCH] refactor --- .../parquet/reader/NestedPositionUtil.java | 41 +++++-------------- 1 file changed, 11 insertions(+), 30 deletions(-) diff --git a/paimon-format/src/main/java/org/apache/paimon/format/parquet/reader/NestedPositionUtil.java b/paimon-format/src/main/java/org/apache/paimon/format/parquet/reader/NestedPositionUtil.java index 62338278512a..9757b94c7583 100644 --- a/paimon-format/src/main/java/org/apache/paimon/format/parquet/reader/NestedPositionUtil.java +++ b/paimon-format/src/main/java/org/apache/paimon/format/parquet/reader/NestedPositionUtil.java @@ -24,8 +24,6 @@ import org.apache.paimon.utils.BooleanArrayList; import org.apache.paimon.utils.LongArrayList; -import java.util.Arrays; - import static java.lang.String.format; /** Utils to calculate nested type position. */ @@ -108,42 +106,29 @@ public static CollectionPosition calculateCollectionOffsets( i < definitionLevels.length; i = getNextCollectionStartIndex(repetitionLevels, collectionRepetitionLevel, i)) { if (definitionLevels[i] >= collectionDefinitionLevel - 1) { - valueCount++; - - boolean isNull = - isOptionalFieldValueNull(definitionLevels[i], collectionDefinitionLevel); - if (isNull) { - nullCollectionFlags.add(true); - nullValuesCount++; - // 1. don't increase offset for null values - // 2. offsets and emptyCollectionFlags are meaningless for null values, but they - // must be set at each index for calculating lengths later - offsets.add(offset); - emptyCollectionFlags.add(false); - continue; - } - - nullCollectionFlags.add(false); // definitionLevels[i] > collectionDefinitionLevel => Collection is defined and not // empty // definitionLevels[i] == collectionDefinitionLevel => Collection is defined but // empty + // definitionLevels[i] == maxDefinitionLevel - 1 => Collection is defined but null if (definitionLevels[i] > collectionDefinitionLevel) { + nullCollectionFlags.add(false); emptyCollectionFlags.add(false); offset += getCollectionSize(repetitionLevels, collectionRepetitionLevel, i + 1); } else if (definitionLevels[i] == collectionDefinitionLevel) { - // don't increase offset for empty values + nullCollectionFlags.add(false); emptyCollectionFlags.add(true); + // don't increase offset for empty values } else { - throw new IllegalStateException( - String.format( - "This case should be handled as null value. " - + "index: %d, definitionLevels: %s, collectionDefinitionLevel: %s.", - i, - Arrays.toString(definitionLevels), - collectionDefinitionLevel)); + nullCollectionFlags.add(true); + nullValuesCount++; + // 1. don't increase offset for null values + // 2. offsets and emptyCollectionFlags are meaningless for null values, but they + // must be set at each index for calculating lengths later + emptyCollectionFlags.add(false); } offsets.add(offset); + valueCount++; } // else when definitionLevels[i] < collectionDefinitionLevel - 1, it means the // collection is not defined, just ignore it @@ -157,10 +142,6 @@ public static CollectionPosition calculateCollectionOffsets( nullCollectionFlags.toArray(), offsetsArray, length, valueCount); } - public static boolean isOptionalFieldValueNull(int definitionLevel, int maxDefinitionLevel) { - return definitionLevel == maxDefinitionLevel - 1; - } - public static long[] calculateLengthByOffsets( boolean[] collectionIsEmpty, long[] arrayOffsets) { LongArrayList lengthList = new LongArrayList(arrayOffsets.length);