public override RowMergeState HandleChunk(RowAsyncEnumerator owner, CellChunk chunk)
            {
                if (chunk.ResetRow)
                {
                    return(owner.ResetRow(chunk));
                }

                owner.HadSplitCell = true;
                owner.Assert(chunk.FamilyName == null, "CellInProgress can't have a family");
                owner.Assert(chunk.Qualifier == null, "CellInProgress can't have a qualifier");
                owner.Assert(chunk.TimestampMicros == 0, "CellInProgress can't have a timestamp");
                owner.Assert(chunk.Labels.Count == 0, "CellInProgress can't have labels");

                owner._currentCell.ValueSizeRemaining -= chunk.Value.Length;

                bool isLast = chunk.ValueSize == 0;

                if (isLast)
                {
                    owner.Assert(
                        owner._currentCell.ValueSizeRemaining == 0,
                        $"CellInProgress is last, but is missing {owner._currentCell.ValueSizeRemaining} bytes");
                }
                else
                {
                    owner.Assert(
                        owner._currentCell.ValueSizeExpected == chunk.ValueSize,
                        "CellInProgress valueSizes should be identical for nonterminal chunks");
                    owner.Assert(!chunk.CommitRow, "CellInProgress can't commit with a nonterminal chunk");
                }

                ref var accumulator = ref owner._currentCell.ValueAccumulator;
Beispiel #2
0
            public override RowMergeState HandleChunk(RowAsyncEnumerator owner, CellChunk chunk)
            {
                if (chunk.ResetRow)
                {
                    return(owner.ResetRow(chunk));
                }

                owner.Assert(
                    chunk.RowKey.IsEmpty || chunk.RowKey == owner._currentCell.Row.Key,
                    "Cell row keys must not change");

                bool isSplit = chunk.ValueSize > 0;

                if (isSplit)
                {
                    owner.Assert(
                        !chunk.CommitRow, "NewCell can't commit when valueSize indicates more data");
                    owner.Assert(
                        !chunk.Value.IsEmpty,
                        "NewCell must have data when valueSize promises more data in the next chunk");
                }
                owner.Assert(chunk.ValueSize >= 0, "NewCell valueSize can't be negative");

                if (chunk.FamilyName != null)
                {
                    if (chunk.FamilyName != owner._currentCell.Family?.Name)
                    {
                        owner._currentCell.Family = new Family {
                            Name = chunk.FamilyName
                        };
                        Debug.Assert(!owner._currentFamilies.ContainsKey(chunk.FamilyName));
                        owner._currentFamilies[chunk.FamilyName] = owner._currentCell.Family;
                    }
                    owner.Assert(chunk.Qualifier != null, "NewCell has a familyName, but no qualifier");
                }

                if (chunk.Qualifier != null && chunk.Qualifier != owner._currentCell.Column?.Qualifier)
                {
                    owner._currentCell.Column = new Column {
                        Qualifier = chunk.Qualifier
                    };
                    owner.Assert(
                        owner._currentCell.Family != null,
                        "NewCell has a qualifier, but no familyName");
                    owner._currentCell.Family.Columns.Add(owner._currentCell.Column);
                }

                owner._currentCell.Timestamp = chunk.TimestampMicros;
                owner._currentCell.Labels    = chunk.Labels;

                // calculate cell size
                owner._currentCell.ValueSizeExpected  = isSplit ? chunk.ValueSize : chunk.Value.Length;
                owner._currentCell.ValueSizeRemaining = owner._currentCell.ValueSizeExpected - chunk.Value.Length;

                if (owner._currentCell.ValueSizeRemaining != 0)
                {
                    ref var accumulator = ref owner._currentCell.ValueAccumulator;
                    if (accumulator == null)
                    {
                        accumulator = new List <byte>(owner._currentCell.ValueSizeExpected);
                    }
                    else
                    {
                        Debug.Assert(accumulator.Count == 0);
                        accumulator.Capacity = Math.Max(owner._currentCell.ValueSizeExpected, accumulator.Capacity);
                    }

                    owner._currentCell.ValueAccumulator.AddRange(chunk.Value);
                    return(CellInProgress.Instance);
                }