@Override public UnsafeMemoryDMStore convertToUnsafeDMStore(CarbonRowSchema[] schema) throws MemoryException { setSchemaDataType(schema); UnsafeMemoryDMStore unsafeMemoryDMStore = new UnsafeMemoryDMStore(); for (DataMapRow dataMapRow : dataMapRows) { dataMapRow.setSchemas(schema); unsafeMemoryDMStore.addIndexRow(schema, dataMapRow); } unsafeMemoryDMStore.finishWriting(); return unsafeMemoryDMStore; }
/** * Add the index row to unsafe. * * @param indexRow * @return */ public void addIndexRow(CarbonRowSchema[] schema, DataMapRow indexRow) throws MemoryException { // First calculate the required memory to keep the row in unsafe int rowSize = indexRow.getTotalSizeInBytes(); // Check whether allocated memory is sufficient or not. ensureSize(rowSize); int pointer = runningLength; for (int i = 0; i < schema.length; i++) { addToUnsafe(schema[i], indexRow, i); } pointers[rowCount++] = pointer; }
/** * Check memory is sufficient or not, if not sufficient allocate more memory and copy old data to * new one. * * @param rowSize */ private void ensureSize(int rowSize) throws MemoryException { if (runningLength + rowSize >= allocatedSize) { increaseMemory(runningLength + rowSize); } if (this.pointers.length <= rowCount + 1) { int[] newPointer = new int[pointers.length + 1000]; System.arraycopy(pointers, 0, newPointer, 0, pointers.length); this.pointers = newPointer; } }
protected AbstractMemoryDMStore getMemoryDMStore(boolean addToUnsafe) throws MemoryException { AbstractMemoryDMStore memoryDMStore; if (addToUnsafe) { memoryDMStore = new UnsafeMemoryDMStore(); } else { memoryDMStore = new SafeMemoryDMStore(); } return memoryDMStore; }
DataMapRow struct = row.getRow(index); for (int i = 0; i < childSchemas.length; i++) { addToUnsafe(childSchemas[i], struct, i);