sparrow 0.6.0
Loading...
Searching...
No Matches
arrow_array_schema_common_release.hpp
Go to the documentation of this file.
1// Copyright 2024 Man Group Operations Limited
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15#pragma once
16
20
21namespace sparrow
22{
29 template <class T>
30 requires std::same_as<T, ArrowArray> || std::same_as<T, ArrowSchema>
32 {
33 using private_data_type = std::
34 conditional_t<std::same_as<T, ArrowArray>, arrow_array_private_data, arrow_schema_private_data>;
35 if (t.release == nullptr)
36 {
37 return;
38 }
39 SPARROW_ASSERT_TRUE(t.private_data != nullptr);
40 const auto private_data = static_cast<const private_data_type*>(t.private_data);
41
42 if (t.dictionary)
43 {
44 if (private_data->has_dictionary_ownership())
45 {
46 if (t.dictionary->release)
47 {
48 t.dictionary->release(t.dictionary);
49 }
50 delete t.dictionary;
51 t.dictionary = nullptr;
52 }
53 }
54
55 if (t.children)
56 {
57 for (int64_t i = 0; i < t.n_children; ++i)
58 {
59 T* child = t.children[i];
60 if (child)
61 {
62 if (private_data->has_child_ownership(static_cast<std::size_t>(i)))
63 {
64 if (child->release)
65 {
66 child->release(child);
67 }
68 delete child;
69 child = nullptr;
70 }
71 }
72 }
73 delete[] t.children;
74 t.children = nullptr;
75 }
76 t.release = nullptr;
77 }
78}
Private data for ArrowArray.
Private data for ArrowSchema.
#define SPARROW_ASSERT_TRUE(expr__)
void release_common_arrow(T &t)
Release the children and dictionnary of an ArrowArray or ArrowSchema.