private static void RoundTrip(string columnName, int[] array, int batchSize = 128) { XDatabaseContext context = new XDatabaseContext(); string columnPath = Path.Combine("VariableIntegerReaderWriterTests", columnName); string columnPrefix = Path.Combine(columnPath, "Vl"); context.StreamProvider.Delete(columnPath); Directory.CreateDirectory(columnPath); XArray values = XArray.All(array, array.Length); using (IColumnWriter writer = new VariableIntegerWriter(context.StreamProvider, columnPrefix)) { ArraySelector page = ArraySelector.All(0).NextPage(array.Length, batchSize); while (page.Count > 0) { writer.Append(values.Reselect(page)); page = page.NextPage(array.Length, batchSize); } } XArray returned = default(XArray); using (IColumnReader reader = new VariableIntegerReader(context.StreamProvider, columnPrefix, CachingOption.AsConfigured)) { returned = reader.Read(ArraySelector.All(array.Length)); } TableTestHarness.AssertAreEqual(values, returned, array.Length); context.StreamProvider.Delete(columnPath); }
public int Next(int desiredCount, CancellationToken cancellationToken) { _currentEnumerateSelector = _currentEnumerateSelector.NextPage(Count, desiredCount); _currentSelector = _currentEnumerateSelector; CurrentRowCount = _currentEnumerateSelector.Count; return(CurrentRowCount); }
public int Next(int desiredCount, CancellationToken cancellationToken) { long countToReturn = Math.Min(_rowCount - _countEnumerated, desiredCount); if (countToReturn == 0) { return(0); } _currentEnumerateSelector = _currentEnumerateSelector.NextPage(_arrayRowCount, (int)countToReturn); if (_currentEnumerateSelector.Count == 0) { _currentEnumerateSelector = ArraySelector.All(_arrayRowCount).Slice(0, 0); _currentEnumerateSelector = _currentEnumerateSelector.NextPage(_arrayRowCount, (int)countToReturn); } _currentSelector = _currentEnumerateSelector; for (int i = 0; i < _columns.Count; ++i) { _columns[i].SetSelector(_currentEnumerateSelector); } CurrentRowCount = _currentEnumerateSelector.Count; _countEnumerated += _currentEnumerateSelector.Count; return(CurrentRowCount); }
public override int Next(int desiredCount, CancellationToken cancellationToken) { _enumerateSelector = _enumerateSelector.NextPage(_source.Columns.Count, desiredCount); _columns[0].SetSelector(_enumerateSelector); _columns[1].SetSelector(_enumerateSelector); return(_enumerateSelector.Count); }
public int Next(int desiredCount, CancellationToken cancellationToken) { _currentEnumerateSelector = _currentEnumerateSelector.NextPage(_rowCount, desiredCount); _currentSelector = _currentEnumerateSelector; for (int i = 0; i < _columns.Count; ++i) { _columns[i].SetSelector(_currentEnumerateSelector); } CurrentRowCount = _currentEnumerateSelector.Count; return(CurrentRowCount); }
private void Upconvert(Type toType) { // Close the current writer _writer.Dispose(); _writer = null; // Determine previous and new file paths string columnValuesFullPath = PathForType(_columnPathPrefix, WritingAsType); string columnConvertedFullPath = PathForType(_columnPathPrefix, toType); // Build a writer for the larger type IColumnWriter writer = BuildDirectWriter(_streamProvider, toType, columnConvertedFullPath); // Convert already written values (if any) if (_rowCountWritten > 0) { // Build a converter to convert the values Func <XArray, XArray> converter = TypeConverterFactory.GetConverter(WritingAsType, toType); // Stream them in, convert them, and write them out using (IColumnReader reader = TypeProviderFactory.TryGetColumnReader(_streamProvider, WritingAsType, columnValuesFullPath)) { int rowCount = reader.Count; ArraySelector page = ArraySelector.All(0).NextPage(rowCount, 10240); while (page.Count > 0) { XArray original = reader.Read(page); XArray converted = converter(original); writer.Append(converted); page = page.NextPage(rowCount, 10240); } } } // Delete the original file _streamProvider.Delete(columnValuesFullPath); // Re-initialize for the new writer WritingAsType = toType; _writer = writer; _converter = (toType == typeof(int) ? null : TypeConverterFactory.GetConverter(typeof(int), toType)); }
public int Next(int desiredCount, CancellationToken cancellationToken) { // If this is the first call, walk all rows once to group them if (!_isDictionaryBuilt) { _isDictionaryBuilt = true; BuildDictionary(cancellationToken); Reset(); } // Once done, page through the distinct group by values found _currentEnumerateSelector = _currentEnumerateSelector.NextPage(_distinctCount, desiredCount); for (int i = 0; i < _columns.Length; ++i) { _columns[i].SetSelector(_currentEnumerateSelector); } CurrentRowCount = _currentEnumerateSelector.Count; return(CurrentRowCount); }
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)); }