Exemplo n.º 1
0
        private void _Initialize()
        {
            // assume theyre either all sorted or all not.  Also, some of these might
            // be empty assuming there were empty buckets so handle that.

            InternalRecordSource mergeDevice = null;

            if (Sorting.IsSorted) {
                mergeDevice = new SortedRecordMerger();
            }

            else {
                // is it right to hard code sortAscending!?!?
                mergeDevice = new RecordSorterReducer(_tempDir, true, _reductionEnabled);
            }

            // add the sources
            foreach (InternalRecordSource source in Inputs) {
                mergeDevice.AddInput(source);
            }

            _output = mergeDevice;
        }
Exemplo n.º 2
0
        private void _Finish()
        {
            if (_doThreading) {
                _SortAndWriteThreaded();
                // wait on all previous threads, sorts and writes
                foreach (Thread t in _threads) {
                    t.Join();
                }
                _threads.Clear();
            }

            else {
                // don't write the last one to disk
                _recordsToSort.Sort();
                _sortedRecords = _recordsToSort;
            }

            int numToMerge = _numTempFiles;

            if (_sortedRecords != null && _sortedRecords.NumRecords != 0) {
                numToMerge++;
            }

            if (numToMerge > 1) {
                _merger = new SortedRecordMerger();

                if (_sortedRecords != null && _sortedRecords.NumRecords != 0) {
                    _merger.AddInput(_sortedRecords);
                }

                for (int i = 0; i < _numTempFiles; i++) {
                    InternalRecordSource source = new InternalRecordFileReader(GetTempFilename(i));
                    _merger.AddInput(source);
                }

                _output = _merger;
            }

            else {
                _output = _sortedRecords;
            }

            // set up reduction filter for reduction across merged sources
            if (_internalReductionEnabled) {
                ReduceFilter reducer = new ReduceFilter();
                RecordFilterDriver filterDriver = new RecordFilterDriver(reducer);
                filterDriver.AddInput(_output);
                _output = filterDriver;
            }

            // this is kind of a hack till i figure out how these should be set
            TotalRecordBytesEstimate = _output.TotalRecordBytesEstimate;
            TotalRecordsEstimate = _output.TotalRecordsEstimate;
        }