@@ -30,12 +30,12 @@ public class FallbackValuesWriter<I extends ValuesWriter & RequiresFallback, F e
3030
3131 public static <I extends ValuesWriter & RequiresFallback , F extends ValuesWriter > FallbackValuesWriter <I , F > of (
3232 I initialWriter , F fallBackWriter ) {
33- return new FallbackValuesWriter <>(initialWriter , fallBackWriter , /*checkAfterBytes =*/ 0 );
33+ return new FallbackValuesWriter <>(initialWriter , fallBackWriter , /*dictionaryCheckThresholdRawSizeBytes =*/ 0 );
3434 }
3535
3636 public static <I extends ValuesWriter & RequiresFallback , F extends ValuesWriter > FallbackValuesWriter <I , F > of (
37- I initialWriter , F fallBackWriter , long checkAfterBytes ) {
38- return new FallbackValuesWriter <>(initialWriter , fallBackWriter , checkAfterBytes );
37+ I initialWriter , F fallBackWriter , long dictionaryCheckThresholdRawSizeBytes ) {
38+ return new FallbackValuesWriter <>(initialWriter , fallBackWriter , dictionaryCheckThresholdRawSizeBytes );
3939 }
4040
4141 /**
@@ -49,9 +49,11 @@ public static <I extends ValuesWriter & RequiresFallback, F extends ValuesWriter
4949
5050 private boolean fellBackAlready = false ;
5151 private boolean compressionChecked = false ;
52- private final long checkAfterBytes ;
52+ private final long dictionaryCheckThresholdRawSizeBytes ;
5353 /** Accumulates raw bytes across pages (only reset in resetDictionary) so the
54- * threshold check works even when individual pages are smaller than checkAfterBytes. */
54+ * threshold check works even when individual pages are smaller than the threshold.
55+ * Overflow is not a concern: a long would require writing over 9.2 exabytes to a single
56+ * column chunk, which is physically impossible. */
5557 private long cumulativeRawBytes = 0 ;
5658
5759 /**
@@ -68,15 +70,15 @@ public static <I extends ValuesWriter & RequiresFallback, F extends ValuesWriter
6870 private long rawDataByteSize = 0 ;
6971
7072 public FallbackValuesWriter (I initialWriter , F fallBackWriter ) {
71- this (initialWriter , fallBackWriter , /*checkAfterBytes =*/ 0 );
73+ this (initialWriter , fallBackWriter , /*dictionaryCheckThresholdRawSizeBytes =*/ 0 );
7274 }
7375
74- public FallbackValuesWriter (I initialWriter , F fallBackWriter , long checkAfterBytes ) {
76+ public FallbackValuesWriter (I initialWriter , F fallBackWriter , long dictionaryCheckThresholdRawSizeBytes ) {
7577 super ();
7678 this .initialWriter = initialWriter ;
7779 this .fallBackWriter = fallBackWriter ;
7880 this .currentWriter = initialWriter ;
79- this .checkAfterBytes = checkAfterBytes ;
81+ this .dictionaryCheckThresholdRawSizeBytes = dictionaryCheckThresholdRawSizeBytes ;
8082 }
8183
8284 @ Override
@@ -89,8 +91,12 @@ public long getBufferedSize() {
8991
9092 @ Override
9193 public BytesInput getBytes () {
92- cumulativeRawBytes += rawDataByteSize ;
93- if (!fellBackAlready && !compressionChecked && cumulativeRawBytes >= checkAfterBytes ) {
94+ try {
95+ cumulativeRawBytes = Math .addExact (cumulativeRawBytes , rawDataByteSize );
96+ } catch (ArithmeticException e ) {
97+ // overflow, keep the previous value
98+ }
99+ if (!fellBackAlready && !compressionChecked && cumulativeRawBytes >= dictionaryCheckThresholdRawSizeBytes ) {
94100 compressionChecked = true ;
95101 BytesInput bytes = initialWriter .getBytes ();
96102 if (!initialWriter .isCompressionSatisfying (rawDataByteSize , bytes .size ())) {
0 commit comments