]> git.proxmox.com Git - ceph.git/blame - ceph/src/arrow/csharp/src/Apache.Arrow/Ipc/ArrowFooter.cs
import quincy 17.2.0
[ceph.git] / ceph / src / arrow / csharp / src / Apache.Arrow / Ipc / ArrowFooter.cs
CommitLineData
1d09f67e
TL
1// Licensed to the Apache Software Foundation (ASF) under one or more
2// contributor license agreements. See the NOTICE file distributed with
3// this work for additional information regarding copyright ownership.
4// The ASF licenses this file to You under the Apache License, Version 2.0
5// (the "License"); you may not use this file except in compliance with
6// the License. You may obtain a copy of the License at
7//
8// http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15
16using System.Collections.Generic;
17using System.Diagnostics;
18using System.Linq;
19
20namespace Apache.Arrow.Ipc
21{
22 internal class ArrowFooter
23 {
24 public Schema Schema { get; }
25 private readonly List<Block> _dictionaries;
26 private readonly List<Block> _recordBatches;
27
28 public IEnumerable<Block> Dictionaries => _dictionaries;
29 public IEnumerable<Block> RecordBatches => _recordBatches;
30
31 public Block GetRecordBatchBlock(int i) => _recordBatches[i];
32
33 public Block GetDictionaryBlock(int i) => _dictionaries[i];
34
35 public int RecordBatchCount => _recordBatches.Count;
36 public int DictionaryCount => _dictionaries.Count;
37
38 public ArrowFooter(Schema schema, IEnumerable<Block> dictionaries, IEnumerable<Block> recordBatches)
39 {
40 Schema = schema;
41
42 _dictionaries = dictionaries.ToList();
43 _recordBatches = recordBatches.ToList();
44
45#if DEBUG
46 for (int i = 0; i < _dictionaries.Count; i++)
47 {
48 Block block = _dictionaries[i];
49 Debug.Assert(BitUtility.IsMultipleOf8(block.Offset));
50 Debug.Assert(BitUtility.IsMultipleOf8(block.MetadataLength));
51 Debug.Assert(BitUtility.IsMultipleOf8(block.BodyLength));
52 }
53
54 for (int i = 0; i < _recordBatches.Count; i++)
55 {
56 Block block = _recordBatches[i];
57 Debug.Assert(BitUtility.IsMultipleOf8(block.Offset));
58 Debug.Assert(BitUtility.IsMultipleOf8(block.MetadataLength));
59 Debug.Assert(BitUtility.IsMultipleOf8(block.BodyLength));
60 }
61#endif
62 }
63
64 public ArrowFooter(Flatbuf.Footer footer, ref DictionaryMemo dictionaryMemo)
65 : this(Ipc.MessageSerializer.GetSchema(footer.Schema.GetValueOrDefault(), ref dictionaryMemo), GetDictionaries(footer),
66 GetRecordBatches(footer))
67 { }
68
69 private static IEnumerable<Block> GetDictionaries(Flatbuf.Footer footer)
70 {
71 for (int i = 0; i < footer.DictionariesLength; i++)
72 {
73 Flatbuf.Block? block = footer.Dictionaries(i);
74
75 if (block.HasValue)
76 {
77 yield return new Block(block.Value);
78 }
79 }
80 }
81
82 private static IEnumerable<Block> GetRecordBatches(Flatbuf.Footer footer)
83 {
84 for (int i = 0; i < footer.RecordBatchesLength; i++)
85 {
86 Flatbuf.Block? block = footer.RecordBatches(i);
87
88 if (block.HasValue)
89 {
90 yield return new Block(block.Value);
91 }
92 }
93 }
94
95 }
96}