public EnumWriter(IStreamProvider streamProvider, string columnPath, Type columnType, IColumnWriter valueWriter) { _streamProvider = streamProvider; _columnPath = columnPath; _valueWriter = valueWriter; _dictionary = (IEnumColumnDictionary)Allocator.ConstructGenericOf(typeof(EnumColumnDictionary <>), columnType); _rowIndexWriter = new PrimitiveArrayWriter <byte>(streamProvider.OpenWrite(Path.Combine(_columnPath, RowIndexFileName))); }
public void Dispose() { // If we're still an enum column, write the distinct values out if (_dictionary != null) { _valueWriter.Append(_dictionary.Values()); _dictionary = null; } if (_valueWriter != null) { _valueWriter.Dispose(); _valueWriter = null; } if (_rowIndexWriter != null) { _rowIndexWriter.Dispose(); _rowIndexWriter = null; } }
private void Convert() { // Close the row index writer _rowIndexWriter.Dispose(); _rowIndexWriter = null; // If we wrote any rows we need to convert... if (_rowCountWritten > 0) { // Get the set of unique values and get rid of the value dictionary XArray values = _dictionary.Values(); // Convert the indices previously written into raw values Func <XArray, XArray> converter = TypeConverterFactory.GetConverter(typeof(byte), typeof(int)); using (IColumnReader rowIndexReader = new PrimitiveArrayReader <byte>(_streamProvider.OpenRead(Path.Combine(_columnPath, RowIndexFileName)))) { int rowCount = rowIndexReader.Count; ArraySelector page = ArraySelector.All(0).NextPage(rowCount, 10240); while (page.Count > 0) { // Read an XArray of indices and convert to int[] XArray rowIndices = converter(rowIndexReader.Read(page)); // Write the corresponding values // Reselect is safe because 'values' are converted to a contiguous array _valueWriter.Append(values.Reselect(ArraySelector.Map((int[])rowIndices.Array, rowIndices.Count))); page = page.NextPage(rowCount, 10240); } } } // Remove the Dictionary (so future rows are streamed out as-is) _dictionary = null; // Delete the row index file _streamProvider.Delete(Path.Combine(_columnPath, RowIndexFileName)); }