53
53
public class AdaptiveDeltaFloatingCodec extends AdaptiveCodec {
54
54
55
55
private Double factor ;
56
+ private float floatFactor ;
56
57
private long max ;
57
58
58
59
public static ColumnPageCodec newInstance (DataType srcDataType , DataType targetDataType ,
@@ -65,6 +66,7 @@ public AdaptiveDeltaFloatingCodec(DataType srcDataType, DataType targetDataType,
65
66
SimpleStatsResult stats , boolean isInvertedIndex ) {
66
67
super (srcDataType , targetDataType , stats , isInvertedIndex );
67
68
this .factor = Math .pow (10 , stats .getDecimalCount ());
69
+ floatFactor = factor .floatValue ();
68
70
if (srcDataType == DataTypes .FLOAT ) {
69
71
this .max =
70
72
(long ) ((long ) Math .pow (10 , stats .getDecimalCount ()) * ((float ) stats .getMax ()));
@@ -185,13 +187,15 @@ public void encode(int rowId, long value) {
185
187
@ Override
186
188
public void encode (int rowId , float value ) {
187
189
if (targetDataType .equals (DataTypes .BYTE )) {
188
- encodedPage .putByte (rowId , (byte ) (max - (value * factor )));
190
+ encodedPage .putByte (rowId , (byte ) (max - (value * floatFactor )));
189
191
} else if (targetDataType .equals (DataTypes .SHORT )) {
190
- encodedPage .putShort (rowId , (short ) (max - (value * factor )));
192
+ encodedPage .putShort (rowId , (short ) (max - (value * floatFactor )));
191
193
} else if (targetDataType .equals (DataTypes .SHORT_INT )) {
192
- encodedPage .putShortInt (rowId , (int ) (max - (value * factor )));
194
+ encodedPage .putShortInt (rowId , (int ) (max - (value * floatFactor )));
193
195
} else if (targetDataType .equals (DataTypes .INT )) {
194
- encodedPage .putInt (rowId , (int ) (max - (value * factor )));
196
+ encodedPage .putInt (rowId , (int ) (max - (value * floatFactor )));
197
+ } else if (targetDataType .equals (DataTypes .FLOAT )) {
198
+ encodedPage .putFloat (rowId , value );
195
199
} else {
196
200
throw new RuntimeException ("internal error: " + debugInfo ());
197
201
}
@@ -229,6 +233,21 @@ public long decodeLong(int value) {
229
233
throw new RuntimeException ("internal error: " + debugInfo ());
230
234
}
231
235
236
+ @ Override
237
+ public float decodeFloat (byte value ) {
238
+ return (max - value ) / floatFactor ;
239
+ }
240
+
241
+ @ Override
242
+ public float decodeFloat (short value ) {
243
+ return (max - value ) / floatFactor ;
244
+ }
245
+
246
+ @ Override
247
+ public float decodeFloat (int value ) {
248
+ return (max - value ) / floatFactor ;
249
+ }
250
+
232
251
@ Override
233
252
public double decodeDouble (byte value ) {
234
253
return (max - value ) / factor ;
@@ -265,7 +284,6 @@ public void decodeAndFillVector(byte[] pageData, ColumnVectorInfo vectorInfo, Bi
265
284
int intSizeInBytes = DataTypes .INT .getSizeInBytes ();
266
285
int longSizeInBytes = DataTypes .LONG .getSizeInBytes ();
267
286
if (vectorDataType == DataTypes .FLOAT ) {
268
- float floatFactor = factor .floatValue ();
269
287
if (pageDataType == DataTypes .BOOLEAN || pageDataType == DataTypes .BYTE ) {
270
288
for (int i = 0 ; i < pageSize ; i ++) {
271
289
vector .putFloat (i , (max - pageData [i ]) / floatFactor );
0 commit comments