use of com.linkedin.pinot.core.io.reader.impl.FixedByteSingleValueMultiColReader in project pinot by linkedin.
the class FixedByteSingleColumnMultiValueReaderWriter method addCapacity.
/**
* This method automatically computes the space needed based on the columnSizeInBytes
* @param rowCapacity Additional capacity to be added in terms of number of rows
* @throws RuntimeException
*/
private void addCapacity(int rowCapacity) throws RuntimeException {
PinotDataBuffer dataBuffer;
try {
dataBuffer = PinotDataBuffer.allocateDirect(rowCapacity * columnSizeInBytes);
//dataBuffer.order(ByteOrder.nativeOrder());
dataBuffers.add(dataBuffer);
currentDataWriter = new FixedByteSingleValueMultiColWriter(dataBuffer, rowCapacity, 1, new int[] { columnSizeInBytes });
dataWriters.add(currentDataWriter);
FixedByteSingleValueMultiColReader dataFileReader = new FixedByteSingleValueMultiColReader(dataBuffer, rowCapacity, 1, new int[] { columnSizeInBytes });
dataReaders.add(dataFileReader);
//update the capacity
currentCapacity = rowCapacity;
currentDataWriterIndex = currentDataWriterIndex + 1;
} catch (Exception e) {
throw new RuntimeException("Error while expanding the capacity by allocating additional buffer with capacity:" + rowCapacity, e);
}
}
use of com.linkedin.pinot.core.io.reader.impl.FixedByteSingleValueMultiColReader in project pinot by linkedin.
the class FixedByteSingleColumnMultiValueReaderWriter method init.
private void init(int rows, int columnSizeInBytes, int maxNumberOfMultiValuesPerRow, int initialCapacity, int incrementalCapacity) throws IOException {
this.columnSizeInBytes = columnSizeInBytes;
this.maxNumberOfMultiValuesPerRow = maxNumberOfMultiValuesPerRow;
headerSize = rows * SIZE_OF_INT * NUM_COLS_IN_HEADER;
headerBuffer = PinotDataBuffer.allocateDirect(headerSize);
// headerBuffer.order(ByteOrder.nativeOrder());
//dataBufferId, startIndex, length
headerWriter = new FixedByteSingleValueMultiColWriter(headerBuffer, rows, 3, new int[] { SIZE_OF_INT, SIZE_OF_INT, SIZE_OF_INT });
headerReader = new FixedByteSingleValueMultiColReader(headerBuffer, rows, 3, new int[] { SIZE_OF_INT, SIZE_OF_INT, SIZE_OF_INT });
//at least create space for million entries, which for INT translates into 4mb buffer
this.incrementalCapacity = incrementalCapacity;
addCapacity(initialCapacity);
}
use of com.linkedin.pinot.core.io.reader.impl.FixedByteSingleValueMultiColReader in project pinot by linkedin.
the class FixedByteWidthRowColDataFileWriterTest method testSpecialPaddingCharsForStringReaderWriter.
@Test
public void testSpecialPaddingCharsForStringReaderWriter() throws Exception {
for (int iter = 0; iter < 2; iter++) {
char paddingChar = (iter == 0) ? '%' : '\0';
final byte[] bytes1 = new byte[] { -17, -65, -67, -17, -65, -67, 32, 69, 120, 101, 99, 117, 116, 105, 118, 101 };
final byte[] bytes2 = new byte[] { -17, -65, -68, 32, 99, 97, 108, 103, 97, 114, 121, 32, 106, 117, 110, 107, 32, 114, 101, 109, 111, 118, 97, 108 };
File file = new File("test_single_col_writer.dat");
file.delete();
int rows = 100;
int cols = 1;
String testString1 = new String(bytes1);
String testString2 = new String(bytes2);
// System.out.println(Arrays.toString(bytes2));
int stringColumnMaxLength = Math.max(testString1.getBytes().length, testString2.getBytes().length);
int[] columnSizes = new int[] { stringColumnMaxLength };
FixedByteSingleValueMultiColWriter writer = new FixedByteSingleValueMultiColWriter(file, rows, cols, columnSizes);
String[] data = new String[rows];
for (int i = 0; i < rows; i++) {
String toPut = (i % 2 == 0) ? testString1 : testString2;
final int padding = stringColumnMaxLength - toPut.getBytes().length;
final StringBuilder bld = new StringBuilder();
bld.append(toPut);
for (int j = 0; j < padding; j++) {
bld.append(paddingChar);
}
data[i] = bld.toString();
writer.setString(i, 0, data[i]);
}
writer.close();
PinotDataBuffer mmapBuffer = PinotDataBuffer.fromFile(file, ReadMode.mmap, FileChannel.MapMode.READ_ONLY, "testing");
FixedByteSingleValueMultiColReader dataFileReader = new FixedByteSingleValueMultiColReader(mmapBuffer, rows, 1, new int[] { stringColumnMaxLength });
for (int i = 0; i < rows; i++) {
String stringInFile = dataFileReader.getString(i, 0);
Assert.assertEquals(stringInFile, data[i]);
Assert.assertEquals(StringUtils.remove(stringInFile, String.valueOf(paddingChar)), StringUtils.remove(data[i], String.valueOf(paddingChar)));
}
file.delete();
}
}
use of com.linkedin.pinot.core.io.reader.impl.FixedByteSingleValueMultiColReader in project pinot by linkedin.
the class FixedByteWidthRowColDataFileWriterTest method testSpecialCharsForStringReaderWriter.
@Test
public void testSpecialCharsForStringReaderWriter() throws Exception {
final byte[] bytes1 = new byte[] { -17, -65, -67, -17, -65, -67, 32, 69, 120, 101, 99, 117, 116, 105, 118, 101 };
final byte[] bytes2 = new byte[] { -17, -65, -68, 32, 99, 97, 108, 103, 97, 114, 121, 32, 106, 117, 110, 107, 32, 114, 101, 109, 111, 118, 97, 108 };
File file = new File("test_single_col_writer.dat");
file.delete();
int rows = 100;
int cols = 1;
String testString1 = new String(bytes1);
String testString2 = new String(bytes2);
// System.out.println(Arrays.toString(bytes2));
int stringColumnMaxLength = Math.max(testString1.getBytes().length, testString2.getBytes().length);
int[] columnSizes = new int[] { stringColumnMaxLength };
FixedByteSingleValueMultiColWriter writer = new FixedByteSingleValueMultiColWriter(file, rows, cols, columnSizes);
String[] data = new String[rows];
for (int i = 0; i < rows; i++) {
String toPut = (i % 2 == 0) ? testString1 : testString2;
final int padding = stringColumnMaxLength - toPut.getBytes().length;
final StringBuilder bld = new StringBuilder();
bld.append(toPut);
for (int j = 0; j < padding; j++) {
bld.append(V1Constants.Str.DEFAULT_STRING_PAD_CHAR);
}
data[i] = bld.toString();
writer.setString(i, 0, data[i]);
}
writer.close();
PinotDataBuffer mmapBuffer = PinotDataBuffer.fromFile(file, ReadMode.mmap, FileChannel.MapMode.READ_ONLY, "testing");
FixedByteSingleValueMultiColReader dataFileReader = new FixedByteSingleValueMultiColReader(mmapBuffer, rows, 1, new int[] { stringColumnMaxLength });
for (int i = 0; i < rows; i++) {
String stringInFile = dataFileReader.getString(i, 0);
Assert.assertEquals(stringInFile, data[i]);
Assert.assertEquals(StringUtils.remove(stringInFile, String.valueOf(V1Constants.Str.DEFAULT_STRING_PAD_CHAR)), StringUtils.remove(data[i], String.valueOf(V1Constants.Str.DEFAULT_STRING_PAD_CHAR)));
}
file.delete();
}
use of com.linkedin.pinot.core.io.reader.impl.FixedByteSingleValueMultiColReader in project pinot by linkedin.
the class FixedByteWidthRowColDataFileReaderTest method testSingleCol.
@Test
void testSingleCol() throws Exception {
String fileName = "test_single_col.dat";
File f = new File(fileName);
f.delete();
DataOutputStream dos = new DataOutputStream(new FileOutputStream(f));
int[] data = new int[100];
Random r = new Random();
for (int i = 0; i < data.length; i++) {
data[i] = r.nextInt();
dos.writeInt(data[i]);
}
dos.flush();
dos.close();
RandomAccessFile raf = new RandomAccessFile(f, "rw");
// System.out.println("file size: " + raf.getChannel().size());
raf.close();
PinotDataBuffer heapBuffer = PinotDataBuffer.fromFile(f, ReadMode.heap, FileChannel.MapMode.READ_ONLY, "testing");
FixedByteSingleValueMultiColReader heapReader = new FixedByteSingleValueMultiColReader(heapBuffer, data.length, 1, new int[] { 4 });
heapReader.open();
for (int i = 0; i < data.length; i++) {
Assert.assertEquals(heapReader.getInt(i, 0), data[i]);
}
heapBuffer.close();
heapReader.close();
// Not strictly required. Let the tests pass first...then we can remove
// TODO: remove me
PinotDataBuffer mmapBuffer = PinotDataBuffer.fromFile(f, ReadMode.mmap, FileChannel.MapMode.READ_ONLY, "mmap_testing");
FixedByteSingleValueMultiColReader mmapReader = new FixedByteSingleValueMultiColReader(mmapBuffer, data.length, 1, new int[] { 4 });
mmapReader.open();
for (int i = 0; i < data.length; i++) {
Assert.assertEquals(mmapReader.getInt(i, 0), data[i]);
}
mmapBuffer.close();
mmapReader.close();
f.delete();
}
Aggregations