@@ -39,16 +39,18 @@ public class VectorizedDeltaByteArrayReader extends VectorizedReaderBase
39
39
private final VectorizedDeltaBinaryPackedReader prefixLengthReader ;
40
40
private final VectorizedDeltaLengthByteArrayReader suffixReader ;
41
41
private WritableColumnVector prefixLengthVector ;
42
- private ByteBuffer previous = null ;
42
+ private ByteBuffer previous ;
43
43
private int currentRow = 0 ;
44
44
45
45
// temporary variable used by getBinary
46
46
private final WritableColumnVector binaryValVector ;
47
+ private final WritableColumnVector tempBinaryValVector ;
47
48
48
49
VectorizedDeltaByteArrayReader () {
49
50
this .prefixLengthReader = new VectorizedDeltaBinaryPackedReader ();
50
51
this .suffixReader = new VectorizedDeltaLengthByteArrayReader ();
51
52
binaryValVector = new OnHeapColumnVector (1 , BinaryType );
53
+ tempBinaryValVector = new OnHeapColumnVector (1 , BinaryType );
52
54
}
53
55
54
56
@ Override
@@ -62,12 +64,11 @@ public void initFromPage(int valueCount, ByteBufferInputStream in) throws IOExce
62
64
63
65
@ Override
64
66
public Binary readBinary (int len ) {
65
- readValues (1 , binaryValVector , 0 , ByteBufferOutputWriter :: writeArrayByteBuffer );
67
+ readValues (1 , binaryValVector , 0 );
66
68
return Binary .fromConstantByteArray (binaryValVector .getBinary (0 ));
67
69
}
68
70
69
- private void readValues (int total , WritableColumnVector c , int rowId ,
70
- ByteBufferOutputWriter outputWriter ) {
71
+ private void readValues (int total , WritableColumnVector c , int rowId ) {
71
72
for (int i = 0 ; i < total ; i ++) {
72
73
// NOTE: due to PARQUET-246, it is important that we
73
74
// respect prefixLength which was read from prefixLengthReader,
@@ -81,29 +82,21 @@ private void readValues(int total, WritableColumnVector c, int rowId,
81
82
int length = prefixLength + suffixLength ;
82
83
83
84
// We have to do this to materialize the output
85
+ WritableColumnVector arrayData = c .arrayData ();
86
+ int offset = arrayData .getElementsAppended ();
84
87
if (prefixLength != 0 ) {
85
- // We could do
86
- // c.putByteArray(rowId + i, previous, 0, prefixLength);
87
- // c.putByteArray(rowId+i, suffix, prefixLength, suffix.length);
88
- // previous = c.getBinary(rowId+1);
89
- // but it incurs the same cost of copying the values twice _and_ c.getBinary
90
- // is a _slow_ byte by byte copy
91
- // The following always uses the faster system arraycopy method
92
- byte [] out = new byte [length ];
93
- System .arraycopy (previous .array (), previous .position (), out , 0 , prefixLength );
94
- System .arraycopy (suffixArray , suffix .position (), out , prefixLength , suffixLength );
95
- previous = ByteBuffer .wrap (out );
96
- } else {
97
- previous = suffix ;
88
+ arrayData .appendBytes (prefixLength , previous .array (), previous .position ());
98
89
}
99
- outputWriter .write (c , rowId + i , previous , previous .limit () - previous .position ());
90
+ arrayData .appendBytes (suffixLength , suffixArray , suffix .position ());
91
+ c .putArray (rowId + i , offset , length );
92
+ previous = arrayData .getBytesUnsafe (offset , length );
100
93
currentRow ++;
101
94
}
102
95
}
103
96
104
97
@ Override
105
98
public void readBinary (int total , WritableColumnVector c , int rowId ) {
106
- readValues (total , c , rowId , ByteBufferOutputWriter :: writeArrayByteBuffer );
99
+ readValues (total , c , rowId );
107
100
}
108
101
109
102
/**
@@ -121,9 +114,29 @@ public void setPreviousReader(ValuesReader reader) {
121
114
122
115
@ Override
123
116
public void skipBinary (int total ) {
124
- // we have to read all the values so that we always have the correct 'previous'
125
- // we just don't write it to the output vector
126
- readValues (total , null , currentRow , ByteBufferOutputWriter ::skipWrite );
117
+ WritableColumnVector c1 = tempBinaryValVector ;
118
+ WritableColumnVector c2 = binaryValVector ;
119
+
120
+ for (int i = 0 ; i < total ; i ++) {
121
+ int prefixLength = prefixLengthVector .getInt (currentRow );
122
+ ByteBuffer suffix = suffixReader .getBytes (currentRow );
123
+ byte [] suffixArray = suffix .array ();
124
+ int suffixLength = suffix .limit () - suffix .position ();
125
+ int length = prefixLength + suffixLength ;
126
+
127
+ WritableColumnVector arrayData = c1 .arrayData ();
128
+ c1 .reset ();
129
+ if (prefixLength != 0 ) {
130
+ arrayData .appendBytes (prefixLength , previous .array (), previous .position ());
131
+ }
132
+ arrayData .appendBytes (suffixLength , suffixArray , suffix .position ());
133
+ previous = arrayData .getBytesUnsafe (0 , length );
134
+ currentRow ++;
135
+
136
+ WritableColumnVector tmp = c1 ;
137
+ c1 = c2 ;
138
+ c2 = tmp ;
139
+ }
127
140
}
128
141
129
142
}
0 commit comments