1
+ /* *
2
+ * @file soma_attribute.h
3
+ *
4
+ * @section LICENSE
5
+ *
6
+ * The MIT License
7
+ *
8
+ * @copyright Copyright (c) 2024-2025 TileDB, Inc.
9
+ *
10
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
11
+ * of this software and associated documentation files (the "Software"), to deal
12
+ * in the Software without restriction, including without limitation the rights
13
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14
+ * copies of the Software, and to permit persons to whom the Software is
15
+ * furnished to do so, subject to the following conditions:
16
+ *
17
+ * The above copyright notice and this permission notice shall be included in
18
+ * all copies or substantial portions of the Software.
19
+ *
20
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
26
+ * THE SOFTWARE.
27
+ *
28
+ * @section DESCRIPTION
29
+ *
30
+ * This file defines the SOMAAttribute class. SOMAAttribute extends SOMAColumn
31
+ * and wraps a TileDB Attribute and optionally an enumeration associated with
32
+ * the attribute. The purpose of this class is to provide a common interface
33
+ * identical to TileDB dimensions and composite columns.
34
+ */
35
+
36
+ #ifndef SOMA_ATTRIBUTE_H
37
+ #define SOMA_ATTRIBUTE_H
38
+
39
+ #include < algorithm>
40
+ #include < vector>
41
+
42
+ #include < tiledb/tiledb>
43
+ #include " soma_column.h"
44
+
45
+ namespace tiledbsoma {
46
+ using namespace tiledb ;
47
+
48
+ class SOMAAttribute : public SOMAColumn {
49
+ public:
50
+ /* *
51
+ * Create a ``SOMAAttribute`` shared pointer from an Arrow schema
52
+ */
53
+ static std::shared_ptr<SOMAAttribute> create (
54
+ std::shared_ptr<Context> ctx,
55
+ ArrowSchema* schema,
56
+ std::string_view type_metadata,
57
+ PlatformConfig platform_config);
58
+
59
+ SOMAAttribute (
60
+ Attribute attribute,
61
+ std::optional<Enumeration> enumeration = std::nullopt)
62
+ : attribute(attribute)
63
+ , enumeration(enumeration) {
64
+ }
65
+
66
+ inline std::string name () const override {
67
+ return attribute.name ();
68
+ }
69
+
70
+ inline bool isIndexColumn () const override {
71
+ return false ;
72
+ }
73
+
74
+ inline void select_columns (
75
+ const std::unique_ptr<ManagedQuery>& query,
76
+ bool if_not_empty = false ) const override {
77
+ query->select_columns (std::vector ({attribute.name ()}), if_not_empty);
78
+ };
79
+
80
+ inline soma_column_datatype_t type () const override {
81
+ return soma_column_datatype_t ::SOMA_COLUMN_ATTRIBUTE;
82
+ }
83
+
84
+ inline std::optional<tiledb_datatype_t > domain_type () const override {
85
+ return std::nullopt;
86
+ }
87
+
88
+ inline std::optional<tiledb_datatype_t > data_type () const override {
89
+ return attribute.type ();
90
+ }
91
+
92
+ inline std::optional<std::vector<Dimension>> tiledb_dimensions () override {
93
+ return std::nullopt;
94
+ }
95
+
96
+ inline std::optional<std::vector<Attribute>> tiledb_attributes () override {
97
+ return std::vector ({attribute});
98
+ }
99
+
100
+ inline std::optional<std::vector<Enumeration>> tiledb_enumerations ()
101
+ override {
102
+ if (!enumeration.has_value ()) {
103
+ return std::nullopt;
104
+ }
105
+
106
+ return std::vector ({enumeration.value ()});
107
+ }
108
+
109
+ ArrowArray* arrow_domain_slot (
110
+ const SOMAContext& ctx,
111
+ Array& array,
112
+ enum Domainish kind) const override ;
113
+
114
+ ArrowSchema* arrow_schema_slot (
115
+ const SOMAContext& ctx, Array& array) override ;
116
+
117
+ private:
118
+ void _set_dim_points (
119
+ const std::unique_ptr<ManagedQuery>& query,
120
+ const SOMAContext& ctx,
121
+ const std::any& points) const override ;
122
+
123
+ void _set_dim_ranges (
124
+ const std::unique_ptr<ManagedQuery>& query,
125
+ const SOMAContext& ctx,
126
+ const std::any& ranges) const override ;
127
+
128
+ void _set_current_domain_slot (
129
+ NDRectangle& rectangle,
130
+ std::span<const std::any> domain) const override ;
131
+
132
+ std::pair<bool , std::string> _can_set_current_domain_slot (
133
+ std::optional<NDRectangle>& rectangle,
134
+ std::span<const std::any> new_domain) const override ;
135
+
136
+ std::any _core_domain_slot () const override ;
137
+
138
+ std::any _non_empty_domain_slot (Array& array) const override ;
139
+
140
+ std::any _core_current_domain_slot (
141
+ const SOMAContext& ctx, Array& array) const override ;
142
+
143
+ std::any _core_current_domain_slot (NDRectangle& ndrect) const override ;
144
+
145
+ Attribute attribute;
146
+ std::optional<Enumeration> enumeration;
147
+ };
148
+ } // namespace tiledbsoma
149
+
150
+ #endif
0 commit comments